Changes

2,164 bytes added ,  13:57, 24 August 2018
Line 142: Line 142:  
===Launching an OpenVPN server on specified hours===
 
===Launching an OpenVPN server on specified hours===
 
----
 
----
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, only 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 restart
Line 159: Line 159:     
To sum up, the first line enables the OpenVPN server 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 OpenVPN server. You can find more information on UCI in this article: '''[[UCI command usage]]'''.
 
To sum up, the first line enables the OpenVPN server 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 OpenVPN server. You can find more information on UCI in this article: '''[[UCI command usage]]'''.
 +
 +
===Launching a WiFi Access Point (AP) on specified hours===
 +
----
 +
For this example we'll configure a system that launches a WiFi AP at the start of every workday (8 AM) and shuts down said AP 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 wireless.@wifi-iface[0].user_enable=1 && uci delete wireless.@wifi-iface[0].disabled && uci commit && wifi
 +
0 18 * * 1-5 uci set wireless.@wifi-iface[0].user_enable=0 && uci set wireless.@wifi-iface[0].disabled=1 && uci commit && wifi
 +
 +
Let's overview what each segment indicates sequentially:
 +
* 0/0 - the actions for both rules must take place at minute 0 (right after the hour has changed)
 +
* 8/18 - the actions 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 actions for both rules must take place every Monday - Friday
 +
* set wireless.@wifi-iface[0].user_enable='''1/0''' - enables/disables the WiFi AP(note that the first rule has ''enable=1'' in it and the second one has ''enable=0''; 1 equals ON; 0 equals OFF)
 +
* uci delete wireless.@wifi-iface[0].disabled - deletes the WiFi ''disabled'' option
 +
* uci set wireless.@wifi-iface[0].disabled=1 - disables the WiFi AP
 +
* uci commit - commits configuration changes
 +
* wifi - restarts the WiFi service
 +
* && - symbols used to separate different commands
 +
 +
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 the ''uci show wireless'' command.
    
==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