LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-27-2014, 08:05 AM   #1
battles
Member
 
Registered: Apr 2014
Distribution: Debian GNU/Linux 7.5 (wheezy)
Posts: 258

Rep: Reputation: Disabled
Can't figure out syntax error


I keep getting this error message running this script. What is causing it?
Line 18 is the last line in the file which I think is a CR.

./Boa404Chk.sh: line 18: syntax error: unexpected end of file


#!/bin/bash

if diff /var/log/boa/access_log /etc/boa_access_bkp >/dev/null
then
exit 0
else
cat /var/log/boa/access_log > /etc/boa_access_bkp
if grep -q '404' '/var/log/boa/access_log'
then
sed 's/404$/===404===/g' '/var/log/boa/access_log > /etc/boa_access_bkp
cd
cat /etc/boa_access_bkp | mail -s "BOA 404 in access_log" me@myisp.net &> /dev/null
cat /etc/boa_access_bkp >> boa_access_dttlbkp #save to send at EOD
cat /dev/null > /var/log/boa/access_log
cat /dev/null > /etc/boa_access_bkp
fi
fi
 
Old 06-27-2014, 08:17 AM   #2
balasaheblalge
LQ Newbie
 
Registered: Jun 2014
Posts: 2

Rep: Reputation: Disabled
Please try using elif instead of else .
 
Old 06-27-2014, 08:28 AM   #3
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,666

Rep: Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970
Quote:
Originally Posted by battles View Post
I keep getting this error message running this script. What is causing it?
Line 18 is the last line in the file which I think is a CR.

./Boa404Chk.sh: line 18: syntax error: unexpected end of file
Code:
#!/bin/bash

if diff /var/log/boa/access_log /etc/boa_access_bkp >/dev/null
   then
       exit 0
   else
      cat /var/log/boa/access_log > /etc/boa_access_bkp
      if grep -q '404' '/var/log/boa/access_log'
      then
         sed 's/404$/===404===/g' '/var/log/boa/access_log > /etc/boa_access_bkp
         cd
         cat /etc/boa_access_bkp | mail -s "BOA 404 in access_log" me@myisp.net &> /dev/null
         cat /etc/boa_access_bkp >> boa_access_dttlbkp   #save to send at EOD
         cat /dev/null > /var/log/boa/access_log
         cat /dev/null > /etc/boa_access_bkp
      fi
fi
Please use the CODE tags when posting scripts...makes things much easier to read. And you're missing the closing single-quote from line 10, after the /var/log/boa/access_log...fixing that seems to fix the script.
Quote:
Originally Posted by balasaheblalge
Please try using elif instead of else .
Would help if you said WHERE to use it, and WHY. Can you post the example code of what you're suggesting?
 
Old 06-27-2014, 08:52 AM   #4
battles
Member
 
Registered: Apr 2014
Distribution: Debian GNU/Linux 7.5 (wheezy)
Posts: 258

Original Poster
Rep: Reputation: Disabled
Thanks. The missing single quote fixed it. I noticed the auto left shift of the script. I guess you just put Code: before a script to correct this?

Last edited by battles; 06-27-2014 at 08:54 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[python] syntax Error : invalid syntax Python_user Programming 2 09-06-2009 12:52 PM
I can't figure out the error message. Gins Programming 42 01-02-2008 12:30 AM
Can't figure out this error MrSako Linux - Software 2 01-06-2007 10:13 AM
C++ syntax error before :: token HELP, i cant find the syntax error :( qwijibow Programming 2 12-14-2004 06:09 PM
Configuration Error can't figure out!! amrogers3 Linux - Newbie 16 01-29-2004 12:36 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:48 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration