Login form root and check system date, and run crontab command to schedule job
#date
#crontab –e
Field Value
minute 0–59
hour Based on a 24-hour clock; for example, 23 = 11 P.M.
day of month 1–31
month 1–12, or jan, feb, mar, etc.
day of week 0–7; where 0 and 7 are both Sunday; or sun, mon, tue, etc.
command The command you want to run
11 5 3 5 * ls
This above line runs the ls command every May 3 at 5:11 A.M. The asterisk in the day of week column simply means that it does not matter what day of the week it is; crontab still runs the ls command at the specified time.
#crontab –e
50 21 14 02 * ls > /dev/tty2
In real life you do not have to restart cron every time you make a change because cron always checks for changes, But so far exams concern we suggest you to restart cron whenever you made change.
#service crond restart
Example:#
# Minute Hour Day of Month Month Day of Week Command
# (0-59) (0-23) (1-31) (1-12 or Jan-Dec) (0-6 or Sun-Sat)
0 2 12 * 0,6 /usr/bin/find
This line executes the "find" command at 2AM on the 12th of every month that a Sunday or Saturday falls on.
2.0 Examples
3.0 Setting Up cron for Users
Each user can use the crontab command to create and manage cron jobs for their own accounts. There are four switches associated with the crontab command:- -u user Allows the root user to edit the crontab of another specific user.
- -l Lists the current entries in the crontab file.
- -r Removes cron entries.
- -e Edits an existing crontab entry. By default, crontab uses vi.
Two files are used to control the behavior of crond daemons
- /etc/cron.allow If present then only users those name are in this file can use crond daemons
- /etc/cron.deny If present then only user those name are in this file will not be able to use crond daemons apart from these user all other can use cron daemons
- If both files are not present then only root can access cron daemons
No comments:
Post a Comment