How to use exit status in crontab

I add the following script line to the red-hat crontab, script should run on Saturday in 5:00 in the morning. In order to run the script /var/scripts/PLW.pl every Saturday at 05:00 morning. I want to check the exit status from the script.

my question : is it possible to add in the crontab after the script line the something like this

0 0 * * 5   /var/scripts/PLW.pl 
[[ $? -eq 0 ]] && run_once.bash

so if exit status is 0 the run_once.bash script will be activated.

Answer

You can do something like,

0 0 * * 5  /usr/bin/python /var/scripts/PLW.pl && /bin/bash /path/to/run_once.bash

Note : && /bin/bash /path/to/run_once.bash will only run if previous command run successfully. So instead of using exit code, you can use &&‘s inbuilt functionality.

Leave a Reply

Your email address will not be published. Required fields are marked *