故障

ip a |grep -E 'eth0|eth1'
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    inet 10.0.2.15/24 brd 10.0.2.255 scope global noprefixroute dynamic eth0
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    inet 192.168.33.32/24 brd 192.168.33.255 scope global noprefixroute eth1

脚本检测


#!/usr/bin/env bash

#url="http://192.168.9.1"
#code=`/usr/bin/curl -iv --interface eth1 -o /dev/null -w %{http_code} -fsL --connect-timeout 1 --max-time 1 -XGET $url`

code=`ping -c1 -i3 -I eth1  192.168.33.1 &> /dev/null;echo $?`
#echo $code;

if [ "$code" = "0" ]; then
        echo "code is $code"
        echo "code ok,do nothing"
else
        echo echo "code is $code"
        echo "code error,will restart eth1 interface";
        /sbin/ip link set eth1 down;
        /sbin/ip link set eth1 up;
        echo "eth1 restart ok";
fi