Snippets

Edel SM ping iowa host for downtime. if comes back, restart ipsec at telx side

Created by Edelberto Mania
#!/bin/bash
# https://trello.com/c/9fQlN7xg/81-script-to-restart-ipsec-telx-gw
# ping IOWA ipsec host
# if goes down and back again, issue restart of ipsec on this host (telx ipsec)
# Edelberto Mania <ed@zenoradio.com>
# 20160127

oif='eth0'
ip='192.235.87.100'
peer_ip='216.51.145.155'
status='/tmp/status'
previous_status='starting'


while(true); do
	## for testing only
	#peer_ip=$(cat /tmp/test_ip)
	#echo ${previous_status}

	ping -I ${oif} -qc4 ${peer_ip} >/dev/null
	if [ $? -eq 0 ]; then
		echo online >${status}
		if [ "${previous_status}" ==  "offline" ]; then
			echo "re-starting ipsec process..."
			/etc/init.d/ipsec restart
			echo "$(date): ${peer_ip} is now back online. Restarted ipsec." >>~emania/ping.log
		fi
	elif [ $? -eq 1 ]; then
		echo offline >${status}
		[ "${previous_status}" ==  "online" ] && echo "$(date): ${peer_ip} is Down." >>~emania/ping.log 
	else
		echo lossy >${status}
		[ "${previous_status}" ==  "online" ] && echo "$(date): ${peer_ip} is Lossy." >>~emania/ping.log
	fi
	previous_status=$(cat ${status})
	sleep 1
done

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.