config_file="/mnt/share/config.ini"
# 检查是否有命令行参数
if [[ $# -ne 1 ]]; then
echo "Usage: $0 "
exit 1
fi
# 读取命令行参数
section_number=$1
current_section=0
while IFS= read -r line; do
# 检测是否为新的网络段落
if [[ $line =~ ^\[Network ]]; then
((current_section++))
if [[ $current_section -eq $section_number ]]; then
read_network_info=true
else
read_network_info=false
fi
fi
if $read_network_info; then
if [[ $line =~ ^Network\ Adapter= ]]; then
network_adapter=${line#*=}
elif [[ $line =~ ^IP-Cidr= ]]; then
ip_cidr=${line#*=}
elif [[ $line =~ ^IP\ Address= ]]; then
ip_address=${line#*=}
elif [[ $line =~ ^Mask= ]]; then
mask=${line#*=}
elif [[ $line =~ ^Gateway= ]]; then
gateway=${line#*=}
elif [[ $line =~ ^Nezha_secret= ]]; then
nezha_secret=${line#*=}
elif [[ $line =~ ^ddns_domain= ]]; then
ddns_domain=${line#*=}
# 获取所有需要的信息后跳出循环
break
fi
fi
done "$NETWORK_CONFIG" /dev/null; then
echo "网络连接成功,执行下一步。"
connected=true
break
else
echo "网络连接失败,正在重试...(尝试次数:$((attempt + 1)))"
((attempt++))
sleep 5 # 等待5秒后重试
fi
done
if $connected; then
# 网络连接成功,执行下一步
# 启动指定服务
# 列出所有名为nezha-agent的screen会话,并提取其会话ID
screen -ls | grep 'nezha-agent' | cut -d. -f1 | awk '{print $1}' | while read session_id; do
# 结束每一个会话
screen -S "$session_id" -X quit
done
echo "所有名为nezha-agent的screen会话已结束。"
screen -S nezha-agent -d -m /opt/nezha/agent/nezha-agent -s api.baidu.com:443 -p $nezha_secret --tls --debug --disable-auto-update
echo "/mnt/share/nezha1.sh" $nezha_secret
else
echo "网络不可用,即将关机。"
fi
else
echo "The specified section number does not exist."
fi
[/ol]复制代码
screen -S nezha-agent -d -m /opt/nezha/agent/nezha-agent -s api.baidu.com:443 -p $nezha_secret --tls --debug --disable-auto-update
不知道怎么回事 执行到这里 参数就传递不全
手动运行是没问题的