#!/bin/bash while true ; do? # # Sleep while the file if_block exists # because someone else is running this script # while [ -f /var/www/uNode/ram/if_block ] ; do? usleep 500000? done? # # when if_block is gone then we are clear to run this script # to keep anyone else from running this script while we are using it # make a file called if_block # touch /var/www/uNode/ram/if_block? # # Is there a file called /etc/network/interfaces and does it contain the word IF_WIFI # when the wifi client is active but not necessairly connected? # if (cat "/etc/network/interfaces" | grep 'IF_WIFI' > /dev/null 2>&1) ; then? #echo "WIFI ACTIVE"? # # is there a command called iwconfig and does it return words that include ESSID # when the wifi is connected?? # if(iwconfig 2>&1 | grep ESSID > /dev/null 2>&1) ; then? #echo "WIFI IS CONNECTED"? # # Is there a file called /var/www/uNode/ram/if_reset # if there is such a file then the original script removes the file # if [ -f /var/www/uNode/ram/if_reset ] ; then? rm /var/www/uNode/ram/if_reset? # # Is there a file called /var/www/uNode/data/vpn_active # if there is such a file then restart the vpn # if [ -f /var/www/uNode/data/vpn_active ] ; then? #echo "VPN IS ACTIVE - RESTARTARTING"? usleep 1000000? sudo service openvpn start? fi? fi ? else? #echo "WIFI DISCONNECTED"? if [-f /var/www/uNode/ram/if_reset ] ; then? echo ""? else? touch /var/www/uNode/ram/if_reset? if [ -f /var/www/uNode/data/vpn_active ] ; then? #echo "VPN IS ACTIVE - STOPPING"? sudo service openvpn stop? fi? fi ? #echo "RESETTING IFACE"? usleep 250000? ifdown -a? usleep 250000? ifup -a? usleep 250000? fi? else? echo "WIFI NOT ACTIVE"? fi? ? # # Wait 1 second # usleep 1000000? # # remove the file if_block # rm /var/www/uNode/ram/if_block? ? echo? usleep 15000000? done? # # here is a good tutorial on the if statement # http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html # # The linux documentation project http://www.tldp.org/ # # # #