Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unexpected end of file in BASH

Writing a simple bash script to do some checks for me in the morning: One part is pulling down some html files and making sure that they exist. The other part is ensuring some local files are present, and emailing if they are not. The problem I am facing is that I am receiving a "syntax error: unexpected end of file" and I can't really understand why it i occuring. Here is a simplified version of the code:

for myHost in $HOSTS
do
  result=$(wget -T $TIMEOUT -t 1 $myHost -O /dev/null -o /dev/stdout)
  result2=$(echo $result | grep "awaiting response")
  connected=$(echo $result | grep "404");
  if [ "$connected" != "" ]; then
    for myEMAIL in $EMAIL
    do
      echo -e "$(date) - $myHost is down! \n This is an automated message." | mailx -r "box.email.com"  -s "$SUBJECT" $myEMAIL
    done
  fi
done

numoffiles=`find . -maxdepth 1 -mtime -1 | grep -i .html | wc -l`
if [ "$numoffiles" -ne 5 ]; then
  FILE=$(find . -maxdepth 1 -mtime -1 -print| grep -i .html)
  mailx -r "box.email.com"  -s "FILE MISSIN" "$EMAIL" << EOF
  EOF
fi

from using sh -x I can see that it gets to assigning the number of reports to the var "numoffiles", but then it just believes that is the end of the file. has anyone got any suggestions?

like image 877
eboni Avatar asked Nov 29 '25 23:11

eboni


1 Answers

There should not be any space before the end of heredoc label:

   EOF
^^^

Change it to

EOF
like image 83
codaddict Avatar answered Dec 02 '25 13:12

codaddict



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!