I am doing the following :
timeout 180 bash myscript.txt
myscript.txt is supposed to be fully executed in less than 180 seconds. IF NOT, I want emergencyscript.txt to be executed. Is it possible to do so ?
Like
timeout 180 [bash myscript.txt] [bash emergencyscript.txt]
The exit status of timeout is 124 if the command times out. You can test for this explicitly.
timeout 180 bash myscript.txt
exit_status=$?
if [[ $exit_status -eq 124 ]]; then
bash emergencyscript.txt
fi
Any other value for exit_status is the result of myscript.txt running to completion.
#!/bin/bash
if ! timeout 180s bash myscript.txt; then bash emergencyscript.txt; fi
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With