cron tab Example Automate scheduling Process Cron tab Important Option

Send Mail
crontab send the result to the Particular mail Id.
0 17 * * * root sh /root/backup.sh | sendmail jkumaron@gmail.com
Store Result in Particular Log File
#vi /etc/crontab
12 15 * * * root sh backup.sh /tmp/rhel5backup.log 2>&1
SYNTAX
Minutes:Hours:Day:Month:Day of the Week
[0-59]:[0-23]:[0-31]:[0-12]:[0-6]

In the Cron tab second entry >> 13,17 it will refer to the 1PM and 5PM
dash ‘-’ refers to the duration hours >> 08-20 refer to the 8AM to the 8PM it cron job run the process
*/10 refers to the every 10 minutes >> First attribute
*/1 every one hours>>Second attribute
cron job 5th entry refer to the Day of the week.
it has value 0 to 6
0 from Sunday
to 6 Saturday.

/var/log/cron - Log File
/var/spool/cron/username - Cron Entry.

if we want to redirect Output to specified user add the mail variable in the crontab
#crontabl -l
MAIL=”rhel5”
@reboot uname -v
Set the Default Mail
MAILTO=root@student.com
10 * * * * /sbin/ping 10.0.0.1

Run cron Job 4th Saturday Of This Month.
* * 22-28 * 6 < Backup Command >
7 Refer to the Saturday,
22-28 Mean From the Date 22 to 28 Only it will start the 4th Saturday.

To view the other user cron tab job we need to use -u
#crontab -u redhat -l
sendmail jkumaron@gmail.com < /etc/crontab 0 2,13 * * * /sbin/ping -c 10.0.0.1; ls -la >>/var/log/cronrun
It will execute ping and ls -la command at 2AM and 1PM and it will put the output of command into the log file /var/log/cronrun
Also Refer the below linkhttp://studentwebsite.blogspot.com/2010/08/where-is-crontab-file-is-located.html

Post a Comment

0 Comments