skip to Main Content

I just need to know:

  1. Our systems are set up to use /var/log/cron to store cron logs, however, there are no exit codes stored here just start/stop times and the PID of the jobs. How can I force our servers to just log a simple exit code for the cron job?

Note: I’m not trying to force the script that is being called to report its own exit code I just wanted to see if it was possible that Cron itself could log is own exit status. Almost if you were able to do an echo $? right after it ran to see what the code was.

2

Answers


  1. you should be able to get the return value by referring to $? – a users crontab (which is not allowed to write to /root/no-no) it looks like this:

     24      15      *       *       *       /bin/echo "foo"; logger `echo $?`
     25      15      *       *       *       /bin/echo "bar" > /root/no-no; logger `echo $?`
    

    then see the output of logger in this case.

    Login or Signup to reply.
  2. I think you are lookin for,

    /60 * * * *  /path/to/Script >/path/to/log 2>&1; [ $? != 0 ] && mail -s "SUBJECT" -E [email protected] < /path/to/log
    

    This will notify you when exit code is not equal to 0 or when cron job will fail.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search