linux_wiki:schedule_tasks_using_at_and_cron

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
linux_wiki:schedule_tasks_using_at_and_cron [2016/02/29 21:44]
billdozor created
linux_wiki:schedule_tasks_using_at_and_cron [2019/05/25 23:50] (current)
Line 3: Line 3:
 **General Information** **General Information**
  
-About this page/how-to/script+Using system utilities to schedule one-off or reoccurring jobs
  
 ---- ----
  
-==== at ====+===== at ====
 at is good for one-off jobs that don't need to reoccur regularly. at is good for one-off jobs that don't need to reoccur regularly.
  
 +\\
 Install, Enable, Start Install, Enable, Start
 <code bash> <code bash>
Line 17: Line 19:
 </code> </code>
  
 +\\
 Example Times (teatime is 4pm) Example Times (teatime is 4pm)
 <code bash> <code bash>
Line 26: Line 29:
 </code> </code>
  
 +\\
 Example job Example job
 <code bash> <code bash>
Line 33: Line 37:
 </code> </code>
  
 +\\
 View jobs View jobs
 <code bash> <code bash>
Line 38: Line 43:
 </code> </code>
  
 +\\
 Remove job (cancel job) Remove job (cancel job)
 <code bash> <code bash>
Line 45: Line 51:
 ---- ----
  
-==== cron ====+===== cron =====
  
 cron is for scheduling reoccurring jobs/scripts. cron is for scheduling reoccurring jobs/scripts.
  
 +\\
 Edit current user's cron Edit current user's cron
 <code bash> <code bash>
Line 54: Line 61:
 </code> </code>
  
 +\\
 System wide System wide
 <code bash> <code bash>
Line 67: Line 75:
 </code> </code>
  
 +\\
 More preferred method: Place scripts inside one of the cron.* directories. More preferred method: Place scripts inside one of the cron.* directories.
   * /etc/cron.d/ = system executed jobs (format => /etc/crontab)   * /etc/cron.d/ = system executed jobs (format => /etc/crontab)
Line 74: Line 83:
   * /etc/cron.weekly/ = weekly executed scripts (format => bash script)   * /etc/cron.weekly/ = weekly executed scripts (format => bash script)
  
 +\\
 Example custom script in /etc/cron.d Example custom script in /etc/cron.d
 <code bash> <code bash>
Line 79: Line 89:
 </code> </code>
   * Executes /home/user/uptimelog as root, every 5 mins   * 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.1456800258.txt.gz
  • Last modified: 2019/05/25 23:50
  • (external edit)