Changes

2,649 bytes added ,  10:37, 23 April 2018
no edit summary
Line 110: Line 110:  
----
 
----
 
To edit crontab, use '''crontab -e'''. This is analogous to using the '''vi''' command on the ''/etc/crontabs/root'' file, so the same rules as when editing with ''vi'' apply. Type ''crontab -e'', press "Enter" and a text editor for the crontab file will open. To start editing, press "I" on your keyboard, then you can edit the crontab file much like with a regular text editor. To save the changes that you made, press the "Escape" (Esc) button on yur keyboard, type ''':x''' and press "Enter". To cancel changes and exit the editor, press '''Control''' ('''Ctrl''') '''+''' '''C''' on your keyboard.
 
To edit crontab, use '''crontab -e'''. This is analogous to using the '''vi''' command on the ''/etc/crontabs/root'' file, so the same rules as when editing with ''vi'' apply. Type ''crontab -e'', press "Enter" and a text editor for the crontab file will open. To start editing, press "I" on your keyboard, then you can edit the crontab file much like with a regular text editor. To save the changes that you made, press the "Escape" (Esc) button on yur 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:
 +
 +
# 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 or if you made a mistake when adding a new rule, this method will not offer a solution and ''crontab -e'' should be used instead.
    
==Examples==
 
==Examples==
   −
This section will provide some crontab usage examples in the hopes of helping you getting the hang of the system or even finding one that you could use.
+
This section will provide some crontab usage examples in the hopes of helping you getting the hang of the system or even finding one that you could use. The examples provided here will be examined thoroughly but the editing method will not be discussed; you can read up on that in the section above.
    
===Periodic SIM switch===
 
===Periodic SIM switch===
Line 119: Line 125:  
For this example we'll configure a rule that initiates a SIM switch every weekday at 6:45 PM. To execute a SIM card switch via CLI the command '''sim_switch''' is used, so we'll combined this with the crontab and configure the rule:
 
For this example we'll configure a rule that initiates a SIM switch every weekday at 6:45 PM. To execute a SIM card switch via CLI the command '''sim_switch''' is used, so we'll combined this with the crontab and configure the rule:
   −
  # 45 18 * * 1-5 sim_switch change
+
  45 18 * * 1-5 sim_switch change
    
Let's overview what each segment indicates sequentially:
 
Let's overview what each segment indicates sequentially:
Line 132: Line 138:  
To sum up, the first five segments denote the frequency of the sim_switch command. The option '''change''' specifies that the SIM card that is currently in use will be switched. So the entire entry will perform a SIM switch to the opposite SIM card every weekday at 6:45 PM.
 
To sum up, the first five segments denote the frequency of the sim_switch command. The option '''change''' specifies that the SIM card that is currently in use will be switched. So the entire entry will perform a SIM switch to the opposite SIM card every weekday at 6:45 PM.
   −
=== ===
+
===Launching an OpenVPN server on specified hours===
 
----
 
----
 +
For this example we'll configure a system that launches an OpenVPN server at the start of a workday (8 AM) and shuts down said server at the end of a workday (6 PM). For this we'll need to add two rules. Each rule will require multiple commands to be executed. Crontab can launch multiple commands the same way as a single command, only the '''&&''' separator should be used to separate the different commands:
 +
 +
0 8 * * 1-5 uci set openvpn.7365727665725F64656D6F.enable=1 && uci commit && /etc/init.d/openvpn restart
 +
0 18 * * 1-5 uci set openvpn.7365727665725F64656D6F.enable=0 && uci commit && /etc/init.d/openvpn restart
 +
 +
Let's overview what each segment indicates sequentially:
 +
* 0/0 - the action must take place at minute 0 (just as the hour changes)
 +
* 8/18 - the action must take place at 8 AM and 6 PM respectively
 +
* */* - all days of the month are applicable to the rules
 +
* */* - all months of the year are applicable to the rules
 +
* 1-5 - the action must take place every Monday - Friday
 +
* openvpn.7365727665725F64656D6F.enable=1/0 - enables/disables OpenVPN
 +
* uci commit - commits configuration changes
 +
* /etc/init.d/openvpn restart - restarts OpenVPN service
 +
* && - used to separate different commands
 +
 +
The first line enables the OpenVPN server at 8 AM, the second disables it at 6 PM. In this example we used UCI to change the state of the OpenVPN server. You find more information on UCI '''[[UCI command usage|here]]'''.
 +
 
==External links==
 
==External links==
    
https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html - PuTTY downloads page link
 
https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html - PuTTY downloads page link

Navigation menu