Skip to content

Instantly share code, notes, and snippets.

@JanTristanH
Created August 29, 2022 09:07
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save JanTristanH/77e01994abb9848c4abe9a83b7ca79b5 to your computer and use it in GitHub Desktop.
#!/bin/bash
# save arguments passed to script as command, excluding the first one
passed_command="${@:2}"
# write hung command to tmp file
(timeout 10m $passed_command) &> logNonReturningCommand.txt & disown
PID=$!;
# wait until first argument is found in file
var=$(grep $1 logNonReturningCommand.txt)
while [ -z "$var" ];
do
sleep 1
var=$(grep $1 logNonReturningCommand.txt)
done
# kill hung command
kill $PID
# remove temporary file
rm -f logNonReturningCommand.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment