Solved

need a cron job that runs every wednesday at noon

Posted on 2012-04-11
16
714 Views
Last Modified: 2012-04-17
I need a Linux cron job that runs every Wednesday at noon.
0
Comment
Question by:Christopher Schene
16 Comments
 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 300 total points
ID: 37833969
0 12 * * 3 /path/to/command

Add it to your crontab by means of "crontab -e"

wmp
0
 

Author Comment

by:Christopher Schene
ID: 37834041
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
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 37834071
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
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 

Author Comment

by:Christopher Schene
ID: 37836019
I did what you suggested but my cron command  never ran. Is there something else I need to configure?
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 37836349
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")?
0
 

Author Comment

by:Christopher Schene
ID: 37837468
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]#
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 37837519
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*"
0
 
LVL 1

Expert Comment

by:nmitev
ID: 37843079
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

0
 
LVL 29

Accepted Solution

by:
MikeOM_DBA earned 200 total points
ID: 37851929
Or, add a trace file to figure out if the script generate an error:
0 12 * * 3 /opt/Carefx/crontabtest.sh >/opt/Carefx/crontabtest.trc 2>&1

Open in new window

:p
0
 

Author Comment

by:Christopher Schene
ID: 37852589
What does cron do if the machine is not running at the time the job is supposed to run?
0
 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 300 total points
ID: 37852642
Nothing. Cron doesn't account for the past, only for the future.
0
 

Author Comment

by:Christopher Schene
ID: 37852933
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?
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 37853017
Rather correct the error.

And take care not to start your script with "#!/bin/bash -e" or "#!/bin/bash -u"
0
 

Author Comment

by:Christopher Schene
ID: 37854236
Thanks experts.....If you don't mind i would like to divide up the points since I was helped by more than one comment.
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 37854565
No problem, go ahead!

wmp
0
 

Author Comment

by:Christopher Schene
ID: 37856039
Increase points
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SMB share across internet 15 82
RHEL installation problems on HP Proliant DL 360 G6 server 20 128
Use awk or sed to manipulate Columns in a File 12 36
SMTP log file for IMSVA 5 30
Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question