The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to find one partucular user logs when there are lots of users running on it ksr.test UNIX for Advanced & Expert Users 4 10-07-2008 04:39 AM
find logs cromohawk UNIX for Dummies Questions & Answers 2 10-03-2008 05:27 PM
find out the line count over FTP connection Rita_questions UNIX for Dummies Questions & Answers 1 03-12-2008 09:25 AM
to grep and find the count arunkumar_mca UNIX for Dummies Questions & Answers 4 11-12-2007 11:55 AM
Find occurances of a directory and count stringman Shell Programming and Scripting 2 08-18-2005 04:20 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-30-2009
gsiva gsiva is offline
Registered User
  
 

Join Date: Dec 2008
Location: coimbatore
Posts: 107
To find out the logs count

Hi,

I am using the below command to find out the mail logs which will grep the repeated message ids:
Code:
less /var/log/messages  |awk '{print +$6}'| sort | uniq -c | sort -nr
OUTPUT:
Code:
    506 1246382279
    404 1246373467
    303 1246383457
    303 1246382268
    300 1246379705
    202 1246383452
    202 1246383448
    202 1246382281
    201 1246383456
    201 1246382284
    201 1246379685
    201 1246374656
    200 1246383453
I am trying to get this to be emailed when if the counts exceeds more than 100 via shell script implementing through cron . but I am not good in shell scripting. can you please advice me on this.

Last edited by Yogesh Sawant; 07-01-2009 at 03:33 AM.. Reason: added code tags
  #2 (permalink)  
Old 07-01-2009
anchal_khare anchal_khare is offline
Registered User
  
 

Join Date: Jun 2007
Location: Mumbai,India
Posts: 325
try:

Code:
count=$(/var/log/messages |awk '{print +$6}'| sort | uniq -c | sort -nr | wc -l)
if [ $count -ge 100 ];then
echo "some body" | mailx -s "WARNING:: Message" "someone@somewhere.com" 2> /dev/null
fi
  #3 (permalink)  
Old 07-01-2009
gsiva gsiva is offline
Registered User
  
 

Join Date: Dec 2008
Location: coimbatore
Posts: 107
Hi anchal,

Thank you for your reply.

Let me be more specific on my query.

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 hope it make sense.
  #4 (permalink)  
Old 07-01-2009
rakeshawasthi rakeshawasthi is offline
Registered User
  
 

Join Date: Aug 2004
Location: India
Posts: 379
Are you sure you are getting this output:
Code:
506 1246373453
404 1246373467
303 1246383457
303 1246382268
300 1246379705
I get this..
Code:
   1 1246373453|jason@abc.com|djuba9@aol.com|2227|success|1
   1 1246373453|jason@abc.com|djtc7109@aol.com|2227|success|1
   1 1246373453|jason@abc.com|djt1000@aol.com|2227|success|1
   1 1246373453|jason@abc.com|djsussma@oakland.edu.uk|2227|success|1
   1 1246373453|jason@abc.com|djstuder@yahoo.com|2227|success|1
   1 1246373453|jason@abc.com|djstaffo@yahoo.com|2227|success|1
  #5 (permalink)  
Old 07-01-2009
gsiva gsiva is offline
Registered User
  
 

Join Date: Dec 2008
Location: coimbatore
Posts: 107
No, I got only the count and not the email. Okay that not an issue. I am trying with redirecting the output to a file and the file should count which has to be done via shell script. Please help me on this ...
  #6 (permalink)  
Old 07-01-2009
rakeshawasthi rakeshawasthi is offline
Registered User
  
 

Join Date: Aug 2004
Location: India
Posts: 379
Ok
redirect this output to a file
output > new_File
for counting did you mean the first field greater than 100?
  #7 (permalink)  
Old 07-01-2009
gsiva gsiva is offline
Registered User
  
 

Join Date: Dec 2008
Location: coimbatore
Posts: 107
yes, it should be greater than 100...
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:24 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0