Script to Conditionally Send Mail Based on Logs
Hey All,
So what I'm attempting to do is search for a particular string in a log file that appears after a certain time. Pull the usernames from the results and count the number of times each username appears. What I'm having trouble with is coming up with a way to trigger an email if any of the usernames appear more than a certain number of times. Here's a simplified snipped of code of what I've done so far. Code:
#!/bin/bash Code:
#!/bin/bash |
Code:
checktime () { Code:
# print username if it appears more than 50 times in the results Code:
# if $results isn't empty, at least one user exceeded the count. email results. Code:
define THRESHOLD |
my usual comment is: do not use pipe chains like grep|awk|sort|uniq, usually it can be solved within a single perl/awk/python/whatever script. It would be more efficient, and every requirement can be implemented - not to speak about the while cycle containing a $(... | awk)!
Especially the function checklogs can be replaced by: awk '$1>=50' Also checkline will look quite similar: awk ' <condition> ' (but it is a bit harder, you need to specify input line format and how/what do you want to check) Next, grep pattern file usually can be replaced by awk '/pattern/' file sort and uniq were also already implemented in awk - and you only need to combine all of it into one single script |
Thanks for the replies; they're both definitely helpful.
|
All times are GMT -5. The time now is 01:32 AM. |