我目前有这个脚本...
#!/bin/bash
# Check NGINX
nginxstat=$(service nginx status)
# Checking Sites
hostsite="localhost:81 - "$(curl --silent --head --location --output /dev/null --write-out '%{http_code}' http://localhost:81 | grep '^2')
##########
# Send to Slack
curl -X POST --data '{"channel":"#achannel","username":"Ansible", "attachments": [{"fallback":"NGINX Reload","pretext":"'"$HOSTNAME"'","color":"good","fields":[{"title":"nginx localhost","value":"'"$hostsite"'","short":true},{"title":"NGINX","value":"'"$nginxstat"'","short":true}]}]}' -i https://xxx.slack.com/services/hooks/incoming-webhook?token=xxx
我已经尝试了又失败了;我想获取 nginx 配置测试的结果并将其推入。在运行此之前,nginx 重新加载开始,重新加载会自行进行配置检查,因此如果配置错误,服务器会保持运行状态。所以我的 nginx 状态命令(有效)显示
NGINX
----------------
nginx (pid 1234) is running...
但是我无法在配置测试中得到相同的结果,我希望这是由于所需转义的性质以及它抽出的其他垃圾
nginx: [warn] "ssl_stapling" ignored, issuer certificate not found
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful