Advertisement
metalx1000

raspbmc network dropping fix - raspberry pi

Aug 22nd, 2014
436
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.82 KB | None | 0 0
  1. #!/bin/bash
  2. #fixes Raspbmc network dropping on the Raspberry Pi
  3. #also added the following to '/etc/network/interfaces'
  4. #  auto eth0
  5. #     iface eth0 inet dhcp
  6.  
  7. while true ; do
  8.     LOGFILE=/home/pi/network-monitor.log
  9.  
  10.     if ifconfig eth0 | grep -q "inet addr:" ;
  11.     then
  12.         echo "$(date "+%m %d %Y %T") : Ethernet OK" >> $LOGFILE
  13.         sleep 60
  14.     else
  15.         echo "$(date "+%m %d %Y %T") : Ethernet connection down! Attempting reconnection." >> $LOGFILE
  16.         ifup --force eth0
  17.         OUT=$? #save exit status of last command to decide what to do next
  18.         if [ $OUT -eq 0 ] ; then
  19.             STATE=$(ifconfig eth0 | grep "inet addr:")
  20.             echo "$(date "+%m %d %Y %T") : Network connection reset. Current state is" $STATE >> $LOGFILE
  21.         else
  22.             echo "$(date "+%m %d %Y %T") : Failed to reset ethernet connection" >> $LOGFILE
  23.         fi
  24.         sleep 10
  25.     fi
  26. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement