Open main menu

Changes

1,540 bytes removed ,  16:57, 24 February 2017
add highlight about ntp
Cron is the system scheduler on Unix/Linux/Mac operating systems. The ''crontab'' is the schedule of actions that the machine must keep. There are two types of crontabs in place on most systems: ''user crontabs'' and the ''system crontab''.
 
{{highlight|text=dates and times are critically important to the proper function of a computer. Be sure to setup and configure the Network Time Protocol Daemon [[NTP]]}}
== Avoid User Crons ==
* <code>man crontab</code> can provide a lot more information.
== One<!-time Jobs ==You can certainly use cron to run one-time jobs, but it would seem to be more effort than it's worth, since cron is designed for '''repeating''' jobs. Using transclude the <code>at</code> command, you can specify a job to be run at some time in the future. The most common thing I do with <code>at</code> is schedule a reboot. Of course if you just want to reboot the machine at 10pm, you can do <code>/sbin/shutdown -r 22:00 "rebooting at 10:00 P.M." &</code> Do this in a [[screen]] session to ensure that the current shell does not need to be intact, but I think backgrounding the process with ''article from '&At''' takes care of that (depending on your shell environment). Anyway, the <code>shutdown</code> command is not as flexible with date and time arguments as the <code>at</code> command. With <code>at</code>, you can specify <code>at 8am tomorrow</code>. Invoking this command launches an interactive shell which you then enter the command to be executed. E.g. <code>shutdown -r now</code>. Finally, you exit the interactive shell with <kbd>Ctrl</kbd>+<kbd>d</kbd>. <code>atq</code> will list the jobs in the queue. <code>at -c 1</code> will 'cat' (display) details of job '''1''' <code>atrm 1</code> will remove job #1 from the queue. Since <code>at</code> reads from STDIN, you can just pipe the command to it rather than using the interactive shell{{: <code>echo "ls -al" | at now + 1 minute</code> Note that since <code>at</code> runs non-interactively with a different shell, you won't actually '''see''' the results of the 'ls' command. <source lang="bash">echo "shutdown -r now" | at 8am tomorrowecho "shutdown -r now" | at midnight 2017-02-25# show the queueatq# show details of job 1at -c 1# cancel / remove job 1atrm 1</source>}}
4,558

edits