×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Why does this cron job not work?

Why does this cron job not work?

Why does this cron job not work?

(OP)
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.

RE: Why does this cron job not work?

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

RE: Why does this cron job not work?

(OP)
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.

RE: Why does this cron job not work?

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
http://www.dermanagement.com/

RE: Why does this cron job not work?

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

RE: Why does this cron job not work?

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
http://www.dermanagement.com/

RE: Why does this cron job not work?

wink
agreed, it also could be in the cron or root user's ~ folder.

RE: Why does this cron job not work?

(OP)
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!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close