Link to home
Start Free TrialLog in
Avatar of Christopher Schene
Christopher ScheneFlag for United States of America

asked on

need a cron job that runs every wednesday at noon

I need a Linux cron job that runs every Wednesday at noon.
SOLUTION
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Christopher Schene

ASKER

I tried it and got this error message:

[root@localhost Carefx]# 0 12 * * 3 /opt/Carefx/crontabtest.sh
bash: 0: command not found
[root@localhost Carefx]# crontab -e
no crontab for root - using an empty one
crontab: no changes made to crontab

[root@localhost Carefx]# 0 12 * * 3 /opt/Carefx/crontabtest.sh <---- this is what I was trying to add
1) Type crontab -e  to open an editor (probably vi) for the crontab.

2) Type i to go to input mode

3) Type the line I gave you

4) Hit the ESC key, then type :wq!

5) Done
I did what you suggested but my cron command  never ran. Is there something else I need to configure?
Check your entry with

crontab -l

All corrrect?

Did you receive any emails from cron?

Does the script run successfully from the command line?

There is also a cron log, but its location is OS dependent. Which is your OS ("uname -a")?
Here is the output


uname -a
Linux localhost.localdomain 2.6.18-194.el5 #1 SMP Fri Apr 2 14:58:14 EDT 2010 x86_64 x86_64 x86_64 GNU/Linux


 crontab -l
0 17 * * 3 /opt/Carefx/crontabtest.sh
0 12 * * 3 /opt/Carefx/crontabtest.sh

no email, yes the script runs correctly from the command line

I looked for a cron.log...but did not find one


[root@localhost ~]# find / -name 'cron*.log' -print
[root@localhost ~]# find / -name 'cron.log' -print
[root@localhost ~]#

The crond service is running:


[root@localhost init.d]# ./crond
Usage: ./crond {start|stop|status|reload|restart|condrestart}
[root@localhost init.d]# ./crond status
crond (pid  3864) is running...
[root@localhost init.d]#
What is the script supposed to do? Are you really sure that it didn't run?

Please be aware that under cron the user's environment is not fully initialized (no initialization scripts like .profile etc. are run).

PATH is just /bin and /usr/bin and there are only a few variables set, like $HOME.

So if your script relies on the usual environment you must initialize it explicitly, and you'll have to call all executables which reside outside of /bin or /usr/bin by their full path.

And yes, finding the location of the cron log is always a problem under Linux.
Please search just for *cron*, without any suffix:

find / -name "*cron*"
Avatar of nmitev
nmitev

Probably a permissions issue, if cron is not running as root.

Try modifying the command to
0 12 * * 3  root  /opt/Carefx/crontabtest.sh

Open in new window

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
What does cron do if the machine is not running at the time the job is supposed to run?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ok, I think I have idea as to what is happening: It seems that one of my commands errors out  and when that happens, it seems that the cron job aborts...is there a way I can tell it to continue even if there are errors?
Rather correct the error.

And take care not to start your script with "#!/bin/bash -e" or "#!/bin/bash -u"
Thanks experts.....If you don't mind i would like to divide up the points since I was helped by more than one comment.
No problem, go ahead!

wmp
Increase points