How to timeout with exit(0) from Bash
No need to use sleep
you can change your command in the following way to force the return code at 0
:
(timeout 20s <binary>; exit 0)
Example:
(timeout 2s '/bin/sleep' 100; exit 0) #subshell creation
echo $?
0
vs
timeout 2s '/bin/sleep' 100
echo $?
124
In case you want to:
Return Exit code 0:
- If command completed successfully (code 0).
- OR if command did not complete yet (code 124), but that's OK too.
Return Exit code 1:
- If command had a failure before timeout reached.
Then try this:
timeout 10m some_command || ( [[ $? -eq 124 ]] && \
echo "WARNING: Timeout reached, but that's OK" )