LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-01-2009, 08:13 AM   #1
gsiva
LQ Newbie
 
Registered: Apr 2007
Posts: 22

Rep: Reputation: 0
To find out the logs count


Hi,

Under my /var/log/message, the output will be like

Jun 30 09:53:30 server-27 in[28989]: 1246373453|jason@abc.com|djstaffo@yahoo.com|2227|success|1
Jun 30 09:53:31 server-27 in[28989]: 1246373453|jason@abc.com|djstuder@yahoo.com|2227|success|1
Jun 30 09:53:33 server-27 in[28989]: 1246373453|jason@abc.com|djsussma@oakland.edu.uk|2227|success|1
Jun 30 09:53:34 server-27 in[28989]: 1246373453|jason@abc.com|djt1000@aol.com|2227|success|1
Jun 30 09:53:35 server-27 in[28989]: 1246373453|jason@abc.com|djtc7109@aol.com|2227|success|1
Jun 30 09:53:36 server-27 in[28989]: 1246373453|jason@abc.com|djuba9@aol.com|2227|success|1

So, what I am doing is,by using the command, (less /var/log/messages |awk '{print +$6}'| sort | uniq -c | sort -nr), it will give me the ouput as

506 1246373453
404 1246373467
303 1246383457
303 1246382268
300 1246379705

Where:
1246373453 -> 1246373453|jason@abc.com|djstaffo@yahoo.com|2227|success|1

So, the picture of my outcome should be like the output should be redirected to the file and that file should verify the count , if the count exceeds more than of 100, it should send me an email. I am trying this via shell script.

for i in $ ( /var/log/messages | awk '{print $1, $2, +$6}' | sort | uniq -c | sort -nr >> /root/mailalert)
if [ $i -ge 100 ]; then
echo "mail6 alert" | mail -s "WARNING:: SPAM MAIL ALERT" "alerts@internet.com" 2> /dev/null
fi

no luck.
 
Old 07-02-2009, 06:40 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Hello gsiva

A powerful debugging technique is to break up the code into simpler blocks and see if each block is doing what you think it is doing.

Using this technique, what is the output from
Code:
/var/log/messages | awk '{print $1, $2, +$6}' | sort | uniq -c | sort -nr
If that's doing what you wanted it to do, what is the output from
Code:
/var/log/messages | awk '{print $1, $2, +$6}' | sort | uniq -c | sort -nr >> /root/mailalert
What value(s) will that give to $i? If none then the loop will not be executed. It looks like you're expecting a single number -- so why use a loop?

You may find the wc command useful.

Best

Charles
 
  


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
how to find PDF page count mfoley Programming 8 02-26-2009 02:55 PM
I can't find WORD COUNT in Open office! ahh where is it/ mr_coffee Linux - Newbie 9 02-17-2009 01:08 AM
find: WARNING: Hard link count is wrong for /proc/1: Ramonvel Slackware 2 05-27-2008 10:28 PM
qmail can't find my logs :) OTIM Linux - Server 2 12-05-2007 02:27 PM
Logs: What to check and where to find them? Swakoo Linux - General 2 01-12-2006 03:35 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:49 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