Skip to content

Instantly share code, notes, and snippets.

@Aricg
Last active December 17, 2015 20:59
Show Gist options
  • Select an option

  • Save Aricg/5671135 to your computer and use it in GitHub Desktop.

Select an option

Save Aricg/5671135 to your computer and use it in GitHub Desktop.
restart racoon ipsec vpn if $@ hosts can't be reached
#!/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