Skip to content

Instantly share code, notes, and snippets.

@chenyanzhe
Last active September 25, 2015 03:11
Show Gist options
  • Save chenyanzhe/035bd1da9c3c3c5b7626 to your computer and use it in GitHub Desktop.
Save chenyanzhe/035bd1da9c3c3c5b7626 to your computer and use it in GitHub Desktop.
Check network connection status.
#!/bin/sh
LOGTIME=$(date "+%Y-%m-%d %H:%M:%S")
wget --spider --quiet www.google.co.jp
if [ "$?" == "0" ]; then
echo '['$LOGTIME'] No Problem.'
exit 0
else
wget --spider --quiet www.baidu.com
if [ "$?" == "0" ]; then
echo '['$LOGTIME'] Problem decteted, restarting.'
/usr/bin/updatelist
/etc/init.d/shadowsocks restart
/etc/init.d/chinadns restart
/etc/init.d/dnsmasq restart
else
echo '['$LOGTIME'] Network Problem. Do nothing.'
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment