suppress_output 633 B

123456789101112131415161718192021222324252627282930313233
  1. #!/bin/bash
  2. # Run a command, suppressing output unless it hangs or crashes.
  3. TMPFILE="$(mktemp)"
  4. PID=$$
  5. # Print output to avoid travis killing us
  6. watchdog() {
  7. for i in $(seq 5 5 150); do
  8. sleep 300
  9. echo "This command has been running for more than $i minutes..."
  10. done
  11. echo "Command timed out after 2.5h, dumping logs:"
  12. cat "$TMPFILE"
  13. echo "TIMED OUT"
  14. kill -SIGKILL $PID
  15. }
  16. watchdog 2>/dev/null &
  17. WATCHDOG_PID=$!
  18. time "$@" >"$TMPFILE" 2>&1
  19. CODE=$?
  20. if [ $CODE != 0 ]; then
  21. tail -n 2000 "$TMPFILE"
  22. echo "FAILED $CODE"
  23. kill $WATCHDOG_PID
  24. exit $CODE
  25. fi
  26. kill $WATCHDOG_PID
  27. exit 0