Operating System - HP-UX
1820227 Members
3476 Online
109620 Solutions
New Discussion юеВ

Re: Problem with Cron job.

 
Viswanadhan
Regular Advisor

Problem with Cron job.

Hi Admins,

I have stupid problem with cron job like as follows.

For example : I have some scripts with 755 permissions. Sometimes i get status from scripts, but sometimes i donot status from few scripts.

If i run the script as " # sh <script name>" as root user, then I get the status of the script, but sometimes script doesnot work.

This happens only for few scripts.
I donot see any problem with sendmail / cron daemon.
For save side, I restarted the sendmail, and cron daemon, then also same problem.

Please guide how to rectify it.

Regards,
Viswa.
10 REPLIES 10
Torsten.
Acclaimed Contributor

Re: Problem with Cron job.

I repeat

"Sometimes i get status from scripts, but sometimes i donot status from few scripts"

This is not really a good explanation of a problem.

But what you can check is if you are using always fully qualified pathes for any commands you call.

For example "/usr/bin/ls" instead of only "ls".

See
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1161570

Hope this helps!
Regards
Torsten.

__________________________________________________
There are only 10 types of people in the world -
those who understand binary, and those who don't.

__________________________________________________
No support by private messages. Please ask the forum!

If you feel this was helpful please click the KUDOS! thumb below!   
Viswanadhan
Regular Advisor

Re: Problem with Cron job.

Hi Torsten,

In cron file, I use fullpath as
For example :

12 1 * * * /usr/local/root/scriptname

with 755 file permissions.

The same script working for some server(s), but the same script sometimes donot work for some server.

Regards,
Viswa.
MarkSyder
Honored Contributor

Re: Problem with Cron job.

Have you tried sending the output from the file to a log file so you can see if it is generating an error?

Mark Syder (like the drink but spelt different)
The triumph of evil requires only that good men do nothing
Viswanadhan
Regular Advisor

Re: Problem with Cron job.

Hi Mark,

Im redirecting the output to a file. I see the result in the output file. But sometimes im not getting the respective output.

Later i get mail about the result from output file as

# mailx -s "Subject" mailid@domain.com

Regards,
Viswa.
MarkSyder
Honored Contributor

Re: Problem with Cron job.

Does the file /var/adm/cron/log indicate that the system has tried to run the job?

Mark
The triumph of evil requires only that good men do nothing
Viswanadhan
Regular Advisor

Re: Problem with Cron job.

Hi Mark,

Yes sometimes log is updating, and sometimes not updating.

I restarted the cron daemon, but im getting the same proble.

Regards,
Viswa.
Dennis Handly
Acclaimed Contributor

Re: Problem with Cron job.

When you are in cron, you aren't interactive. So your scripts may stop on a bad exit status if you have used "set -e".

You could use "set -x" to trace your commands to see where it is stopping.

>and sometimes not updating.

If you don't have anything in /var/adm/cron/log then it never started.
rajdev
Valued Contributor

Re: Problem with Cron job.

Hi Viswa,

I would suggest the following steps for checking cron script issues :

1. Cron will only supply a few variables to
your script, so use complete PATHs whereever needed

cron supplied variables
HOME=user's-home-directory
LOGNAME=user's-login-id
PATH=/usr/bin:/usr/sbin:.
SHELL=/usr/bin/sh

2. for cronjobs its always good practice to
redirect the standard output and standard error to another log file, and that will help you to troubleshoot

so your job should be

12 1 * * * /usr/local/root/scriptname > /usr/local/root/scriptname.log 2>&1

now you should get the output and errors in /usr/local/root/scriptname.log file

you can also append the log file name with
date or time stamps so that they are not overwritten each time

eg: scriptname.log.`date +%d%m%y%H%M%Y` etc

or you can also keepon appending to the same file
ie 12 1 * * * /usr/local/root/scriptname >> /usr/local/root/scriptname.log 2>&1

3. check the cron user that you are using and it has the proper permissions for the script , the log files etc

4. use the correct shell in the first line of the script, and ensure that it exists
and maintain it uniformally on all servers

ie #!/usr/bin/sh or #!/usr/bin/ksh

5. check the cron log file - /var/adm/cron/log and see if the job is executed , u should get the time when the job runs and the exit status etc
check for rc=1 [ ie non zero exit status will normally indicate error ]

hope this helps in troubleshooting the problem.

Regards,
Devaraj
Viswanadhan
Regular Advisor

Re: Problem with Cron job.

Hi Dev,

I tried to debug the script ( tail -f /var/adm/cron/log ), and redirected the output to a file.

In log file i did not see any error ( rc=1 ).

Unfortunately in the predefined script I saw a mail id ( the output goes to this mail id).

I have to work out for the mail id.

Thanks to All.

Regards,
Viswa.
Viswanadhan
Regular Advisor

Re: Problem with Cron job.

Thanks to All.