Cassandra Shell Scripts Technologies

Shell Script to monitor Cassandra system.log for errors :

[OR]
Grep current hour and last one hour statements from logfile:
[OR]
Get last one hour messages from logfile using sed command:


Crontab entry:

00,05,10,15,20,25,30,35,40,45,50,55 * * * * /u01/scripts/system_log_check.sh 1> /u01/logs/system_log_check.log 2>&1

system_log_check.sh

#! /bin/sh
Script Name : system_log_check.ksh
By : Kishore Uppala
Date : 8/8/2019
Description : Sends alert, if "Too many pending remote requests" error found in system log .

Version : Initial
MailId="nagakishore64@gmail.com"
export CONTENT="/tmp/system_log_check.html"
export SUBJECT="[CRITICAL] : Errors found in system log of $HOSTNAME [hostname -i] at date. Please check immediatly"
echo "Errors in System Log" > /tmp/system_log_check.html
echo "<pre>-------------------------------------------------------------</pre> " >/tmp/system_log_check.out
#Search Present hour, last hour log statements for keyword "Too Many Pending" and append the matched statements to the file.


sed -n "/$(date -d -1hour +"%Y-%m-%d %H:")/,/$(date +"%Y-%m-%d %H:") /p" /var/log/cassandra/system.log|grep -i "Too many pending"|tail >>/tmp/system_log_check.out


echo "Script Last Ran @ " `date `

echo "<HTML>
<HEAD></HEAD>
<BODY>
<TABLE border="1">
<TR><TD><br>
`cat /tmp/system_log_check.out`
<br\></TD></TR>
</TABLE>
</BODY>
</HTML>">>/tmp/system_log_check.html

strings=`grep -i 'Too many' /tmp/system_log_check.html | wc -l`

if [ $strings -ne 0 ]
then
(
echo "TO :$MailId"
echo "Subject: $SUBJECT"
echo "MIME-Version: 1.0"
echo "Content-Type: text/html"
echo "Content-Disposition: inline"
cat $CONTENT) | /usr/lib/sendmail -r 'Cassandra-DBA' $MailId
fi

Comments Rating 0 (0 reviews)

About the author

BestTechReads

Add Comment

Click here to post a comment

Sending

Categories

Categories