Home > Debian, Linux, Shell, bash, mysql > Bash script for checking mysql problem by reading daemon.log

Bash script for checking mysql problem by reading daemon.log

August 6th, 2008

 Powered by Max Banner Ads 
#!/bin/bash
 
### Checking del daemon.log per eventuali problemi sul DB MySQL
# rel. 0.3 - 01 Agosto 2008
 
# time_to_check_min=`date +"%b %d %k:%M" -d "-1 min"`
# time_to_check_hour=`date +"%b %d %k:%M" -d "-1 hour"`
file_to_check=/var/log/daemon.log
tmp_file=/tmp/info.tmp.01.$$
tmp_file1=/tmp/info.tmp.02.$$
host=`cat /etc/hostname`
semaphore=/tmp/.flag_checking_daemon_log
 
daemon=mysql
 
if [[ -e $semaphore ]];
  then
    echo "checking for mysqld....Nothing to do ....another cron is still working"
  else
    touch $semaphore
if [[ `date +"%d"` < '10' ]]; then
    time_to_check_min=`date +"%b %d %k:%M" -d "-1 min"| sed -r 's/[[:space:]](0)([1-9])[[:space:]]/  2 /'`
    time_to_check_hour=`date +"%b %d %k:%M" -d "-1 hour"| sed -r 's/[[:space:]](0)([1-9])[[:space:]]/  2 /'`
else
    time_to_check_min=`date +"%b %d %k:%M" -d "-1 min"`
    time_to_check_hour=`date +"%b %d %k:%M" -d "-1 hour"`
fi
#echo "checking for ""$file_to_check  $time_to_check_min"
grep "$time_to_check_min" "$file_to_check" > $tmp_file
grep "$daemon" "$tmp_file" > $tmp_file1
if [[ -e $tmp_file1 ]];
    then
        if [[ -s $tmp_file1 ]]; then
            mail -s "Something happening on [ $daemon ] for ""$host" tech-c@bakeca.it < $tmp_file1
        fi
        #remove the tmp_file
        rm -f $tmp_file
        rm -f $tmp_file1
    fi
   #removing the semaphore
   rm -f $semaphore
fi

Fabio Laganà Debian, Linux, Shell, bash, mysql , , , , ,

  1. No comments yet.
  1. No trackbacks yet.
You must be logged in to post a comment.