Quote:
|
Originally Posted by pkumar5
After doing enough RnD on net i have sufficient idea about crontab. My basic problem is how to configure it.
"man crontab" also gave me some idea. The problem is i am not able to open crontab file using crontab -l.
Now i am wondering what shd i do. 
|
If no valid crontab has been created for the user yet, "crontab -l" has nothing to display. You might have also created the file as root, with the group set as root as well. This means that accessing the file as user 'abc' will not work, as 'abc' might not have permissions to access the file.
Crontab files usually exists with permissions as follow (linux example) :
[root@srvtst ~]# ls -l /var/spool/cron
total 8
-rw------- 1 abc root 1960 Jun 10 2009 abc
Note that the file here belongs to user abc, and group is set as root. File permission is set to 600 (chmod), which is user has rw, no-one else has access.
Either fix the permissions, or possibly delete / rename the crontab file that you created. Log in as the abc user. Ensure you can access the crontab with "crontab -e" and add / edit the intended line(s).
If there is no crontab file, the first -e invocation will create it if you add at least one character/line to the file.
It's always a good idea to add a similar "comments" heading to the file, just for your own reference :
Code:
# Crontab layout :
# The first five fields shall be integer patterns that specify the following:
# 1. Minute [0,59]
# 2. Hour [0,23]
# 3. Day of the month [1,31]
# 4. Month of the year [1,12]
# 5. Day of the week ([0,6] with 0=Sunday)
# Each of these patterns can be either an asterisk (meaning all valid
# values), an element, or a list of elements separated by commas. An ele-
# ment shall be either a number or two numbers separated by a hyphen
# (meaning an inclusive range).
################################################################################
# Run doyourthang.sh script daily at 03:00 on weekdays to "do your thang"
################################################################################
00 03 * * 1-5 /home/abc/scripts/doyourthang.sh > /dev/null 2>&1
#######
# Fin #
#######
Edit: Wanted to add the comment on the " > /dev/null 2>&1" at the end of the crontab line. We always cat unwanted output from crons to /dev/null, so no mails are generated from the crons - in most cases nobody will ever read this. Our scripts do error checking internally, and mails required output to the various admins or groups accordingly.