Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why does this cron job not work? 1

Status
Not open for further replies.

lcs01

Programmer
Aug 2, 2006
182
US
Here is the output of 'crontab -e':

Code:
01 08 * * * /home/userID/mybin/saveLogs.pl > /dev/null 2>&1
01 09 * * * /home/userID/logs/zipLogs.csh > /dev/null 2>&1

The first one works OK. But the 2nd does not work at all.

However, while I was in /home/userID/logs and manually execute this script 'zipLogs.csh', it works just fine.

BTW, the script 'zipLogs.csh' is very simple:

Code:
#! /bin/csh -f

set today = `date +%Y_%m_%d`
echo $today
set log = "log_$today.tar"
echo "log = $log"
tar cvf $log *.log
gzip $log
\rm *.log
echo "exit ..."

I can not figure out why it does not work through cron job. By saying 'not working', I meant that there is no files with this name pattern, e.g. 'log_2007_05_30.tar.gz' created in the subdir '/home/userID/logs'! Again, when I execute it from cmdline './zipLogs.csh', it works just fine.

Could someone tell what I have missed here?

Just for your reference, the platform is linux.

Thanks for your help.
 
Maybe you are looking in the wrong directory?
Where in your script do you tell cron to place the log file in your subdirectory?

hope this helps
 
No, the path is right. I put it on the 'logs' subdir. Just want to make things simpler. I just can not understand why it does not work. Must some thing simple and stupid.
 
try making the script run as root from crontab to ensure that your script has sufficient rights to write in the folder.

I noticed you wrote "\rm" rather than "rm"



D.E.R. Management - IT Project Management Consulting
 
Hello,

thedaver's idea may be helpful here.
Apart from that, I may be a bit dense. Sorry for that.
But what do you mean by I put it on the 'logs' subdir. ?
How do you put anything in a cron script to a subdir without using some kind of cd subdir or full path name?

To make things clear:
Just calling a script by its full path /home/userID/logs/zipLogs.csh does not mean that /home/userID/logs will be the script's working directory.

Have a look at your home directory. The log file may be there.
Or, for further diagnosis, remove the > /dev/null 2>&1
Or, even better, put a cd command in your script.

regards
 
hahahaha!
hoinz, I'll bet you a $1.00 that you're right. crond probably is trying to do the work in the cron or root user's ~ folder.

lcs01, add a hard "cd /your/log/folder/" statement in your script!

D.E.R. Management - IT Project Management Consulting
 
[wink]
agreed, it also could be in the cron or root user's ~ folder.
 
Thank you both, hoinz & thedaver!

I am sure "cd /your/log/folder/" will work. Gee, I have not done shell scripting for almost ten years and I guess I forgot everything.

Thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top