Task scheduling:
Crond Service:
Cron is for tasks that needed to be repeated in regular basis
- uses the crond service (started by default)
- Started by default and it used by different services
- Used for users commands of scripts that run on the system by the root user.
- cron job send the output in mail for the user account or the output of command
send in file.
Note: Mail server and mail client have to be working on the system.
- Scripts location are found in /etc/cron.*
- Users commands including the root user are found in /var/spool/cron/username
Note: The Default Editor to write in Cron is (vim by default, unless the EDITOR
environment variable has been set to something different using export)
Note: The file being edited will have one job per line
The cron uses the cronie service:
It is a process that is running on the system:
If root account needs to make task executed other than hourly, daily, weekly,
monthly. The root account have to add the scripts in /etc/cron.d directory.
How to use cron to schedule a task?
To schedule task or job in cron we use crontab command either for root account or
the standard user account.
To list the task used for the user or root:
Crontab Synatx:
Writing in crontab:
Minutes: from 0 to 59
Hour: from 0 to 23
Day of Month: from 1 to 31
Month: from 1 to 12 or you can specify jan, feb, mar
Day of week: from 0 to 6 or you can specify sun, mon
Examples:
0 11 20 5 * tar –czvf home.tar.gz /home
*/15 2-4 * jun 1-4 uptime >>cpu.stat
0 0 * * 5 df –h >>disk.space
To remove the cron job from the system:
Controlling access to crontab:
/etc/cron.allow
/etc/cron.deny
Notes:
1. Whitespace is not permitted in either file.
2. The root user can always use cron, regardless of the usernames listed in the
access control files.
3. If users are named in /etc/cron.allow file, all other users won't be able to use
cron.
4. If there is no /etc/cron.allow file, only users named in /etc/cron.deny can't use
cron.
AT:
at is for tasks that needed to run for just one time
- uses the atd service (started by default)
- at job send the output in mail for the user account
At package:
At service in the system:
At process in the system:
Configure at jobs:
at time
Command to run
CRTL+d (end of input)
Example:
Time can be:
HH:MM ==> 23:15
Midnight ==>12:00 am
Noon ==>12:00 pm
Now+time ==> now +2min, now +2 hours, now +5days, now +1week
at 4 tomorrow
at 5am +4 days
at teatime ==> Associated jobs will start at 4:00 P.M.
at teatime tomorrow
at noon +4 days
at 5pm august 3 2016
at 3:00 6/13/07
Jobs will be saved at /var/spool/at/”job name in scripted form”
To view the job time:
Or
[root@srv1 ~]# at –l ==> display the same output
To remove the job from the queue:
Controlling at jobs
/etc/at.allow
/etc/at.deny