Created
October 4, 2021 04:34
-
-
Save licsber/dfa0651fc8b86ee2629d69c3c2db779d to your computer and use it in GitHub Desktop.
自动检测有无网络 并发送推送/重启虚拟机
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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