The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-27-2008
chrisb345 chrisb345 is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 9
fi

Does anybody know what is wrong here. I am running centOS
Code:
the anticrash gives me this.

#!/bin/sh

while true
do
  rm banme.tmp
  :> banme.txt
  /usr/sbin/tcpdump -p -c 100 -n -i eth0 "dst host 66.197.12 6.19 and udp port 7777" >banme.tmp 
  grep "length 0" banme.tmp | cut -f 3 -d " " | cut -f 1-4 -d "." >> banme.txt
  if [ `grep -c . banme.txt` -gt 0 ]
  then
    ip=`head -1 banme.txt`
    if [ `grep -c ${ip} /etc/sysconfig/iptables` -eq 0 ]
    then
      dat=`date`
      echo "${dat} adding ${ip} to iptables" >> banme.log
      /sbin/iptables -A INPUT -s ${ip} -j DROP      
      /sbin/iptables-save > /etc/sysconfig/iptables
    else
      echo "${ip} is already in iptables" 
    fi   //LINE 20<<
  fi
  sleep 0
done
[root@inerdtech control]# sh ./anticrash.sh
: command not founde 2:
./anticrash.sh: line 20: syntax error near unexpected token `fi'
'/anticrash.sh: line 20: ` fi
  #2 (permalink)  
Old 07-27-2008
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,423
Comment the red part of of your fi command :
Code:
    else
      echo "${ip} is already in iptables" 
    fi   # //LINE 20<<
Jean-Pierre.
  #3 (permalink)  
Old 07-27-2008
chrisb345 chrisb345 is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 9
Quote:
Originally Posted by aigles View Post
Comment the red part of of your fi command :
Code:
    else
      echo "${ip} is already in iptables" 
    fi   # //LINE 20<<
Jean-Pierre.
the comment doesnt exist in the real script it was simply used to show what line it was any ideas
  #4 (permalink)  
Old 07-27-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,312
The script seems to be proper, check the file with vi, do you see a ^M at the end of a lines?
  #5 (permalink)  
Old 07-27-2008
grahamb grahamb is offline
Registered User
  
 

Join Date: Dec 2005
Location: Windsor, Ont Canada
Posts: 13
// is not comment marker

Hi
I used # in line 20, thus:
Code:
    fi   # //LINE 20<<
That works!
Graham
  #6 (permalink)  
Old 07-27-2008
chrisb345 chrisb345 is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 9
[root@inerdtech control]# sh ./anticrash.sh
: command not founde 2:
./anticrash.sh: line 20: syntax error near unexpected token `fi'
'/anticrash.sh: line 20: ` fi #//LINE20

these are what i get if i use the #//line20 and also no i donot have ^M any other suggestions?
  #7 (permalink)  
Old 07-27-2008
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,423
  1. Try to execute your script with the command :
    Code:
    /bin/sh ./anticrash.sh
  2. Execute your script with the debug option, and show us the output:
    Code:
    which sh
    sh -vx ./anticrash.sh

Jean-Pierre.
Closed Thread

Bookmarks

Tags
cut, dos2unix, echo, grep, iptables, line terminators, tcpdump

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:40 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0