Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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"
share|improve this question
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 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 at 6:52
    
@Patrick: Did that. –  Pavel Šimerda Apr 6 at 6:53

1 Answer 1

up vote 9 down vote accepted

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"
share|improve this answer
1  
Or even: ((applicationstatus==200)) && mailbody="${body}" || mailbody="${body1}" –  devnull Apr 6 at 6:56
    
@devnull: Modified to something in between. –  Pavel Šimerda Apr 6 at 6:59
    
Thanks. That did check one error. But i am still getting unexpected end of file error. –  Novice User Apr 6 at 7:08
1  
Got it to work. thanks –  Novice User Apr 6 at 7:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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