避免在bash脚本中多次重新启动httpd服务
我有一个shell脚本,用于检查错误并返回状态“0”(全部正常)或“1”(需要修正)。我希望在检查失败时添加一个httpd restart命令(这将理想地解决问题)。但是,我不希望服务重新启动太频繁,不要超过4次 下面是shell脚本:避免在bash脚本中多次重新启动httpd服务,bash,sh,telegraf,Bash,Sh,Telegraf,我有一个shell脚本,用于检查错误并返回状态“0”(全部正常)或“1”(需要修正)。我希望在检查失败时添加一个httpd restart命令(这将理想地解决问题)。但是,我不希望服务重新启动太频繁,不要超过4次 下面是shell脚本: response=$(curl -s --max-time 15 --header ‘Host: xyz.testurl.com’ "https://localhost/login/creds.kcc?&TARGET=https:xyz.testurl.
response=$(curl -s --max-time 15 --header ‘Host: xyz.testurl.com’ "https://localhost/login/creds.kcc?&TARGET=https:xyz.testurl.com" --insecure 2>/dev/null)
if [ "$response" = "error_msg" ]
then
echo "Service,host=$prd,pattern=errocheck value=1"
else
echo "Service,host=$prd,pattern=errocheck value=0"
fi
我可以在if循环中附加一个服务httpd restart
命令,但这意味着每次错误检查失败时它都会重新启动服务。我想对重启进行某种控制
如果您的问题是正确的,我们将不胜感激
- 如果“$response”=“error\u msg”,则执行“service httpd restart”
- 但是,重启次数不超过4次
#!/bin/bash
for n in $(seq 4)
do
response=$(curl -s --max-time 15 --header ‘Host: xyz.testurl.com’ "https://localhost/login/creds.kcc?&TARGET=https:xyz.testurl.com" --insecure 2>/dev/null)
if [ "$response" != "error_msg" ]; then
exit 0
fi
service httpd restart
sleep 10 # temporary solution
done
exit 1