Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 12-12-2011, 06:37 PM   #1
LQ Newbie
Registered: Jun 2011
Posts: 4

Rep: Reputation: Disabled
Batch Log File Count number of "unknown user” algorithm


How can I write a script that extracts number "Unknown User" from a log file?


At 2011-12-07 03:04:21.902: 250 OK^M
At 2011-12-07 03:04:21.902: 550 "Unknown User"^M
At 2011-12-07 03:04:21.902: 503-All RCPT commands were rejected with this error:^M
503-"Unknown User"^M
503 Valid RCPT command must precede DATA^M
At 2011-12-07 03:04:21.902: Sent: RSET^M

At 2011-12-07 03:04:21.941: 250 Reset OK^M
Log-Entry-Offset/Size: 608761155/0000663^M
Content-ID: 1121995/20029_1 892879 HU^M
Status-Attempt-Session-Error: 1:1:2d:0^M
Date: Wed Dec 07 03:04:21 EST 2011^M
At 2011-12-07 03:04:21.491: Sent: MAIL FROM:<>^M

Old 12-12-2011, 09:18 PM   #2
LQ Guru
Registered: Apr 2005
Posts: 5,817

Rep: Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002

You can use "grep" to grep out what you need, and use it within a for loop, counting as you go with a variable. On a side note though, you should use the command "dos2unix" on your file to convert it, since I am seeing "^M" in your file.


Old 10-14-2014, 05:50 AM   #3
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 178Reputation: 178
grep '"Unknown User"' logfile.txt | wc -l


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
PostFix + ISPConfig mail return "unknown user" or "no such user here" Jacky444 Linux - Server 1 02-10-2010 05:21 PM
how to delete last number/word of a file and incude file count at the end of the chennaiguy Linux - Newbie 2 02-18-2008 10:08 PM
Can't log in, "User's $HOME/.dmrc file is being ignored...." georgecrisp Ubuntu 9 02-06-2008 04:35 PM
New SQUID user: How to clear the "access.log" and "store.log" automatically? yuzuohong Linux - Networking 2 12-02-2006 06:37 AM
Count number of line in a file. philipina Programming 7 03-18-2004 06:04 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:33 PM.

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