Show pageOld revisionsBacklinksBack to top This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. ====== Schedule Tasks Using At And Cron ====== **General Information** Using system utilities to schedule one-off or reoccurring jobs. ---- ===== at ===== at is good for one-off jobs that don't need to reoccur regularly. \\ Install, Enable, Start <code bash> yum install at systemctl enable atd systemctl start atd </code> \\ Example Times (teatime is 4pm) <code bash> at now +5 minutes at now +5 hours at 12:00am at teatime <enter command> <ctrl+d> </code> \\ Example job <code bash> at now +5 minutes at>logger "System uptime is:$(uptime)" at> <ctrl+d> </code> \\ View jobs <code bash> atq </code> \\ Remove job (cancel job) <code bash> atrm <job#> </code> ---- ===== cron ===== cron is for scheduling reoccurring jobs/scripts. \\ Edit current user's cron <code bash> crontab -e </code> \\ System wide <code bash> /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 </code> \\ 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 <code bash> */5 * * * * root /home/user/uptimelog </code> * Executes /home/user/uptimelog as root, every 5 mins ---- ===== Anacron ===== Anacron runs all scripts in cron.* directories. This allows jobs to be run if the scheduled time was while a system was powered off. \\ Main config and contents: /etc/anacrontab <code bash> #period in days delay in minutes job-identifier command 1 5 cron.daily nice run-parts /etc/cron.daily 7 25 cron.weekly nice run-parts /etc/cron.weekly @monthly 45 cron.monthly nice run-parts /etc/cron.monthly </code> \\ Run all anacron jobs(in /etc/anacrontab), ignore timestamps (note that the "delay in minutes" setting is still in effect) <code bash> anacron -f </code> \\ View timestamps for anacron jobs (cron.daily in this example) <code bash> cat /var/spool/anacron/cron.daily </code> \\ Run all jobs now, ignore delay specifications in /etc/anacrontab <code bash> anacron -n </code> ---- linux_wiki/schedule_tasks_using_at_and_cron.txt Last modified: 2019/05/25 23:50(external edit)