fi

Does anybody know what is wrong here. I am running centOS

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

Comment the red part of of your fi command :

    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

The script seems to be proper, check the file with vi, do you see a ^M at the end of a lines?

Hi
I used # in line 20, thus:

    fi   # //LINE 20<<

That works!
Graham

[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?

  1. Try to execute your script with the command :
    text /bin/sh ./anticrash.sh
  2. Execute your script with the debug option, and show us the output:
    text which sh sh -vx ./anticrash.sh

Jean-Pierre.

[root@inerdtech control]# sh -vx ./anticrash.sh
#!/bin/sh

+ $'\r'
: command not founde 2:
while true
do
  rm banme.tmp
  :> banme.txt
  /usr/sbin/tcpdump -p -c 100 -n -i eth0 "dst host 75.127.119.54 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   #//LINE20
./anticrash.sh: line 20: syntax error near unexpected token `fi'
'/anticrash.sh: line 20: `    fi   #//LINE20
[root@inerdtech control]#

You have a return character "^M" after the lines. Try to remove those characters with:

tr -d '\r' < your_file > new_file

Are you sure that your script file doesn't contain ^M character(s) ?

> cat -v ctrlM.sh
#/usr/bin/bash

# Next line is ctrl-M
^M
date
> sh -vx ctrlM.sh
#/usr/bin/bash

# Next line is ctrl-M

+ $'\r'
ctrlM.sh: line 4: $'\r': command not found
date
+ date
Sun Jul 27 22:34:29     2008
>

Try to remove ^M:

> tr -d '\r' <ctrlM.sh >no_ctrlM.sh
> sh -vx no_ctrlM.sh
#/usr/bin/bash

# Next line is ctrl-M

date
+ date
Sun Jul 27 22:37:49     2008
>

Jean-Pierre.

sorry can you explain this a little more simply i dont understand

The first error happens when an line containing only ^M is executed.
The script ctrM.sh in my previus post shows the error.

You can remove ^M in your script with the tr command (see the example in my post).

Jean-Pierre.

Windows editors produce files that have two characters that define the end of a line - so-called carriage control.

UNIX just uses one character, so files from DOS or Windows show an extra character ascii 13 or control-M == ^M

UNIX shell does not like the ^M character. Delete all of the ^M characters and things will be fine. You can do it with Aigles tr example or with dos2ux (sometimes called dos2unix).

How to get rid of the ^M characters

# way  number 1
dos2ux anticrash.sh > tmfile; mv tmfile anticrash.sh; chmod +x anticrash.sh
#way number 2
tr -d '\r' < aniticrash.sh > newanticrash.sh; chmod +x newanticrash.sh

# note '\r' is the return button or ^M

tcpdump: ioctl: No such device

why am i getting this error

I am now getting error

tcpdump: WARNING: arptype 65535 not supported by libpcap - falling back to cooked socket
Couldn't find user 'pcap'