Timeout function return value

If timeout times out, it exits with status 124; you can check this to determine whether the script timed out or not.


According the manual (man timeout):

Synopsis timeout [OPTION] NUMBER[SUFFIX] COMMAND [ARG]...

[...] If the command times out, then exit with status 124. Otherwise, exit with the status of COMMAND

Combine this with the knowledge that the exit status or return value is stored in the variable, $?, and we have...

timeout 5 /some/local/script/connect_script -x 'status' > output.txt
RETVAL=$?

Then, you can do more processing based on the value of $RETVAL, which will be 124 if it times out, or some other value based on the exit status of connect_script.