0887 371 498 support@itservice-bg.net
25.09.2010 · Самуил Арсов · Bash script

change deafult gateway with ping

touch /etc/init.d/ping
chmod 755 /etc/init.d/ping
nano /etc/init.d/ping

#!/bin/bash
 
PINGOUT=`ping -c 10 194.145.63.12 | grep "100% packet loss"`
if [ "$PINGOUT" = "" ]; then
echo "ping gateway OK"
else
route del deafult
route add default gw 93.155.131.19
fi

nano /etc/crontab

*/1 * * * * root test -x /etc/init.d/ping && /etc/init.d/ping

/etc/init.d/cron restart