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/ | sendmail
Store Result in Particular Log File
#vi /etc/crontab
12 15 * * * root sh /tmp/rhel5backup.log 2>&1
Minutes:Hours:Day:Month:Day of the Week

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
@reboot uname -v
Set the Default Mail
10 * * * * /sbin/ping

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 < /etc/crontab 0 2,13 * * * /sbin/ping -c; 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 link

No comments:
Write comments