script to alert for repeated occurrence.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script to alert for repeated occurrence.
# 8  
Old 12-20-2010
Thanks, yes that one is simpler. to be specific to MOD and keep it different from crowd. But i'm getting multiple result. Any idea if the search is being made whole, and each word is looked up individually.

I am trying this command :
Code:
nawk -F'(MOD dn=\"uid=)|[,]' '{u[$2]++}END{for(i in u) if(u[i]>thr) print "user",i,"has crossed ["u[i]"] the thresold limit ",thr}' thr=100 access


Last edited by Scott; 12-20-2010 at 01:53 PM.. Reason: Code tags, please...
# 9  
Old 12-20-2010
You will get message for each user in access file if user count is greater than thresold.
Pls post the output what you are getting if it is unexpected along with expected one.
# 10  
Old 12-20-2010
Actually, i want the search to be restricted to MOD or DEL etc. Not all occurence of "uid".

I want only to search for words having this string (MOD dn=\"uid=).

The error is that it is fetching for these type of rows :

(SRCH dn=\"uid=)

Hope this explains my issue.

Thanks, John.
# 11  
Old 12-21-2010
To restrict the search to MOD or DEL only:
Code:
nawk -F'(MOD dn="uid=)|(DEL dn="uid=)|[,]' '/(MOD dn="uid=)|(DEL dn="uid=)/ {u[$2]++}END{for(i in u) if(u[i]>thr) print "user",i,"has crossed ["u[i]"] the thresold limit ",thr}' thr=100 access

# 12  
Old 12-21-2010
Thanks You !

Yes, it is working now. However, i am wondering what is the purpose of the below specified string, just for understanding sake and usability in other command :

Code:
 "[,]' '/(MOD dn="uid=)|(DEL dn="uid=)/"

Also, as i plan to set the threshold too high, i wound like the command to sent a email with the content whenever the mod/del goes over the set threshold. Is it possible to put it in the same command?

Regards - John.

Moderator's Comments:
Mod Comment Please use code tags when posting data and code samples!

Last edited by Franklin52; 12-21-2010 at 02:33 PM..
# 13  
Old 12-21-2010
In above command:
Code:
 
-F'(MOD dn="uid=)|(DEL dn="uid=)|[,]'

This sets field separator to uid value as second field. e.g. in Input line
Code:
 
[20/Dec/2010:09:41:15 -0500] conn=867199 op=17 msgId=21 - MOD dn="uid=acp100,ou=internal,ou=People1,dc=abc,dc=xxx,dc=com"

Here bold, red strings are field separators.
1st green string becomes 1st field i.e. $1
and 2nd green string becomes 2nd field i.e. $2 (And $2 is used while further procesing)
Then
Code:
/(MOD dn="uid=)|(DEL dn="uid=)/

This is a searach pattern. This will make sure that only those lines get processed which has MOD dn="uid= OR MOD dn="uid= as substring. Without this search pattern, all lines will be processed which gives undesired result.

To send output as an email, pipe the output to mailx command as below (Put real value for TO_EMAIL_ID value, say.. xxx@yyy.com and modify "Thresold Email" as the subject of your email.
Code:
nawk -F'(MOD dn="uid=)|(DEL dn="uid=)|[,]' '/(MOD dn="uid=)|(DEL dn="uid=)/ {u[$2]++}END{for(i in u) if(u[i]>thr) print "user",i,"has crossed ["u[i]"] the thresold limit ",thr}' thr=100 access | mailx -s 'Thresold Email' TO_EMAIL_ID


Last edited by anurag.singh; 12-22-2010 at 04:35 AM..
# 14  
Old 12-21-2010
Thanks a Lot !
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Cybersecurity

**ALERT**ALERT* Whats app requesting users to upgrade to latest version as; its vulnerability found.

Hello All, Want to share here an article for Whats app users that team whats app is requesting users to upgrade to its latest version since they have found a vulnerability; where Hacker could turn on a cell's camera, mic and scan messages and emails. Here is an article from "THE VERGE" for... (1 Reply)
Discussion started by: RavinderSingh13
1 Replies

2. Shell Programming and Scripting

sed print from last occurrence match until the end of last occurrence match

Hi, i have file file.txt with data like: START 03:11:30 a 03:11:40 b END START 03:13:30 eee 03:13:35 fff END jjjjjjjjjjjjjjjjjjjjj START 03:14:30 eee 03:15:30 fff END ggggggggggg iiiiiiiiiiiiiiiiiiiiiiiii I want the below output START (13 Replies)
Discussion started by: Jyotshna
13 Replies

3. UNIX for Beginners Questions & Answers

awk script to find repeated IP adress from trace file (.tr)

+ 8.00747 /NodeList/0/DeviceList/0/$ns3::PointToPointNetDevice/TxQueue/Enqueue ns3::PppHeader (Point-to-Point Protocol: IP (0x0021)) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 63 id 0 protocol 17 offset (bytes) 0 flags length: 540 10.1.3.3 > 10.1.2.4) ns3::UdpHeader (length: 520 49153 >... (11 Replies)
Discussion started by: Nipa
11 Replies

4. Shell Programming and Scripting

Substitute first occurrence of keyword if occurrence between two other keywords

Assume a string that contains one or multiple occurrences of three different keywords (abbreviated as "kw"). I would like to replace kw2 with some other string, say "qux". Specifically, I would like to replace that occurrence of kw2 that is the first one that is preceded by kw1 somewhere in the... (4 Replies)
Discussion started by: M Gruenstaeudl
4 Replies

5. Shell Programming and Scripting

Shell script for alert

Hi Experts, Im new in shell script , please help to achieve the below requirement, We have some replication setup in unix server, in that if there is any exception or error occurs immediately the rep_exception.log will have the exception detail, this log will be updated if any error occurs no... (8 Replies)
Discussion started by: pandiyan
8 Replies

6. Programming

Not a repeated question (Perl Script Create Football Formation)

https://www.unix.com/programming/252468-perl-script-create-football-formation.html https://www.unix.com/members/43551.html, it is not repeated question. please read it before u block my question. Unblock it for me. Thanks:mad: (0 Replies)
Discussion started by: Tzeronone
0 Replies

7. Shell Programming and Scripting

Find repeated word and take sum of the second field to it ,for all the repeated words in awk

Hi below is the input file, i need to find repeated words and sum up the values of it which is second field from the repeated work.Im trying but getting no where close to it.Kindly give me a hint on how to go about it Input fruits,apple,20,fruits,mango,20,veg,carrot,12,veg,raddish,30... (11 Replies)
Discussion started by: 100bees
11 Replies

8. Shell Programming and Scripting

How do I put data piped to my script into an array for repeated processing

Hi folks, Sorry for something I'm sure was answered already, I just could not find it in a search of the forums. I am trying to build a script that eats a config file as: cat file.cnf | ConProcess.shWhat I want to do inside the script is: !#/usr/bin/bash # captured piped cat into an... (6 Replies)
Discussion started by: Marc G
6 Replies

9. Shell Programming and Scripting

Script - Filter data - repeated loop - Help needed...

Dear Friend, I need a help for the below problem.. Can anyone suggest me to do... Input file data: rule { name=mainrule filt=pos loc { x=right + 660 y=top - 3100 } object_kind= DRAW ... (15 Replies)
Discussion started by: vasanth_vadalur
15 Replies

10. Shell Programming and Scripting

Email alert script

I need to code a script, which will run via cron, every 30 minutes. The script will read a file containing a date&time and number (which represents disk space). The file gets appended to every 30 minutes. Here's a sample of the file: CPU 1:04/25/02 1:00 am:1972554 CPU 1:04/25/02 1:30... (1 Reply)
Discussion started by: moon
1 Replies
Login or Register to Ask a Question