To find out the logs count


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting To find out the logs count
# 1  
Old 06-30-2009
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  
Old 07-01-2009
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  
Old 07-01-2009
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  
Old 07-01-2009
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  
Old 07-01-2009
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  
Old 07-01-2009
Ok
redirect this output to a file
output > new_File
for counting did you mean the first field greater than 100?
# 7  
Old 07-01-2009
yes, it should be greater than 100...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to find the count of IP addresses that belong to different subnets and display the count?

Hi, I have a file with a list of bunch of IP addresses from different VLAN's . I am trying to find the list the number of each vlan occurence in the output Here is how my file looks like 1.1.1.1 1.1.1.2 1.1.1.3 1.1.2.1 1.1.2.2 1.1.3.1 1.1.3.2 1.1.3.3 1.1.3.4 So what I am trying... (2 Replies)
Discussion started by: new2prog
2 Replies

2. UNIX for Beginners Questions & Answers

How to count respon time max min avg for nginx logs?

Hi All, need your help, i want count respon time max and average my nginx logs, based on hourly or minutes per api... my nginx.log sample : 10.1.1.1 - - "POST /v2/api/find/outlet/ HTTP/1.1" 200 2667 "-" "okhttp/3.12.0" "118.215.153.47" 0.178 0.178 . 10.1.1.1 - - "POST... (4 Replies)
Discussion started by: fajar_3t3
4 Replies

3. UNIX for Dummies Questions & Answers

How to Find zipped logs?

from time to time, I received an alert, let's call it "alert_name"but in order to run the script that loads the missing data, I need to check firs if the logs have been zipped out, how can I do this? I Know: 1.- Name of the alert. 2.- Server where it runs. (4 Replies)
Discussion started by: JLo5621
4 Replies

4. Shell Programming and Scripting

Find logs between two timestamp

Suppose there are log entries like 16 Jul 2012 11:46:45,628 SendToClientService ExecuteThread: '256' for queue: 'weblogic.kernel.Default (self-tuning)': Received an unknown fault. 16 Jul 2012 11:47:45,650 SendToClientService ExecuteThread: '256' for queue: 'weblogic.kernel.Default... (4 Replies)
Discussion started by: snehasish_jana
4 Replies

5. Shell Programming and Scripting

Pattern count on rotating logs for the past 1 Hr

Hi All, I have a requirement to write a shell script to search the logs in past 1 hour and extract some pattern from it and count it cumulatively to a file. The problem which I'm facing here is - logs rotates on size basis, say if size of log reaches 5 MB then new log will be generated and... (7 Replies)
Discussion started by: Gem_In_I
7 Replies

6. Shell Programming and Scripting

Count number of errors within logs for last 6 months

I have directory /test/logs which has multiple logs: audit.log audit.log.1 audit.log.2 audit.log.3 audit.log.4 audit.log.5 audit.log is current log file and audit.log.X are archive log files. I need to search within these log files and count word "error-5" logged within last 6 months... (4 Replies)
Discussion started by: djanu
4 Replies

7. Shell Programming and Scripting

To find latest set of logs among new and old

Hi All I am writing a script which will select the latest logs (which are generated every night via a script) among old one and new. Script generates set of 3 logs each time it runs. Example : log-WedJun082011_bkt1.log log-WedJun082011_bkt2.log log-WedJun082011_bkt3.log I have... (1 Reply)
Discussion started by: ratneshnagori
1 Replies

8. Shell Programming and Scripting

Grep string from logs of last 1 hour on files of 2 different servers and calculate count

Hi, I am trying to grep a particular string from the files of 2 different servers without copying and calculate the total count of its occurence on both files. File structure is same on both servers and for reference as follows: 27-Aug-2010... (4 Replies)
Discussion started by: poweroflinux
4 Replies

9. Shell Programming and Scripting

How to find the password in the logs and remove the log which indicate it.

I want to crypt my files but as you know I have to write the password in the xterm...as you know there is a log where every thing I write in the xterm are store on it..how can I get the logs and delete the record which indicate my password..or prevent the xterm from storing my password in the... (2 Replies)
Discussion started by: ahmad.diab
2 Replies

10. UNIX for Dummies Questions & Answers

find logs

hi friends, how do i modify the "find" command to search for large files with *.log extension along with a mtime parameter for files that are 30days, 1yr, 2yr old . please help my dear friends, thanks in advance (2 Replies)
Discussion started by: cromohawk
2 Replies
Login or Register to Ask a Question