Changes

10 bytes removed ,  09:35, 7 September 2021
Line 82: Line 82:  
| 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: center; vertical-align: top;" | 5
+
| style="text-align: center; vertical-align: top;" | 1-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 111: Line 111:  
** 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.
 
** 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 on 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 the 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  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 exit the editor without saving changes, press the "Escape" button and type ''':q!''' on your keyboard.
    
A simpler yet more restricted method of editing would be using the '''echo''' command to add new 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 new 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 144: Line 144:  
For this example we'll configure a system that launches an OpenVPN server at the start of every workday (8 AM) and shuts down said server at the end of every 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; the '''&&''' separator should be used to divide the different commands:  
 
For this example we'll configure a system that launches an OpenVPN server at the start of every workday (8 AM) and shuts down said server at the end of every 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; the '''&&''' separator should be used to divide the different commands:  
   −
  0 8 * * 1-5 uci set openvpn.7365727665725F64656D6F.enable=1 && uci commit && /etc/init.d/openvpn restart
+
  0 8 * * 1-5 uci set openvpn.7365727665725F64656D6F.enable=1 && uci commit && /etc/init.d/openvpn start
  0 18 * * 1-5 uci set openvpn.7365727665725F64656D6F.enable=0 && uci commit && /etc/init.d/openvpn restart
+
  0 18 * * 1-5 uci set openvpn.7365727665725F64656D6F.enable=0 && uci commit && /etc/init.d/openvpn stop
    
Let's overview what each segment indicates sequentially:
 
Let's overview what each segment indicates sequentially:
Line 206: Line 206:  
To sum up, the first line enables the WiFi AP at 8 AM, the second disables it at 6 PM. At the end of the enabling and disabling processes the changes are committed and the related services restarted. We used UCI to change the state of the WiFi AP. You can find more information on UCI in this article: '''[[UCI command usage]]'''.
 
To sum up, the first line enables the WiFi AP at 8 AM, the second disables it at 6 PM. At the end of the enabling and disabling processes the changes are committed and the related services restarted. We used UCI to change the state of the WiFi AP. You can find more information on UCI in this article: '''[[UCI command usage]]'''.
   −
'''NOTE''': if you have multiple access points or had them in the past, the path to the relevant options (i.e., ''wireless.@wifi-iface[0]'') may be different. You check these path with this command:
+
'''NOTE''': if you have multiple access points or had them in the past, the path to the relevant options (i.e., ''wireless.@wifi-iface[0]'') may be different. You check these paths with this command:
 
   
 
   
 
  ''uci show wireless | grep able''
 
  ''uci show wireless | grep able''
Anonymous user

Navigation menu