Tag Archives: GROUP

Help in finding last-1-hr exceptions (server wise) using tentakel

By sarah-alikhan31

Code:

[root@server-A]# cat test.sh
#!/bin/sh
dt_1=`date +%h" "%d", "%Y%l -d "1 hour ago"` #Apr 05, 2013 1 --- if ran at 02 AM
dt_2=`date +%p -d "1 hour ago"` # AM|PM
echo $dt_1
echo $dt_2

tentakel -g GROUP "hostname; cat /opt/logs/log.out | grep -A2 "$dt_1:" | grep -v "$dt_2"" > /tmp/test/last_hr_logs.txt

# Here I can grep the txt file for exceptions. But I also need to maintain the list of server/hostname on which the exceptions have been observed.
#cat /tmp/test/last_hr_logs.txt |grep 'Exception'| awk -F'Exception:' '{print $2}'|sort | uniq -c >> /usr/bin/simran/test/Hourly_Exception_Report.txt
[root@server-A]#


Scenario:
I have a server( A) where I want to run this script. This server has passwordless ssh connection to 10 prod. servers .And I can easily run ‘tentakel’ on A, as configured.
This script needs to fetch the last-1-hr exceptions & their count from 10 different log files being generated on these live/prod. servers.
( The name and the location of the log file remains the same on these 10 servers.)
Once I have the exception/count from each of the 10 servers, I can mail it and also dump it on the local DB that I have.

Earlier i thought of finding the no. of lines in a log file with wc -l and use a second wc -l on the log file to find out how many more lines were added
at the time of next run & then just tail the difference and execute ‘tentakel’ to grep -A2 ‘Exception’.
Finally, I would have saved the last wc -l into a separate file for the next run.
something like:

Code:

tentakel -g GROUP "hostname; tail -n $addedLines /opt/logs/log.out | grep -A2 'Exception'" >> /tmp/temp-file


However, saving the last line count in $addedLines is not helping me, since I am using the same script to be executed on 2nd server , 3rd server and so on….in a single instance of script execution :(. The logs on servers-2nd, 3rd.. are obviously not the same and I dont want to use so many variables to keep count on it.

Now, I am using the above(test.sh) solution based on date-timestamps as checkpoints in log files…but stuck & not able to move further
& I have had many versions on this script…
🙁 someone gotto help me on this asap !!

Experts, I definately need help here!!

…read more

Source: FULL ARTICLE at The UNIX and Linux Forums