Crontabs: Difference between revisions
PauliusRug (talk | contribs) No edit summary |
|||
(30 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
==Introduction== | ==Introduction== | ||
'''Crontab''' is a list of commands that allows tasks (programs, scripts) to be run automatically at regular time intervals. For example, in | '''Crontab''' is a list of commands that allows tasks (programs, scripts) to be run automatically at regular time intervals. For example, in RUT routers it is responsible for executing such services as Automatic Reboot functions, SIM Idle Protection, Scheduled SMS and others that function in a periodic manner. | ||
The crontab can be opened for editing, adding, removing or modifying scheduled tasks. This article will provide an explanation of the crontab functionality principle and present some usage examples | The crontab can be opened for editing, adding, removing or modifying scheduled tasks. This article will provide an explanation of the crontab functionality principle and present some usage examples in hopes that it may help you configure your own crontab rules. | ||
==Crontab syntax and editing overview== | ==Crontab syntax and editing overview== | ||
===Editing environment=== | ===Editing environment=== | ||
---- | ---- | ||
Firstly, you must decide on what environment you | Firstly, you must decide on what environment you want to use for editing. Crontabs can be edited via a '''Command Line Interface''' ('''CLI'''). RUT routers offer a range of options in that regard. For example, you can use the CLI present in the router's WebUI ('''Services → CLI'''). Or you can log in via '''SSH''' and make edits from there. The method of logging in via SSH is different on different systems: on Linux systems you can use the '''Terminal''' app log in with the command '''''ssh root@<routers_lan_ip_address>'''''; on '''Windows''' systems you can use the free '''PuTTY''' client. | ||
In all cases the | In all cases the log in information is the same (user name: '''root'''; password: admin password (default: '''admin01''')). The syntax of the commands is also the same, so feel free to follow the guide step-by-step whichever method you choose. | ||
Once you've chosen your preferred environment, we can begin the overview | Once you've chosen your preferred environment, we can begin the overview on the syntax and editing of crontabs. | ||
===Syntax and editing=== | ===Syntax and editing=== | ||
---- | ---- | ||
Crontab entries are stored in the '''/etc/crontabs/root''' file. You can edit that file directly with the command '''''vi /etc/crontabs/root''''', but it is more convenient to edit with '''''crontab -e''''', which we'll be using for all examples in this guide. ''-e'' is an option of the ''crontab'' command | Crontab entries are stored in the '''/etc/crontabs/root''' file. You can edit that file directly with the command '''''vi /etc/crontabs/root''''', but it is more convenient to edit with '''''crontab -e''''', which we'll be using for all examples in this guide. ''-e'' is an option of the ''crontab'' command used for editing. Presented below is a list all options that can be used with ''crotab'': | ||
Usage: crontab [-c DIR] [-u USER] [-ler]|[FILE] | Usage: crontab [-c DIR] [-u USER] [-ler]|[FILE] | ||
Line 30: | Line 28: | ||
FILE Replace crontab by FILE ('-': stdin) | FILE Replace crontab by FILE ('-': stdin) | ||
As | As an example, lets try the '''''-l''''' option that shows the contents of the crontab file: | ||
[[File:Configuration example 1 crontabs.png]] | [[File:Configuration example 1 crontabs.png]] | ||
For the sake of | For the sake of example, I've added a Ping Reboot rule to the router's configuration. In the figure above you can see that creating such a rule also generates an entry (encapsulated in green) in the crontab list. Let's examine this entry: | ||
* '''/sbin/ping_reboot 1 8.8.8.8 NULL 2 56 5 1 0 cfg02c21d''' | * The '''/sbin/ping_reboot 1 8.8.8.8 NULL 2 56 5 1 0 cfg02c21d''' part indicates the action that is to be taken. In this case it is the ''/sbin/ping_reboot'' command with the options ''1 8.8.8.8 NULL 2 56 5 1 0 cfg02c21d'' | ||
* '''*/5 * * * *''' | * The '''*/5 * * * *''' part indicates the frequency at which the action is executed. It consists out of five segments: '''minute''', '''hour''', '''day of month''', '''month''' and '''day of week''' in that order. A table of examples on how to specify this frequency is presented below: | ||
{| class="wikitable" | {| class="wikitable" | ||
Line 74: | Line 72: | ||
| style="text-align: center; vertical-align: top;" | 11 | | style="text-align: center; vertical-align: top;" | 11 | ||
| style="text-align: center; vertical-align: top;" | 15 | | style="text-align: center; vertical-align: top;" | 15 | ||
| style="text-align: center; vertical-align: top;" | 1 | | style="text-align: center; vertical-align: top;" | 1/6/12 | ||
| style="text-align: center; vertical-align: top;" | * | | style="text-align: center; vertical-align: top;" | * | ||
| style="text-align: left; vertical-align: top;" | At 11:57 Hrs on | | style="text-align: left; vertical-align: top;" | At 11:57 Hrs on 15th of Jan, June & Dec. | ||
|- | |- | ||
| style="text-align: center; vertical-align: top;" | 25 | | style="text-align: center; vertical-align: top;" | 25 | ||
| style="text-align: center; vertical-align: top;" | 6 | | style="text-align: center; vertical-align: top;" | 6 | ||
| style="text-align: center; vertical-align: top;" | * | | style="text-align: center; vertical-align: top;" | * | ||
| style="text-align: center; vertical-align: top;" | | | style="text-align: center; vertical-align: top;" | 1 | ||
| style="text-align: center; vertical-align: top;" | | | style="text-align: center; vertical-align: top;" | 5 | ||
| style="text-align: left; vertical-align: top;" | At 6:25 AM every weekday (Mon-Fri) | | style="text-align: left; vertical-align: top;" | At 6:25 AM every weekday (Mon-Fri) | ||
|- | |- | ||
Line 89: | Line 87: | ||
| style="text-align: center; vertical-align: top;" | 4,12,26 | | style="text-align: center; vertical-align: top;" | 4,12,26 | ||
| style="text-align: center; vertical-align: top;" | * | | style="text-align: center; vertical-align: top;" | * | ||
| style="text-align: center; vertical-align: top;" | | | style="text-align: center; vertical-align: top;" | * | ||
| style="text-align: left; vertical-align: top;" | At midnight on | | style="text-align: left; vertical-align: top;" | At midnight on 4th, 12th and 26th of every month | ||
|- | |- | ||
| style="text-align: center; vertical-align: top;" | 5 | | style="text-align: center; vertical-align: top;" | 5.10 | ||
| style="text-align: center; vertical-align: top;" | 9 | | style="text-align: center; vertical-align: top;" | 9.14 | ||
| style="text-align: center; vertical-align: top;" | | | style="text-align: center; vertical-align: top;" | 10 | ||
| style="text-align: center; vertical-align: top;" | * | | style="text-align: center; vertical-align: top;" | * | ||
| style="text-align: center; vertical-align: top;" | 0,4 | | style="text-align: center; vertical-align: top;" | 0,4 | ||
Line 100: | Line 98: | ||
|- | |- | ||
|} | |} | ||
==External links== | ==External links== | ||
https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html - PuTTY downloads page link | |||
Revision as of 13:06, 19 April 2018
Main Page > General Information > Configuration Examples > Router control and monitoring > CrontabsIntroduction
Crontab is a list of commands that allows tasks (programs, scripts) to be run automatically at regular time intervals. For example, in RUT routers it is responsible for executing such services as Automatic Reboot functions, SIM Idle Protection, Scheduled SMS and others that function in a periodic manner.
The crontab can be opened for editing, adding, removing or modifying scheduled tasks. This article will provide an explanation of the crontab functionality principle and present some usage examples in hopes that it may help you configure your own crontab rules.
Crontab syntax and editing overview
Editing environment
Firstly, you must decide on what environment you want to use for editing. Crontabs can be edited via a Command Line Interface (CLI). RUT routers offer a range of options in that regard. For example, you can use the CLI present in the router's WebUI (Services → CLI). Or you can log in via SSH and make edits from there. The method of logging in via SSH is different on different systems: on Linux systems you can use the Terminal app log in with the command ssh root@<routers_lan_ip_address>; on Windows systems you can use the free PuTTY client.
In all cases the log in information is the same (user name: root; password: admin password (default: admin01)). The syntax of the commands is also the same, so feel free to follow the guide step-by-step whichever method you choose.
Once you've chosen your preferred environment, we can begin the overview on the syntax and editing of crontabs.
Syntax and editing
Crontab entries are stored in the /etc/crontabs/root file. You can edit that file directly with the command vi /etc/crontabs/root, but it is more convenient to edit with crontab -e, which we'll be using for all examples in this guide. -e is an option of the crontab command used for editing. Presented below is a list all options that can be used with crotab:
Usage: crontab [-c DIR] [-u USER] [-ler]|[FILE] -c Crontab directory -u User -l List crontab -e Edit crontab -r Delete crontab FILE Replace crontab by FILE ('-': stdin)
As an example, lets try the -l option that shows the contents of the crontab file:
For the sake of example, I've added a Ping Reboot rule to the router's configuration. In the figure above you can see that creating such a rule also generates an entry (encapsulated in green) in the crontab list. Let's examine this entry:
- The /sbin/ping_reboot 1 8.8.8.8 NULL 2 56 5 1 0 cfg02c21d part indicates the action that is to be taken. In this case it is the /sbin/ping_reboot command with the options 1 8.8.8.8 NULL 2 56 5 1 0 cfg02c21d
- The */5 * * * * part indicates the frequency at which the action is executed. It consists out of five segments: minute, hour, day of month, month and day of week in that order. A table of examples on how to specify this frequency is presented below:
Segment | minute | hour | day of month | month | day of week | Description |
---|---|---|---|---|---|---|
Possible values | 0-59 | 0-23 | 1-31 | 1-12 | 0-6 | |
Examples | */5 | * | * | * | * | every 5 minutes |
12 | */3 | * | * | * | every 3 hours at 12 minutes | |
57 | 11 | 15 | 1/6/12 | * | At 11:57 Hrs on 15th of Jan, June & Dec. | |
25 | 6 | * | 1 | 5 | At 6:25 AM every weekday (Mon-Fri) | |
0 | 0 | 4,12,26 | * | * | At midnight on 4th, 12th and 26th of every month | |
5.10 | 9.14 | 10 | * | 0,4 | At 9:05AM, 9:10AM, 2:05PM and 2:10PM every Sunday and Thursday |
External links
https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html - PuTTY downloads page link