-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_eth0.sh
executable file
·54 lines (52 loc) · 2.34 KB
/
check_eth0.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
# **************** INSTALLATION *******************
# crontab -e
# */5 * * * * sudo sh /home/pi/rasp_scripts/check_wifi.sh > /dev/null 2>&1
#=================================================================
# Script Variables Settings
clear
wlan='eth0'
gateway='192.168.10.110'
alias ifup='/sbin/ifup'
alias ifdown='/sbin/ifdown'
alias ifconfig='/sbin/ifconfig'
#=================================================================
#http://www.pihome.eu/2017/10/19/auto-reconnecting-wifi-on-raspberry/
echo " _____ _ _ _ "
echo " | __ \ (_) | | | | "
echo " | |__) | _ | |__| | ___ _ __ ___ ___ "
echo " | ___/ | | | __ | / _ \ | |_ \_ \ / _ \ "
echo " | | | | | | | | | (_) | | | | | | | | __/"
echo " |_| |_| |_| |_| \___/ |_| |_| |_| \___|"
echo " "
echo " S M A R T H E A T I N G C O N T R O L "
echo "*************************************************************************"
echo "* PiHome is Raspberry Pi based Central Heating Control systems. It runs *"
echo "* from web interface and it comes with ABSOLUTELY NO WARRANTY, to the *"
echo "* extent permitted by applicable law. I take no responsibility for any *"
echo "* loss or damage to you or your property. *"
echo "* DO NOT MAKE ANY CHANGES TO YOUR HEATING SYSTEM UNTIL UNLESS YOU KNOW *"
echo "* WHAT YOU ARE DOING *"
echo "*************************************************************************"
echo
echo " Have Fun - PiHome"
date
echo " - Auto Reconnect Wi-Fi Status for $wlan Script Started ";
echo
# Only send two pings, sending output to /dev/null as we don't want to fill logs on our sd card.
# If you want to force ping from your wlan0 you can connect next line and uncomment second line
ping -c2 ${gateway} > /dev/null # ping to gateway from Wi-Fi or from Ethernet
# ping -I ${wlan} -c2 ${gateway} > /dev/null # only ping through Wi-Fi
# If the return code from ping ($?) is not 0 (meaning there was an error)
if [ $? != 0 ]
then
# Restart the wireless interface
ifdown --force ${wlan}
ifup ${wlan}
sleep 5
ifup ${wlan}
fi
ping -I ${wlan} -c2 ${gateway} > /dev/null
date
echo
echo " - Auto Reconnect Wi-Fi Status for $wlan Script Ended ";