vi /backups/alertlog_monotor.sh
#!/bin/bash
SERNAME=srv1.xyz.com
SERPUBIP=192.168.72.50
SERVER=`hostname` #### Sets the server name for the email
WEEKDAY=`date '+%w%H%M'` #### Sets the number value of the day of the week
DATE_VAR=`date '+%Y_%m_%d'`
Error_log_loc=/data/mysql
egrep 'Error' $Error_log_loc/$SERNAME.err |sort -u > $Error_log_loc/$SERNAME_ALERTLOG.txt
cat $Error_log_loc/$SERNAME.err >> $Error_log_loc/$SERNAME_Archived_ALERTLOG.txt
cat /dev/null > $Error_log_loc/$SERNAME.err
if [ -s "$Error_log_loc/$SERNAME_ALERTLOG.txt" ] ; then
cat $Error_log_loc/$SERNAME_ALERTLOG.txt | mail -s "URGENT -ERROR in Alert Log File for $SERNAME ($SERPUBIP) at `date` " ssdas@24x7-itsupport.com
fi
# Weekly alert log datestamp and compress (Sunday 00:15)
if [[ $WEEKDAY -eq 00015 ]]; then
mv $Error_log_loc/$SERNAME_Archived_ALERTLOG.txt $Error_log_loc/$SERNAME_Archived_ALERTLOG_${DATE_VAR}.log
gzip $Error_log_loc/$SERNAME_Archived_ALERTLOG_${DATE_VAR}.log
fi
exit 0
:wq (save & exit)
Now Schedule the above script in crontab for every 15mins.
crontab -l
*/15 * * * * /backups/alertlog_monotor.sh
#!/bin/bash
SERNAME=srv1.xyz.com
SERPUBIP=192.168.72.50
SERVER=`hostname` #### Sets the server name for the email
WEEKDAY=`date '+%w%H%M'` #### Sets the number value of the day of the week
DATE_VAR=`date '+%Y_%m_%d'`
Error_log_loc=/data/mysql
egrep 'Error' $Error_log_loc/$SERNAME.err |sort -u > $Error_log_loc/$SERNAME_ALERTLOG.txt
cat $Error_log_loc/$SERNAME.err >> $Error_log_loc/$SERNAME_Archived_ALERTLOG.txt
cat /dev/null > $Error_log_loc/$SERNAME.err
if [ -s "$Error_log_loc/$SERNAME_ALERTLOG.txt" ] ; then
cat $Error_log_loc/$SERNAME_ALERTLOG.txt | mail -s "URGENT -ERROR in Alert Log File for $SERNAME ($SERPUBIP) at `date` " ssdas@24x7-itsupport.com
fi
# Weekly alert log datestamp and compress (Sunday 00:15)
if [[ $WEEKDAY -eq 00015 ]]; then
mv $Error_log_loc/$SERNAME_Archived_ALERTLOG.txt $Error_log_loc/$SERNAME_Archived_ALERTLOG_${DATE_VAR}.log
gzip $Error_log_loc/$SERNAME_Archived_ALERTLOG_${DATE_VAR}.log
fi
exit 0
:wq (save & exit)
Now Schedule the above script in crontab for every 15mins.
crontab -l
*/15 * * * * /backups/alertlog_monotor.sh