Posted By

miha on 08/07/14


Tagged

openvpn


Versions (?)

VPN connection status checker via cron


 / Published in: Bash
 

Sends notification if Wi-Fi is connected and VPN is disconnected. Needs libnotify, cron task must be run with root permissions.

  1. #!/bin/sh
  2. # http://www.linuxquestions.org/questions/linux-networking-3/check-vpn-status-900320/
  3. # cron example (checks every minute):
  4. # * * * * * checker.sh >/dev/null 2>&1
  5.  
  6. WIFIUP=`/sbin/ifconfig wlan0 | grep -c "UP"`;
  7. VPNUP=`/sbin/ifconfig tun0 | grep -c "UP"`;
  8.  
  9. if [ $WIFIUP != 0 ] && [ $VPNUP = 0 ];
  10. then
  11. su -c 'DISPLAY=:0 notify-send "VPN disconnected!!!"' USER
  12. # echo "" | mail -s "VPN disconnected" USER@localhost
  13. fi
  14.  
  15. exit 0

Report this snippet  

You need to login to post a comment.