Search This Blog

Sunday, 30 August 2020

create the monitor.sh

Step first..we create the monitor.sh file in home "/home"

[root@ab home]#cat > monitor.sh
[root@ab home]#vi monitor.sh
###add following lines to the file

case $1 in
0) tail -100f /var/log/messages;;
1) tail -100f /var/log/secure;;
2) tail -100f /var/spool/mail/root;;
3) tail -100f /var/log/dmesg;;
4) tail -100f /var/log/maillog;;
5) echo "**************************** START **************"
df -h
echo ""
echo "TEMP FILE SIZE : " `du -ch /tmp | tail -1`
echo ""
w
uptime
free -m
date
crontab -l
echo "Files greater than 500MB";;
#find / -type f -size +500000k -exec ls -lh {} \; | awk '{print $9 " : " $5}';;

6) top;;

98) echo "WEBFILE BACKUP STATUS :" ; du -ch /backups/web_backup/* ; echo ""; echo "DB BACKUP STATUS :" ; du -ch /backups/db_backup/*;;

99) echo "BACKUP REPORT OF kmi_192.168.100.125 FOR DATE : " `date`
echo ""
echo "*** BACKUP REPORT FOR kmi - 192.168.100.125  LINUX WEB SERVER ***"
echo "PRIVATE IP :" `/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'`
echo "HOSTNAME :" `localhost`
echo "SCHEDULE TIME OF BACKUP : 00:30 & 20:00 PER DAY"
echo "SCRIPT LOCATION : /home/monitor.sh"
echo "BACKUP LOCATION : /backups/{db_backup,web_backup}"
echo "CURRENT TIME : " `date`
echo "WEBFILE SIZE :" `du -ch /var/www/html | tail -1 | awk '{ print $1}'`
path1=`ls -ltrh /backups/web_backup/ | tail -1 | awk '{ print $9 }'`
echo "WEBFILE BACKUP SIZE :" `du -ch /backups/web_backup/$path1 | tail -1 | awk '{print $1}'`
echo "WEBFILE BACKUP STATUS : "
ls -ltrh /backups/web_backup/

echo "DATABASE SIZE :"
/usr/bin/mysql -u root -predhat -e 'SELECT table_schema "Data Base Name", sum( data_length + index_length ) / 1024 / 1024 "Data Base Size in MB" FROM information_schema.TABLES;'
path1=`ls -ltrh /backups/db_backup/ | tail -1 | awk '{ print $9 }'`

echo "DATABASE BACKUP SIZE :" `du -ch /backups/db_backup/$path1 | tail -1 | awk '{ print $1}'`
ls -ltrh /backups/db_backup

echo "DISK SPACE STATUS : "
df -h
echo "TEMP FILE STATUS :" `du -ch /tmp | tail -1 | awk '{ print $1}'`
echo "MEMORY SPACE STATUS : "
free -m
echo "httpd SERVICE STATUS :" `/sbin/service httpd status`
echo "LIST OF BLOCKED IP :"
cat /var/log/messages | grep "`date +%b` `date +%e --date=\"-1 day\"`" | grep Ban | awk '{print $1" - "$2" - "$3" - " $4 " - " $9}'
;;

*) echo "Wrong Option"
exit;;
esac
................................................

step 2nd -  :wq (save & exit)

step 3rd- give permission to that file

[root@ab home]# chmod 755 monitor.sh

step 4- copy that file to /usr/bin

[root@ab home]# cp -avf monitor.sh /usr/bin/monitor

step 5- go to root bash_profile
#####add these lines

[root@ab ~]#  vi .bash_profile
 
alias m=monitor

step 6 - :wq (save & exit)

Step 7 - Sheduled the crontab

crontab -e

25 13 * * * /home/monitor.sh



Step 8 - now logout & connect again and check status

---------------------------------------------------------

now check

[root@ab ~]# m 99

=====>

BACKUP REPORT OF kmi_192.168.100.125 FOR DATE :  Wed Mar 18 13:23:35 IST 2015

*** BACKUP REPORT FOR kmi - 192.168.72.99 LINUX WEB SERVER ***
PRIVATE IP : 192.168.100.125
/usr/bin/monitor: line 30: localhost: command not found
HOSTNAME :
SCHEDULE TIME OF BACKUP : 00:30 & 20:00 PER DAY
SCRIPT LOCATION : /home/monitor.sh
BACKUP LOCATION : /backups/{db_backup,web_backup}
CURRENT TIME :  Wed Mar 18 13:23:35 IST 2015
WEBFILE SIZE : 4.0K
ls: cannot access /backups/web_backup/: No such file or directory
du: cannot access `/backups/web_backup/': No such file or directory
WEBFILE BACKUP SIZE : 0
WEBFILE BACKUP STATUS :
ls: cannot access /backups/web_backup/: No such file or directory
DATABASE SIZE :
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
ls: cannot access /backups/db_backup/: No such file or directory
du: cannot access `/backups/db_backup/': No such file or directory
DATABASE BACKUP SIZE : 0
ls: cannot access /backups/db_backup: No such file or directory
DISK SPACE STATUS :
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2        28G   14G   13G  52% /
tmpfs           3.0G   76K  3.0G   1% /dev/shm
/dev/sda1       380M   52M  308M  15% /boot
/dev/sda6       2.9G  4.5M  2.7G   1% /home
/dev/sda3       8.6G  519M  7.6G   7% /tmp
/dev/sda5       5.7G  4.1G  1.3G  77% /usr
/dev/sda8       1.9G  323M  1.5G  18% /var
TEMP FILE STATUS : 499M
MEMORY SPACE STATUS :
             total       used       free     shared    buffers     cached
Mem:           988        637        351          0         72        247
-/+ buffers/cache:        316        671
Swap:         2047        141       1906
httpd SERVICE STATUS : httpd is stopped
LIST OF BLOCKED IP :


No comments:

Post a Comment