Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # pings a pre-determined IP address and restarts OpenVPN if ping doesn't work
- # Set outputfiles
- OUTPUT_FILE="/pinger/log.txt"
- IP_FILE="/pinger/lastip.txt"
- # Ping settings. think of something when you are dealing with a spotty connection like wifi
- PING_IP="8.8.8.8"
- PING_AMOUNT="1"
- # Command to determine IP address. Maybe make this a setting later
- IP_COMMAND="wget http://ipinfo.io/ip -qO -"
- echo "Pinging $PING_IP, trying $PING_AMOUNT times"
- ping -c $PING_AMOUNT $PING_IP
- STATUS=$?
- if [ "$STATUS" = "0" ] ; then
- echo "Ping was successful, internet still works, saving IP"
- $IP_COMMAND > $IP_FILE
- else
- echo "Ping failed, restarting OpenVPN"
- LOG_TIME=$(date)
- LAST_IP=$(cat $IP_FILE)
- echo "last known IP address was $LAST_IP"
- service openvpn restart
- sleep 5
- NEW_IP=$($IP_COMMAND)
- echo "new IP is $NEW_IP"
- echo -e "$LOG_TIME\tRestarted OpenVPN. Old IP: $LAST_IP\t\tNew IP:$NEW_IP" >> $OUTPUT_FILE
- echo $NEW_IP > $IP_FILE
- fi
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement