2011-06-29 123 views
3

早上寫一個簡單的bash腳本來爲我做一些檢查: 一部分是拉下一些html文件並確保它們存在。 另一部分是確保一些本地文件存在,如果不存在則發送電子郵件。 我面臨的問題是我收到一個「語法錯誤:意外的文件結束」,我無法真正理解爲什麼它發生。 下面是代碼的簡化版本:BASH中的文件意外結束

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 

從用sh -x我可以看到,它得到分配的報告,VAR「numoffiles」的數量,但後來它只是認爲這是結束的文件。有沒有人有任何建議?

回答

6

不應該有定界符標籤結束前的任何空間:

EOF 
^^^ 

將其更改爲

EOF 
+0

最好的,我不能相信我錯過了。感謝您的幫助 – eboni

+3

@ user185572:不客氣。不要忘記將答案標記爲已接受。 – codaddict