This is an old revision of the document!
Schedule Tasks Using At And Cron
General Information
About this page/how-to/script.
at
at is good for one-off jobs that don't need to reoccur regularly.
Install, Enable, Start
yum install at systemctl enable atd systemctl start atd
Example Times (teatime is 4pm)
at now +5 minutes at now +5 hours at 12:00am at teatime <enter command> <ctrl+d>
Example job
at now +5 minutes at>logger "System uptime is:$(uptime)" at> <ctrl+d>
View jobs
atq
Remove job (cancel job)
atrm <job#>
cron
cron is for scheduling reoccurring jobs/scripts.
Edit current user's cron
crontab -e
System wide
/etc/crontab # .---------------- minute (0 - 59) # | .------------- hour (0 - 23) # | | .---------- day of month (1 - 31) # | | | .------- month (1 - 12) OR jan,feb,mar,apr ... # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat # | | | | | # * * * * * user-name command to be executed
More preferred method: Place scripts inside one of the cron.* directories.
- /etc/cron.d/ = system executed jobs (format ⇒ /etc/crontab)
- /etc/cron.daily/ = daily executed scripts (format ⇒ bash script)
- /etc/cron.hourly/ = hourly executed scripts (format ⇒ bash script)
- /etc/cron.monthly/ = monthly executed scripts (format ⇒ bash script)
- /etc/cron.weekly/ = weekly executed scripts (format ⇒ bash script)
Example custom script in /etc/cron.d
*/5 * * * * root /home/user/uptimelog
- Executes /home/user/uptimelog as root, every 5 mins