LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Logging for FTp Daemon (https://www.linuxquestions.org/questions/linux-newbie-8/logging-for-ftp-daemon-775948/)

wjs1990 12-15-2009 09:30 PM

Logging for FTp Daemon
 
Hi all,
I tried using the following command on a red hat system:

FILE=""
if [ -f /etc/vsftpd.conf ]; then
FILE="/etc/vsftpd.conf"
else
FILE="/etc/vsftpd/vsftpd.conf"
fi
if [ -f $FILE ]; then
awk '/^#?xferlog_std_format/ \
{ print "xferlog_std_format=NO"; next };
/^#?log_ftp_protocol/ \
{ print "log_ftp_protocol=YES"; next };
{ print }' ${FILE}-preCIS > ${FILE}
if [ `egrep -c log_ftp_protocol ${FILE}` == 0 ]; then
echo "log_ftp_protocol=YES" >> ${FILE}
fi
chown root:root $FILE
chmod 0600 $FILE
echo "diff ${FILE}-preCIS $FILE"
diff ${FILE}-preCIS $FILE
else
echo "OK - No /etc/vsftpd.conf."
fi

However, the system return me an error saying, "syntax error near unexpected token `fi'. I suppose the it is trying to say that there are some errors near the last "fi". Any ideas?

Thanks.

alunduil 12-15-2009 09:39 PM

It looks like the problem is a missing \. Please put long code segments in tags in the future, but I think this is what you wanted:

Code:

FILE=""
if [ -f /etc/vsftpd.conf ]; then
  FILE="/etc/vsftpd.conf"
else
  FILE="/etc/vsftpd/vsftpd.conf"
fi
if [ -f $FILE ]; then
  awk '/^#?xferlog_std_format/ \
    { print "xferlog_std_format=NO"; next };
    /^#?log_ftp_protocol/ \
    { print "log_ftp_protocol=YES"; next }; (MISSING \ ?)
    { print }' ${FILE}-preCIS > ${FILE}
  if [ `egrep -c log_ftp_protocol ${FILE}` == 0 ]; then
    echo "log_ftp_protocol=YES" >> ${FILE}
  fi
  chown root:root $FILE
  chmod 0600 $FILE
  echo "diff ${FILE}-preCIS $FILE"
  diff ${FILE}-preCIS $FILE
else
  echo "OK - No /etc/vsftpd.conf."
fi

Regards,

Alunduil

wjs1990 12-15-2009 09:55 PM

I tried inserting the "\", but the problem is still there.

Regards
JS

chrism01 12-15-2009 10:18 PM

Well, usually it also gives the linenum when that happens. Can you show the exact & entire err msg.
One option for you to try is to put

set -xv

as the 2nd line of your script ie just after the
#!/usr/bin/bash

type line.
The set cmd will show you exactly what's happening.

alunduil 12-15-2009 11:31 PM

Just a note, but you can actually just change the shebang line to read: #!/bin/bash -xv as well.

Regards,

Alunduil

wjs1990 12-16-2009 02:23 AM

Thanks all.


All times are GMT -5. The time now is 08:06 PM.