LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 02-05-2006, 05:33 PM   #1
willigiann
Member
 
Registered: Nov 2004
Posts: 46

Rep: Reputation: 15
grep messages


Hello everyone!
I am getting many attacks everyday and i start to get annoyed with it. I have open only SSHD and thats where i am receiving all the attacks. So i was thinking somehow to block those specific IP's when they attacking me. So i want somehow to automaticly put all the IPs (Only) into a file and then block them. The problem is that grep returns all the line and not only the IP.
For example if i run cat /var/log/messages | grep sshd | grep Failed
it will return Jan 31 15:33:48 server sshd[10982]: Failed password for named from 65.254.61.170 port 42024 ssh2
Now, i know a command "split" that i can use it to get back only the 65.254.61.170 but i have no idea how to use it!
Any ideas?
 
Old 02-05-2006, 07:12 PM   #2
bulliver
Senior Member
 
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86_64; Gentoo PPC; FreeBSD; OS X 10.9.4
Posts: 3,760
Blog Entries: 4

Rep: Reputation: 78
First of all, you have RUOC going on (redundant use of 'cat')

Second, awk will do what you like:
Code:
$ grep sshd /var/log/messages | grep Failed | awk '{print $11}'
65.254.61.170
 
Old 02-06-2006, 08:04 AM   #3
willigiann
Member
 
Registered: Nov 2004
Posts: 46

Original Poster
Rep: Reputation: 15
thank you for your quick answer and your comments.
i tried but here is the output:
server:/home/billg # grep sshd /var/log/messages | grep Failed | awk '{print $11}' 65.254.61.170
awk: cmd. line:1: fatal: cannot open file `65.254.61.170' for reading (No such File or Folder)

I have SuSE 10
 
Old 02-06-2006, 01:10 PM   #4
bulliver
Senior Member
 
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86_64; Gentoo PPC; FreeBSD; OS X 10.9.4
Posts: 3,760
Blog Entries: 4

Rep: Reputation: 78
I think you misunderstand, the '65.254.61.170' is just the output based on the logline you gave me.

Code:
grep sshd /var/log/messages | grep Failed | awk '{print $11}'
is the command you should use...
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Howto tail -f /var/log/messages | grep isdninfo Mopp Programming 4 07-22-2011 10:00 AM
Redirecting the kernel messages to file other than /var/log/messages jyotika_b83 Linux - General 3 04-28-2005 06:39 PM
/var/log/messages full of these messages. Should I be concerned? mdavis Linux - Security 5 04-16-2004 10:08 AM
ps -ef|grep -v root|grep apache<<result maelstrombob Linux - Newbie 1 09-24-2003 11:38 AM
syslog and firestarter - log messages to another file than messages mule Linux - Newbie 0 08-07-2003 03:35 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 06:03 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration