1835822 Members
3586 Online
110085 Solutions
New Discussion

Cron job problem

 
Peter Remirez
Occasional Advisor

Cron job problem

Hi,

I have an entry in the cron job as follows:
0 13 * * 1 rsync -arvz /afs/sie.intel.com/cad/sun4x_57/xscale/windriver/2.2.1/docs/usb/ /pgfs2/sws1/CSR/users/cloh6/usb/ > /pgfs2/eng/cloh6/syncout0

It somehow fails to execute the rsync command above at the specified time. Hence the job did not get executed at all.

The rsync command did get run when it was invoked from the command line.

I was wondering if anyone does have any ideas on the cause of this problem & the method of solving it?

Thanks
11 REPLIES 11
Pete Randall
Outstanding Contributor

Re: Cron job problem

Peter,

Cron jobs have minimal environements (i.e. not PATH, few variables set, etc.). Try the full path name for the rsync command.


Pete


Pete
Pete Randall
Outstanding Contributor

Re: Cron job problem

Peter,

Edited version:

Cron jobs have minimal environments (i.e. not much of a PATH, few variables set, etc.). Try the full path name for the rsync command.


Pete


Pete
Ralph Grothe
Honored Contributor

Re: Cron job problem

In the file you redirected the cronjob's stdout to, does there appear something like:

sh: rsync: not found.

I guess rsync, as Pete wrote, isn't in one of the standard paths cronjobs are furnished with like /usr/bin.

In the shell where you successfully issued the rsync command what does your PATH look like, or what is a "which rsync" responding?
Madness, thy name is system administration
Andi Rigauer
Regular Advisor

Re: Cron job problem

The best thing to check if your cron was running is to add something into the script like touch /tmp/cron.tmp
after the script supposed to run you can check it under /tmp if the file has been created.
the others a right as well. For cron you should think of the enviroment.
Maybe don't trigger the sync via cron, trigger a other script which triggers the sync. Within this script you can parse the env.
But don't forgett to use a absolute path for it.
god, root where's the difference
Radim Jarosek
Regular Advisor

Re: Cron job problem

Hi,

As Pete wrote it's common problem when you start scripts from crontab. In addition , from my experience if you use some variables in your script, put in the beginning line

. /home/user/profile

or special cron-profile (file where you can specify PATH, variables, ORACLE_HOME .....)

. /home/user/cronprofile


HTH

Radim
Steven E. Protter
Exalted Contributor

Re: Cron job problem

Here is how I write cron scripts to avoid the problem.

I have two sessions open as the user.

One session edits the script, the other issues the whence command for every command I plan to use.

All commands are done with the full path of the command. It would be easier to set the PATH variable, but that leaves open the possbility that the PATH variable can be changed by the cron script itself.

An OS upgrade can mess up scripts by moving the commands themselves, but I get warning on that and can either use sed to change all user contributed scripts, or softlink to the new command area when that happens.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Kent Ostby
Honored Contributor

Re: Cron job problem

Also, check email for root (or whatever user this is) as cron will usually email you output from commands if things dont go well.

I mention this because we tend to not check "root"'s email on our system and then every once in a while we do and usually find old cron job errors :-)

Best regards,

Kent M. Ostby
"Well, actually, she is a rocket scientist" -- Steve Martin in "Roxanne"
Peter Remirez
Occasional Advisor

Re: Cron job problem

Kent,
The email which I obtained did not indicate the which command in the crontab produced the error.

The error which message obtained from the e-mail is:
Subject: Your crontab file has an error in it
Your "crontab" on pgsc2603
unexpected end of line
This entry has been ignored.

Is there a way which to run the crontab in a verbose mode i.e. displaying the error message occuring at a specific command?

Thanks

Steve Post
Trusted Contributor

Re: Cron job problem

Besides PATH to commands, people here are telling you to check on all of the environmental variables.

Try this. Put this on the bottom of your crontab file for a second
* * * * /usr/bin/env > /tmp/crontab.env

Wait until /tmp/crontab.env gets created.
Run /usr/bin/env > /tmp/my.env

(remove the /usr/bin/env from the crontab file now).

Then look at both files. If it runs by hand, and not by cron, the differences here could be why rsync fails to run.

IF it's not the environment, maybe there's something different on the system at 1300 hours?

steve
Pete Randall
Outstanding Contributor

Re: Cron job problem

Peter,

It's complaining about an unexpected end of line. Unfortunately, the forums formatting makes your crontab entry difficult to read in your original post. Could you attache the actual crontab entry so we can better see it?


Pete


Pete
Wouter Jagers
Honored Contributor

Re: Cron job problem

Unexpected end of line ? Seems like a 'typo' in your crontab..

Try to delete the line completely and type it in again (don't paste it from your clipboard).

greets
Wout
an engineer's aim in a discussion is not to persuade, but to clarify.