Skip to content

Instantly share code, notes, and snippets.

@tyilo
Created December 5, 2019 10:24
Show Gist options
  • Save tyilo/2356ba1143aa354a19b9e67c3ef43040 to your computer and use it in GitHub Desktop.
Save tyilo/2356ba1143aa354a19b9e67c3ef43040 to your computer and use it in GitHub Desktop.
Fix NetworkManager
#!/bin/bash
if [[ $(id -u) -ne 0 ]]; then
echo "Run with root!"
exit 1
fi
net_connected() {
ping -c 1 1.1.1.1 > /dev/null
}
while true; do
if ! net_connected; then
echo "Restarting NetworkManager"
systemctl restart NetworkManager
while ! net_connected; do
sleep 1
done
echo "Internet seems to work again"
fi
sleep 1
done
[Unit]
Description=Automatically restarts NetworkManager if internet access becomes unavailable
[Service]
ExecStart=/usr/sbin/fix-nm
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment