Mailing List
Home
Forum Home
Linux - General Red Hat Linux discussion list
Enterprise Linux 3 - Discussion of Red Hat Enterprise Linux 3 (Taroon)
Installation - Getting started with Red Hat Linux
Red Hat Linux 9 - Discussion of Red Hat Linux 9 (Shrike)
Red Hat Linux 7.3 - Discussion of Red Hat Linux 7.3 (Valhalla)
Red Hat Linux 7.2 - Discussion of Red Hat Linux 7.2 (Enigma)
Apache Web Server
Oracle database, Microsoft SQL server ...
Subjects
application/x mplayer2 plugin
RPM error: db4 error(16) from dbenv >remove: Device or resource
   busy
Command stream end of file while reading
X Windows problem (xauth)
Upgrading openoffice 1 1 rpm
FTP: connection refused
FTP: connection refused
mount: /dev/cdrom: is not a valid block device
Dell Precision 650, RedHat 9, no sound
how to trace the cause resulting in the crash of bind server
Virus on the list
UNINSTALL RPM MYSQL
usb pen drives: mounting as a user
broadcom network interface
make mrproper
sendmail configuration on redhat
Couldn 't open PID file /var/run/named/named pid Permission denied
Promise 378 controller
kernel 2 6 and /dev/sound/mixer not found
Problem using up2date
mrtg step by step howto/configuration for a newbie?
Compiling and Installing Kernel 2 6
Can 't locate module ppp0, can 't locate module ppp compress 21
HOW I CAN MAKE BOOTABLE FLOPPY DISKET
Lotus Notes under Wine
/etc/security/limits conf question
Intel E/1000 driver
Command stream end of file while reading
rpm database corrupt
qla2300 modules
 
Search:  
Power your search with and, or, +, -, or "some phrase" operators.
script needed

script needed

2005-08-05       - By Michael Velez

 Back
Reply:     1     2     3     4     5     6     7     8     9     10     >>  

I'd say something like this should work:

#!/bin/bash

IPADDRLIST=`tail -50 /var/log/messages | grep "<line pattern>" | awk '{print
$<ip addr field number>}' | sort | uniq`

for IPADDR in $IPADDRLIST
do
  IPADDRCNT=`tail -50 /var/log/messages | grep "<line pattern>" | grep
-c $IPADDR`

  if [[ $IPADDRCNT -ge 10 ]]
  then
    echo $IPADDR >> /etc/hosts.deny
  fi
done

where <line pattern> is the pattern of the line you're looking for in the
messages file and <ip addr field number> is the field number of the IP
address in the line found, where fields are any group of characters
separated by a white space.

The first grep will give you a list of all IP addresses.  The for loop will
then loop through that list and find the line count number for each IP
address.  If greater than 10, concatenate to the hosts.deny file (NOTE: I've
never used that file so I don't know if pure appending results in the right
format. You may have ot change that part).

Also, the awk may not give you the IP address on its own since I don't know
the format of that line either (you need to check and change if necessary).
If not you may have to add an extra step in the pipe after the awk to just
get the IP address.

In any case, the above should point you in the right direction,
Michael



> -- --Original Message-- --
> From: redhat-list-bounces@(protected)
> [mailto:redhat-list-bounces@(protected)] On Behalf Of kmail
> Sent: Friday, August 05, 2005 1:16 AM
> To: redhat-list@(protected)
> Subject: script needed
>
> Hello all,
>
> I need a script to read the last 50 lines for example from
> the messages log and look for repeated ftp access attempts,
> then when the number of attempts exceeded 10 or any
> configurable number, then that ip will be appended to the
> hosts.deny file, or, something can help preventing that kind of attack
>
> any idea ?
>
> Thanks
>
>
>
> ---
> This message has been scanned for viruses and dangerous
> content by MailScanner and is believed to be clean.
>
> --
> redhat-list mailing list
> unsubscribe mailto:redhat-list-request@(protected)?subject=unsubscribe
> https://www.redhat.com/mailman/listinfo/redhat-list
>

--
redhat-list mailing list
unsubscribe mailto:redhat-list-request@(protected)?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list

Earn $52 per hosting referral at Lunarpages.