The UNIX and Linux Forums  

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
Code:
[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]#
  #2 (permalink)  
Old 07-27-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,315
You have a return character "^M" after the lines. Try to remove those characters with:
Code:
tr -d '\r' < your_file > new_file
  #3 (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,426
Are you sure that your script file doesn't contain ^M character(s) ?

Code:
> 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:
Code:
> 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.
  #4 (permalink)  
Old 07-27-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,770
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
Code:
# 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
  #5 (permalink)  
Old 07-28-2008
chrisb345 chrisb345 is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 9
tcpdump: ioctl: No such device

why am i getting this error
  #6 (permalink)  
Old 07-28-2008
chrisb345 chrisb345 is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 9
I am now getting error

tcpdump: WARNING: arptype 65535 not supported by libpcap - falling back to cooked socket
Couldn't find user 'pcap'
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 11:34 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