I have two scripts. First one is basically wrapper that calls subscript and sets timeout.

# wrapper_script

timeout --signal=SIGTERM 50 main_script.sh

And if execution of main_script.sh takes longer than 50 s, I am trying to catch SIGTERM

# main_script.sh

trap "echo 'Reached time limit'; rm $log_file; exit" SIGHUP SIGINT SIGTERM

I never get message "Reached time limit" printed, child script gets killed, but it does not catch SIGTERM. Do I miss something?


At least in the example you provided, your main_script.sh is going to exit immediately after the trap statement. If I add while :; do :; done to the end of your main_script.sh I get the "Reached time limit"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.