HPE Community read-only access December 15, 2018
This is a maintenance upgrade. You will be able to read articles and posts, but not post or reply.
Hours:
Dec 15, 4:00 am to 10:00 am UTC
Dec 14, 10:00 pm CST to Dec 15, 4:00 am CST
Dec 14, 8:00 pm PST to Dec 15, 2:00 am PST
System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

finding whether cronjob ran successfully

 
SOLVED
Go to solution
Shivkumar
Super Advisor

finding whether cronjob ran successfully

Hello,

How do we know that a particular cronjob ran successfully ?

Thanks,
Shiv
8 REPLIES
James R. Ferguson
Acclaimed Contributor

Re: finding whether cronjob ran successfully

Hi:

Examine '/var/adm/cron/log'. The 'rc=' denotes the return (exit) code from the crontask. Non-zero indicates failure; zero is success, by convention.

Regards!

...JRF...

Re: finding whether cronjob ran successfully

If you haven't redirected stderr & stdout, this will be mailed to you.
Tingli
Esteemed Contributor

Re: finding whether cronjob ran successfully

Just put
2>&1 | mail root
in the end of the entry. The log will be sent to root mail.
Avinash20
Honored Contributor
Solution

Re: finding whether cronjob ran successfully

Just to add

file (/var/adm/cron/log).

A typical log entry consists of three parts similar to:

> CMD: find / -name core -exec rm -f {} \;
> root 12345 c Wed Apr 4 07:44:00 METDST 2001
< root 12345 c Wed Apr 4 07:46:13 METDST 2001

The two first entries (>) are consecutive. The third entry may not immediately follow the command and start entry (for example there could be information about another cron job starting or ending before this job ended). You can find the third entry (the termination entry) by using the job's PID (since the pid is common to both the start and end entry).

Here in detail is what they mean:

> CMD: find / -name core -exec rm -f {} \;

| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| command/script name
|
v
'>' command name

> root 12345 c Wed Apr 4 07:44:00 METDST 2001
| | | |
| | | + c=cronjob a=atjob b=batch-job (or d-y - refer to queuedefs(4)
| | +-- command's PID
| +---- username.
v
'>' startup time entry.


< root 12345 c Wed Apr 4 07:46:13 METDST 2001 vv=xx
| | | | \___/
| | | + c=cronjob a=atjob b=batch-job |
| | +-- command's PID |
| +---- username. optional status/termination
v information.
'<' termination time entry.

There are 2 possible formats for this optional information:

- 'rc=xx' This field is added when the exit code of the job is not equal to 0
- 'ts=xx' this is the exit code of the shell used by cron to launch the command.
"Light travels faster than sound. That's why some people appear bright until you hear them speak."
Avinash20
Honored Contributor

Re: finding whether cronjob ran successfully

A) a normal execution without errors.

crontab entry:
* * * * * ll / >/dev/null

> CMD: ll / >/dev/null
> didier 9436 c Wed Apr 4 18:07:00 METDST 2001
< didier 9436 c Wed Apr 4 18:07:00 METDST 2001

B) an example of command that exits with an error.

crontab entry:
* * * * * cat /unexisting_file > /dev/null

> CMD: cat /unexisting_file > /dev/null
> didier 20321 c Wed Apr 4 09:41:00 METDST 2001
< didier 20321 c Wed Apr 4 09:41:00 METDST 2001 rc=2

C) an example of command that terminates when it recieves a signal.

crontbab entry:
* * * * * sleep 12345

$ ps -ef | grep 12345
didier 20844 20843 1 09:43:00 ? 0:00 sleep 12345
didier 20843 25184 2 09:43:00 ? 0:00 sh -c sleep 12345

$ kill -7 12345

> CMD: sleep 12345
> didier 20843 c Wed Apr 4 09:43:00 METDST 2001
< didier 20843 c Wed Apr 4 09:43:20 METDST 2001 rc=135
^^^
135=128+7

rc=135 135=128+7 128 means that the command has made an unexpected exit. 7
represents the signal that caused the unexpected exit.

D) an example of unexpected shell exit.

crontbab entry:
* * * * * sleep 12345

$ ps -ef | grep 12345
didier 21414 25184 0 09:45:00 ? 0:00 sh -c sleep 12345
didier 21416 21414 0 09:45:00 ? 0:00 sleep 12345

$ kill -7 21414

> CMD: sleep 12345
> didier 21414 c Wed Apr 4 09:45:00 METDST 2001
< root 21413 c Wed Apr 4 09:45:00 METDST 2001
< didier 21414 c Wed Apr 4 09:45:16 METDST 2001 ts=7
^^^^

ts=7 This means that the cron shell used to execute the command has made an expected exit due to signal 7

For further reading please look at the man pages for at(1), cron(1M), proto(4),
and queuedefs(4).
"Light travels faster than sound. That's why some people appear bright until you hear them speak."
Avinash20
Honored Contributor

Re: finding whether cronjob ran successfully

Please assign point to this thread
"Light travels faster than sound. That's why some people appear bright until you hear them speak."
Avinash20
Honored Contributor

Re: finding whether cronjob ran successfully

Also as stated above
Cron will always automatically mail output for stdout and stderr to root unless you specifically state in the command that stdout and stderr are redirected elsewhere.
"Light travels faster than sound. That's why some people appear bright until you hear them speak."
Arturo Galbiati
Esteemed Contributor

Re: finding whether cronjob ran successfully

Hi,
if you don't have redirect the stdout and stderr of teh script all the output are sent to the mail of the user where crontab run.
HTH.
Rgds,
Art