我正在尝试使用curl获取少数网站的标题,并在收到404,403,500,503等错误时发送邮件,但我一直收到此错误
错误:
line 7: [: -eq: unary operator expected
代码:
# !/bin/sh
NOW=$(date +"%H:%M_%m-%d-%Y")
web() {
res=$(curl -I -s "$1" -o test/"$1_log_$NOW" | grep HTTP/1.1 | awk {'print $2'})
if [ $res -eq 500 ]
then
echo "Error $res on $1" |mail -s "Error $res at $1 "mail@something.com
fi
}
我设法做我想要的但是我改变了很多剧本:
#!/bin/sh
NOW=$(date +"%H:%M_%m-%d-%Y")
web() {
res=$(curl -I -s $1 | grep HTTP/1.1 | awk {'print $2'})
if [[ "$res" == 500 ||"$res" == 403 || "$res" == 404 ||"$res" == 503 ]]
then
echo "Error $res on $1" |mail -s "Error $res at $1 " somethng@domain.com
fi
echo "$res" > /home/user/test/"$1_log_$NOW"
}
web domain1.com