I use Ubuntu (Trusty and Xenial) and usually put my computer in sleep mode rather than power it down. A common problem is that upon wake the network is down so one has to restart the network-manager service. E.g.
sudo service network-manager restart
I am tired of doing this so I have hacked the following together:
#!/bin/sh # should live in /lib/systemd/system-sleep/... # sudo mv restart-network-on-wake.sh /lib/systemd/system-sleep/ # sudo chmod a+x /lib/systemd/system-sleep/restart-network-on-wake.sh case $1/$2 in pre/*) echo "Going to $2..." exit 0 ;; post/*) echo "Waking up from $2..." if ! ping -q -c 1 -W 1 126.96.36.199 > /dev/null; then echo "IPv4 is down, restarting network-manager" service network-manager restart fi ;; esac
I am a novice at shell scripting I guess and don't have a strong understanding of Linux internals. Do you have any thoughts?