树莓派检测ip脚本

在树莓派上运行web服务器,但有时候开机完网络没有启动成功,需要重启networking服务,所以写了一个脚本来检测IP是否为192.168.x.x,如果不是则重启networking

#!/bin/bash

while true
do
        IP="$(ip addr show eth0|grep "inet\b"|awk '{print $2}')"
        VAL_CHK=$(echo $IP|awk -F"." '{if(($1==191)&&($2==168)&&($3==1)){ printf "T"}else{printf "F";}}')
        echo $IP
        echo $VAL_CHK
        if [ "$VAL_CHK" = "T" ]
        then
                echo "IP is available."
                exit 0
        else
                echo "IP is error!"
                systemctl stop networking
                sleep 5
                systemctl start networking
                sleep 5
        fi
done

猜你喜欢

转载自blog.csdn.net/Namcodream521/article/details/81463524