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" [email protected] <<EOS
`echo -e $mailbody`
EOS
fi
echo "email subject ::$subj"
echo "email body ::$mailbody"
3
  • 3
    The line assigning mailbody is wrong. You're calling the contents of $body and/or $body1 as a shell command line. Apr 6, 2014 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 :-)
    – phemmer
    Apr 6, 2014 at 6:52
  • @Patrick: Did that. Apr 6, 2014 at 6:53

1 Answer 1

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"
3
  • 1
    Or even: ((applicationstatus==200)) && mailbody="${body}" || mailbody="${body1}"
    – devnull
    Apr 6, 2014 at 6:56
  • @devnull: Modified to something in between. Apr 6, 2014 at 6:59
  • Thanks. That did check one error. But i am still getting unexpected end of file error. Apr 6, 2014 at 7:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .