#!/usr/bin/bash
trap call_event 11
call_event(){
exit
}
INTERFACE=eth0
DEST_IP_NCOL=1
GW_IP_NCOL=2
WATCH_DEST_IP="0.0.0.0"
GW_IP="172.21.7.1"
route -n | awk '{if(NR>2){print $0}}' | while read info ; do
dest_ip=$(echo $info | grep ${INTERFACE} | cut -d' ' -f${DEST_IP_NCOL})
gw_ip=$(echo $info | grep ${INTERFACE} | cut -d' ' -f${GW_IP_NCOL})
if [[ "$WATCH_DEST_IP" == "$dest_ip" ]] && [[ "$GW_IP == $gw_ip" ]] ; then
kill -s 11 $$
fi
done
route add default gw $GW_IP $INTERFACE
watchsys.sh
while $(sleep 1) ; do ./watchsys.sh ; done
exit 指令只会退出当前管道,不会退出脚本的执行进程