3

Why would the following script give following errors :

./check1.sh: line 10: Hi,: command not found  
./check1.sh: line 21: syntax error: unexpected end of file

check1.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" me@domain.com <<EOS
`echo -e $mailbody`
EOS
fi
echo "email subject ::$subj"
echo "email body ::$mailbody"
  • 3
    The line assigning mailbody is wrong. You're calling the contents of $body and/or $body1 as a shell command line. – Pavel Šimerda Apr 6 '14 at 6:51
  • @PavelŠimerda you should post that as an answer. I was about to, but your comment showed up, so you can have it :-) – Patrick Apr 6 '14 at 6:52
  • @Patrick: Did that. – Pavel Šimerda Apr 6 '14 at 6:53
9

The line assigning mailbody is wrong. You're calling the contents of $body and/or $body1 as a shell command line.

Replace

mailbody=$([ "$applicationstatus" == 200 ] && $body || $body1)

With

[ "$applicationstatus" = 200 ] && mailbody="$body" || mailbody="$body1"
  • 1
    Or even: ((applicationstatus==200)) && mailbody="${body}" || mailbody="${body1}" – devnull Apr 6 '14 at 6:56
  • @devnull: Modified to something in between. – Pavel Šimerda Apr 6 '14 at 6:59
  • Thanks. That did check one error. But i am still getting unexpected end of file error. – Novice User Apr 6 '14 at 7:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.