Skip to content

Instantly share code, notes, and snippets.

@licsber
Created October 4, 2021 04:34
Show Gist options
  • Select an option

  • Save licsber/dfa0651fc8b86ee2629d69c3c2db779d to your computer and use it in GitHub Desktop.

Select an option

Save licsber/dfa0651fc8b86ee2629d69c3c2db779d to your computer and use it in GitHub Desktop.
自动检测有无网络 并发送推送/重启虚拟机
#!/usr/bin/env bash
DATE=$(date '+%Y-%m-%d %H:%M')
function network() {
local timeout=2
local target=www.baidu.com
local code=`curl -I -s --connect-timeout ${timeout} ${target} -w %{http_code} | tail -n1`
if [ "Licsber$code" = "Licsber200" ]; then
return 1
else
return 0
fi
}
network
if [ $? -eq 1 ]; then
if [ ! -n "$1" ]; then
echo $DATE有网 >> /tmp/ikuai
. /etc/profile; sct "$DATE A108有网." "$(cat /tmp/ikuai | grep 没网 | sed 's/$/\n/')"
fi
else
echo $DATE没网 >> /tmp/ikuai
virsh reboot iKuai
virsh start iKuai
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment