为什么以下脚本会出现以下错误:
./check1.sh: line 10: Hi,: command not found
./check1.sh: line 21: syntax error: unexpected end of file
检查1.sh:
#!/bin/bash
subj="host `hostname`"
healthcheckstatus=$(curl -s -o /dev/null -w '%{http_code}' http://localhost)
body="Hi, Application is up"
body1="Hi, Application is down"
mailbody=$([ "$applicationstatus" == 200 ] && $body || $body1)
if [ $healthcheckstatus != "200" ]
then
mail -s "$subj" [email protected] <<EOS
`echo -e $mailbody`
EOS
fi
echo "email subject ::$subj"
echo "email body ::$mailbody"
答案1
线路分配mailbody
错误。您正在将$body
和/或 的内容$body1
作为 shell 命令行进行调用。
代替
mailbody=$([ "$applicationstatus" == 200 ] && $body || $body1)
和
[ "$applicationstatus" = 200 ] && mailbody="$body" || mailbody="$body1"