1855314 Members
2366 Online
104109 Solutions
New Discussion

process ID of a cronjob

 
SOLVED
Go to solution
Gary Yu
Super Advisor

process ID of a cronjob

Hi team,

Our hosted company just setup openview alert for all our production servers, one of the alert is when a cronjob failed for any reason, I will get a message from OV server telling me a cron command with pid "xxxx" failed, and rc=xxx.

the problem is we have lots of cronjobs running on the server, and the OV message itself doesn't have timestamp, the only time tag I got is the time I received the mail, which does not accurately match the server time. So it's hard for me to find out which cronjob failed.

I'm just wondering, if I put "echo $$" at the begining of all cronjob scripts(some scripts are complicated, they call other scripts), will that match the PID indicated at the OV message?

thanks,
Gary
6 REPLIES 6
A. Clay Stephenson
Acclaimed Contributor

Re: process ID of a cronjob

Yes it will but $$ won't help you that much BUT
echo "${$}: File Purge Program" > ${LOGFILE}
date >> ${LOGFILE}

will do rather well for your purposes.

Or a syslog message could be used as well.

If it ain't broke, I can fix that.
Gary Yu
Super Advisor

Re: process ID of a cronjob

thanks Clay for the reply, I did a test, the process name related to the PID from echo ${$} is always '-su' shouldn't it be my script name?
John Palmer
Honored Contributor

Re: process ID of a cronjob

Hi,

I wonder whether openview alert is just looking at cron's log file '/var/adm/cron/log'.

This lists the command run, process id, time and result code (if non zero). The process id is going to be the parent id of your process as cron calls it with an su. You could try logging ${PPID} in your script and it should tie up with the one logged by cron.

Regards,
John
Gary Yu
Super Advisor

Re: process ID of a cronjob

Hi John, it's my guess too that OV monitors cronjobs by looking into /var/adm/cron/log file. BTW, when I got the error "rc=xxx", where can I check the meaning of these rc number?

thanks,
Gary
John Palmer
Honored Contributor

Re: process ID of a cronjob

Unfortunately,there isn't a numbering convention for result codes. You may need to consult the documentation or if it's a script you're running, check the code.

Regards,
John
John Poff
Honored Contributor
Solution

Re: process ID of a cronjob

Hi Gary,

I remembered reading some posts about the return codes from cron. I did a search and found a couple of threads that talk about them. You can also look at /usr/include/sys/errno.h to see the return codes used.

Good luck!

JP


http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0xce8093e260b0d611abdb0090277a778c,00.html

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x982beea29889d611abdb0090277a778c,00.html