![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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]#
|
|
||||
|
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 |
![]() |
| Bookmarks |
| Tags |
| cut, dos2unix, echo, grep, iptables, line terminators, tcpdump |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|