31,703
edits
Line 107: | Line 107: | ||
* the '''day of week''' segment functions a bit differently than the others: | * the '''day of week''' segment functions a bit differently than the others: | ||
** '''0''' indicates Sunday and '''1-6''' indicate Monday through Saturday. | ** '''0''' indicates Sunday and '''1-6''' indicate Monday through Saturday. | ||
** since weekdays shift throughout the year, i.e., they are not dependent on specific days of a month, | ** since weekdays shift throughout the year, i.e., they are not dependent on specific days of a month, when they are used in conjunction with crontab, the action will be executed when the current time matches the value in either field. For instance, '''5 5 5 * 5''' would cause the specified command to be executed at 5:05 AM every fifth day of every month plus every Friday. | ||
---- | ---- | ||
To edit crontab, use '''crontab -e'''. This is analogous to using the '''vi''' command | To edit crontab, use '''crontab -e'''. This is analogous to using the '''vi''' command with the ''/etc/crontabs/root'' file, so the same rules apply here as when editing with ''vi''. Type ''crontab -e'', press "Enter" and a text editor for the crontab file will open. To start editing, press the "I" key on your keyboard; you can then edit the crontab file much like with a regular text editor (except you can't use your mouse pointer to place the text cursor anywhere you want; use the arrow keys on your keyboard instead). To save changes after editing, press the "Escape" ("Esc") button on your keyboard, type ''':x''' and press "Enter". To cancel changes and exit the editor, press "'''Control'''" ('''Ctrl''') '''+''' "'''C'''" on your keyboard. | ||
A simpler yet more restricted method of editing would be using the '''echo''' command to add lines to the crontab file. It can be used in such a manner: '''echo "Hello, world" >> /etc/crontabs/root'''. This command will add the text '''Hello, world''' to the crontab file, i.e., it adds whatever is specified within the quotation marks (" ") after the ''echo'' command to the file that is specified after the double '''more than''' ('''>>''') symbol. For example, to add a rule that reboots the router everyday at midnight, we would have to use: | A simpler yet more restricted method of editing would be using the '''echo''' command to add lines to the crontab file. It can be used in such a manner: '''echo "Hello, world" >> /etc/crontabs/root'''. This command will add the text '''Hello, world''' to the crontab file, i.e., it adds whatever is specified within the quotation marks (" ") after the ''echo'' command to the file that is specified after the double '''more than''' ('''>>''') symbol. For example, to add a rule that reboots the router everyday at midnight, we would have to use: | ||
Line 115: | Line 115: | ||
# echo "0 0 * * * reboot" >> /etc/crontabs/root | # echo "0 0 * * * reboot" >> /etc/crontabs/root | ||
Using the command in such a way simply adds a new line with the denoted text at the end of the specified file. This is convenient when you just want to add a new rule(s) quickly, but unlike ''vi'' or ''crontab -e'' it doesn't offer any editing capabilities. So if you want edit existing rules | Using the command in such a way simply adds a new line with the denoted text at the end of the specified file. This is convenient when you just want to add a new rule(s) quickly, but unlike ''vi'' or ''crontab -e'' it doesn't offer any other editing capabilities. So if you want edit or remove existing rules, this method will not offer a solution and ''crontab -e'' should be used instead. | ||
==Examples== | ==Examples== |