From b1bf90cea8a8abac7ccc4577ec6b8a548b9ca8d2 Mon Sep 17 00:00:00 2001 From: Xlous <35778015+ixmu@users.noreply.github.com> Date: Sat, 15 Jul 2023 22:20:17 +0800 Subject: [PATCH] Update network_monitor.sh --- network_monitor.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/network_monitor.sh b/network_monitor.sh index 9af5bd0..b70f098 100644 --- a/network_monitor.sh +++ b/network_monitor.sh @@ -1,5 +1,8 @@ #!/bin/bash +#生成断网自动重启脚本 +cat > /opt/network_monitor.sh<< EOF +#!/bin/bash while true; do if ping -c 1 google.com &> /dev/null; then echo "网络连接正常" @@ -9,3 +12,20 @@ while true; do fi sleep 60 done +EOF +chmod +x /opt/network_monitor.sh + +# 检查 /etc/crontab 文件是否包含指定的行 +if grep -q "@reboot root /opt/network_monitor.sh >>/dev/null 2>&1 &" /etc/crontab; then + echo "已存在相应的行,跳过操作。" +else + # 在文件末尾追加指定的内容 + echo "@reboot root /opt/network_monitor.sh >>/dev/null 2>&1 &" | sudo tee -a /etc/crontab > /dev/null + echo "已成功追加内容到 /etc/crontab 文件。" +fi + +# 提示用户按任意键重启 +read -p "按下任意键后将执行系统重启操作。请确保您已保存并关闭所有未保存的工作。按下任意键继续..." + +# 执行系统重启 +sudo reboot \ No newline at end of file