小编Akk*_*kki的帖子

如何编写用于检查网站实时的shell脚本

我正在编写一个shell脚本来监控网站是否存在,并在下面发送电子邮件提醒是我的代码

#!/bin/bash
if [[ curl -s --head  --request GET http://opx.com/opx/version | grep "200 OK" > /dev/null] && [ curl -s --head --request GET http://oss.com/version | grep "200 OK" > /dev/null ]]
then echo "The HTTP server on opx.com and oss.com is up!" #> /dev/null
else
msg="The HTTP server  opx.com Or oss.com is down "
email="opx-noc@opx.com"

curl --data "body=$msg &to=$email &subject=$msg" https://opx.com/email/send
fi;
Run Code Online (Sandbox Code Playgroud)

如果我运行这个代码,我得到了

./Monitoring_Opx_Oss: line 2: conditional binary operator expected
./Monitoring_Opx_Oss: line 2: syntax error near `-s'
./Monitoring_Opx_Oss: line 2: …
Run Code Online (Sandbox Code Playgroud)

bash shell if-statement

4
推荐指数
1
解决办法
2万
查看次数

标签 统计

bash ×1

if-statement ×1

shell ×1