forked from dweeber/WiFi_Check
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wifi_check.bash
49 lines (38 loc) · 899 Bytes
/
wifi_check.bash
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
#!/usr/bin/env bash
# The IP for the server to ping
SERVER=10.0.1.1
INTERFACE="wlan0"
LOCKFILE="/var/run/$(basename $0).pid"
logger -t $0 "$(date) routine check for $INTERFACE"
### Handle lockfile ###
if [ -e ${LOCKFILE} ]; then
PID=$(<${LOCKFILE})
if kill -0 &>1 > /dev/null $PID; then
logger -t $0 "$PID still running"
exit 1
else
rm ${LOCKFILE}
fi
fi
echo $$ > ${LOCKFILE}
### Check status by ping
ping -c2 ${SERVER} > /dev/null
if [ $? != 0 ]; then
logger -t $0 "ping ${SERVER} failed - run ifup on ${INTERFACE}"
ifdown --force ${INTERFACE}
sleep 5
ifup ${INTERFACE}
fi
### Check status by ifconfig
# if ifconfig $wlan | grep -q "inet addr:" ; then
# # Network is Okay
# else
# logger -t $0 "ping ${SERVER} failed - run ifup on ${INTERFACE}"
# ifdown --force ${INTERFACE}
# sleep 5
# ifup ${INTERFACE}
# fi
### Exit
rm ${LOCKFILE}
exit 0
# end