스크립트가 IP 주소를 덮어씁니다

스크립트가 IP 주소를 덮어씁니다

시간 결과 > 인터페이스를 다시 시작 하는 경우 google.com을 핑하는 대신 IP주소를 덮어쓰고 인터페이스가 올바른지 확인하는 스크립트를 작성하세요./etc/network/interfaces30 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

관련 정보