2

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.

  • 1
    just put /var/scripts/PLW.pl && run_once.bash on one line. && means do the following command if the previous command exit code is true, ie 0. – meuh Jul 14 '16 at 14:07
4

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.

  • 2
    The if test is superfluous because the && means it will only be done if the exit code is 0. – meuh Jul 14 '16 at 14:09
  • @meuh Oh yeah, I don't know how I didn't realized it. – Rahul Jul 15 '16 at 5:20
  • 1
    Also, you can't use backslashes to continue a line inside of crontab (as you did in the first version of this answer). – Wildcard Jul 15 '16 at 5:53
  • @Wildcard I used '\' just for the sake of clearity. One line was looking bit messy and hard to read. – Rahul Jul 15 '16 at 5:57
0

use 0 0 * * 5 /var/scripts/PLW.pl run 'run_once.sh' from your perl program with system("/bin/sh","/path/run_once.sh"); before exit($EXIT_SUCCESS); A cluttered crontab is bad, comment your perl program instead.

Edit: or just use exec() from perl.

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.