Created
August 29, 2022 09:07
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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