脚本覆盖ip地址

脚本覆盖ip地址

编写将被覆盖IP地址的脚本,/etc/network/interfaces并确保接口正确,而不是 ping google.com 如果时间结果 >30 ms重新启动接口

但这段代码无法正常工作。

#!/bin/bash
echo "lets start ip configuratioon ...."

lastconf=$(cat /etc/network/interfaces | awk '{print $1}')
if [ ! -z $lastconf ]; then
    sed -i "/auto $lastconf/,/auto.*/{/auto.*/b;d;};" /etc/network/interfaces
    sed -i "/auto $lastconf/d" /etc/network/interfaces
echo "Now last ip configuration will be removed :)))"

ipconf="auto $lastconf\niface $lastconf inet static\n\taddress 192.168.1.2\n\tnetmask 255.255.255.0\n\tgateway 192.168.1.1\n\tdns-nameserver 8.8.8.8 192.168.0.2
echo -e $ipconf >> /etc/network/interfaces

ifconfig $lastconf down && ifconfig $lastconf up
service networking restart

pinging=$(ping google.com -c 1 | grep '64 bytes')
if [ -z $pinging ]; then
        exit 0
fi

if [ $pinging -gt 30 ]; then
        echo "request timee is more than 30wami; restarti daicko"
        ifconfig $lastconf down && ifconfig $lastconf up
        service networking restart
fi
exit 0

相关内容