Last active
December 17, 2015 20:59
-
-
Save Aricg/5671135 to your computer and use it in GitHub Desktop.
restart racoon ipsec vpn if $@ hosts can't be reached
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| status=0 | |
| logdir="/var/log/vpnevent/" | |
| log="vpnevent.log" | |
| #[[ ! $UID = 0 ]] && echo "This script must be run as root"; exit 1 | |
| if [[ ! "$1" ]] | |
| then | |
| echo "usage: "$0" List of hosts on which this script depends" | |
| echo "example: "$0" wwww.google.com 127.0.0.1" | |
| echo | |
| exit 1 | |
| fi | |
| log() { | |
| if [ ! -d "$logdir" ]; then | |
| mkdir -p "$logdir" | |
| fi | |
| if [ ! -f "$logdir""$log" ]; then | |
| touch "$logdir""$log" | |
| log "creating log file" | |
| fi | |
| echo "$(date "+%y/%m/%d %h:%m:%s"): $@" | tee -a "$logdir""$log" | |
| } | |
| for hosts in "$@" | |
| do | |
| ping -c4 $hosts &> /dev/null; | |
| status=$(($status + $?)) | |
| done | |
| if [[ $status -gt 0 ]]; then | |
| echo $status | |
| /etc/init.d/racoon stop | |
| /etc/init.d/setkey stop | |
| /etc/init.d/setkey start | |
| /etc/init.d/racoon start | |
| log PING FAILED, RESTARTING IPSEC TUNNEL | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment