lucasdaniel1991
(usa Outra)
Enviado em 25/10/2019 - 16:06h
achei isso na internet procede esse script está correto?
#!/bin/bash
TARGETDIR=/var/log
FILE=networkcheck.log
ROUTER="192.168.1.1"
PING="/bin/ping"
$PING -c4 $ROUTER > /dev/null
if [ $? != 0 ]
then
echo "$(date): Test 1 of 2 failed, No network connection with "$ROUTER", restarting eth0" >>$TARGETDIR/$FILE
/sbin/ifdown 'eth0'
sleep 5
/sbin/ifup --force 'eth0'
sleep 20
$PING -c4 $ROUTER > /dev/null
if [ $? != 0 ]
then
echo "$(date): Test 2 of 2 also failed, No network connection with "$ROUTER", RESTARTING SYSTEM" >>$TARGETDIR/$FILE
/sbin/shutdown -r now
else
echo "$(date): Network with "$ROUTER" was restored after eth0 restart withouth restarting system" >> $TARGETDIR/$FILE
fi
else
echo "$(date): Network OK with "$ROUTER" " >> $TARGETDIR/$FILE
fi