Sign up ×
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.

Can somebody help me debug this simple script. Been trying for 2 hrs now but I cant seem to get it to work.

#!/bin/bash

echo "Search for MMSC or WAP connectivity errors"

sftpErrorCount=$(tail -100 3_ERRORs_log.txt | grep "MMSC_Upload2" | grep "Fail to copy"| awk '{print $1 " " $2" " $3" " $4}'| wc -l)

if [ "$sftpErrorCount" -gt 0 ]
then
sftpErrorDate=$(tail -100 3_ERRORs_log.txt | grep "MMSC_Upload2" | grep "Fail to copy"| awk '{print $1 " " $2" " $3" " $4}'| tail -1)
echo "Error found at around $sftpErrorDate please check FTP logs"

else
echo "No errors found"

Error when I execute the script

sh test_script.sh
Search for MMSC or WAP connectivity errors
test_script.sh: line 14: syntax error: unexpected end of file
share|improve this question

1 Answer 1

up vote 1 down vote accepted

You need to close your if-statement with the word fi.

#!/bin/bash

echo "Search for MMSC or WAP connectivity errors"

sftpErrorCount=$(tail -100 3_ERRORs_log.txt | grep "MMSC_Upload2" |
   grep "Fail to copy"| awk '{print $1 " " $2" " $3" " $4}'| wc -l)

if [ "$sftpErrorCount" -gt 0 ] ; then
    sftpErrorDate=$(tail -100 3_ERRORs_log.txt | grep "MMSC_Upload2" |
      grep "Fail to copy"| awk '{print $1 " " $2" " $3" " $4}'| tail -1)
    echo "Error found at around $sftpErrorDate please check FTP logs"
else
    echo "No errors found"
fi
# ^ This closes the block.

Also note that I made a few styling changes to your script. Indentation can make bugs like these easier to find.

share|improve this answer
    
Thanks alot evan! I think i should rest for a bit these is an embarassing mistake! –  dimas Jul 25 '13 at 1:56

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.