最佳答案
我试图创建一个简单的Bash脚本,以检查网站是否关闭,由于某种原因"和quot;操作符不工作:
#!/usr/bin/env bash
WEBSITE=domain.example
SUBJECT="$WEBSITE DOWN!"
EMAILID="an@email.example"
STATUS=$(curl -sI $WEBSITE | awk '/HTTP\/1.1/ { print $2 }')
STRING=$(curl -s $WEBSITE | grep -o "string_to_search")
VALUE="string_to_search"
if [ $STATUS -ne 200 ] && [[ "$STRING" != "$VALUE" ]]; then
echo "Website: $WEBSITE is down, status code: '$STATUS' - $(date)" | mail -s "$SUBJECT" $EMAILID
fi
“-a"操作符也不工作:
if [ $STATUS -ne 200 ] -a [[ "$STRING" != "$VALUE" ]]
你还可以建议什么时候使用:
?