1752297 Members
4364 Online
108786 Solutions
New Discussion

Re: configuring cron job

 
SOLVED
Go to solution
Victor BERRIDGE
Honored Contributor

Re: configuring cron job

Hi Shiv,

My advice would be do like me and write a Header for all your cronfiles with the summarized syntax e.g:
# /sm/cron/cronfile.root
# crontab file for the super-user.
#
# ==========================================================================
# F O R M A T
# ==========================================================================
# Minute Hour Month_Day Month Weekday Command
# (0-59) (0-23) (1-31) (1-12) (0-6)*0=sun run-string
# * = in any crontab field represents all legal values.
# Therefore, to schedule the ps(1) cmd to execute at 5:10pm on every
# friday and monday during june, july, august, you would make an entry
# in your crontab fithe that looks like this :
# 10 17 * 6,7,8 1,5 ps>>psfile 2>&1
# The 2>&1 redirects any error msg to the file psfile.
# ==========================================================================

# archive annuelle de l export le 3 dimanche de janvier chaque annee
#00 04 * 1 0 /sm/bin/archive_annuelle >>/sm/log/archive_ann.er 2>&1
...
You may notice I also put the file in a place where all cronfiles should be (my standards...) with the name of the user of this cronfile. So I rarely (almost never) use crontab -e and can then alway compare the curent and the file for modifications and if there are any ask why (especially roots) I am not informed... some modifications are done by software installation (...)
Dont forget to explicitely redirect ouputs (std and error) otherwise cron will keep on sending you mails about them...
If you do read a .profile to set env variable or do a su - , dont forget to add in that .profile a test for interactive session (since you are in batch mode) e.g.
if [[ $- = *i* ]]; then #tty interactive test (VBE - 030306)
# set term if it's not set
...
fi
otherwise cron will in the messages it will send complain its "not a typewriter"...

Now you should be able to write down a crontab script that is easily readable and exempt of most common errors...

All the best
Victor