Dial pppoe through ISP, sometimes it will disconnect by itself, so we can usually write a simple schedule, let him run once every minute, for example, but things are not that simple, just checking whether ppp0 is connected is not enough , Look at how my bash is written.
Schedule to run every minute, like below
* * * * * /usr/local/scripts/repppoe.sh
The bash of my repppoe.sh is as follows:
#!/bin/bash
/sbin/ifconfig ppp0
if [ $? -gt 0 ];then
echo "start up ppp0"
/usr/bin/pon dsl-provider
fi
/sbin/ifconfig ppp1 >/dev/null 2>&1
if [ $? -eq 0 ];then
#全關
/usr/bin/poff -a
sleep 3
#重撥
/usr/bin/pon dsl-provider
fi
A little explanation, I usually use simple instructions to check whether the execution is correct,
In the figure below, you can see that when the command is executed successfully, it will return 0, that is to say, there is no problem returning 0, and I don’t need to redial.
There is a one-in-a-million exception, and I encountered it. Maybe ifconfig returned a value other than 0.
This will cause the script to dial a new network ppp1, which is not what I want, just like the following
So in the repppoe.sh above, I detected more ppp1, if for some reason, ppp1 should not appear,
My solution is usually very explosive, just stop him all, and then redial again. 😛
No Comment
Post your comment