I have a program which will print out either pass or fail. I want to detect the programs which hang in there and echo 'timeout'
I wrote a script like this:
echo -n 'test' && timeout 5 ./mytest | grep -q -i 'passed' && echo ', passed'|| echo ', failed'
if [ $? -eq 124 ]; then
NAME timeout - run a command with a time limit SYNOPSIS timeout [OPTION] DURATION COMMAND [ARG]... timeout [OPTION] DESCRIPTION Start COMMAND, and kill it if still running after DURATION. ...
Here's an example:
cmd_output=`timeout 5 ./mytest` if [ $? -eq 124 ]; then echo 'timeout' else echo $cmd_output fi