summaryrefslogtreecommitdiff
path: root/wlanWDprowl.sh
blob: 95a710d56d83ff0abfe66e9c6da65514effa8389 (plain)
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
#!/bin/bash
# wlanWDprowl.sh
# SJP 19 Nov 2017
#
# Designed to stop a headless wireless raspi from disappearing from the LAN.
# IS called from a systemd timer on an Arch linux OS.
#
cd /usr/local/bin
# The following block enables private configuration
# I use .gitignore to exclude the config file trom github.
logdir="/path/to/my/log"  # overwritten by sourcing from a local config file.
if [ -e wlanWDlog.conf ]; then
    . wlanWDlog.conf   # source directory name from local config file
else echo "wlanWDlog.conf does not exist"; exit 1
fi
# end of privacy config

# Get wireless adaptor name
wirelessLink=$(networkctl | awk '/wlan/ {print $2}')

# Prowl:
# Detect the state of the wireless network adaptor
wlanStatus=$(networkctl status ${wirelessLink} | awk '/State:/ {print $2}')
logline="$(date) ${wlanStatus}"
# write all to log for now. This will show if I'm still alive.
echo ${logline} >> ${logdir}/wlanStatus.log

if [ ${wlanStatus} != "routable" ]; then 
    # we have lost wireless, so log the occurrence and restart the service
    echo ${logline} >> ${logdir}/wlanStatus.log
    sudo systemctl restart systemd-networkd.service
fi