Automatic Server and Database Monitoring mail from local machine

Automatic Server and Database Monitoring mail from local machine


Automatic mail from local machine of "Monitoring of AIX Servers and result of Database Queries"
Following files needed for implementing mail for  "Monitoring of AIX Servers and Database"

1) mailid.txt : You can put all mail ids in this file and system will read this file to send mail.

cat>mailid.txt
abc@example.com
xyz@example.com

2) monitor.sh : This file have all commands and Oracle queries whose result need to be sent by mail

format for monitor.sh file is :-

#!/bin/ksh
#mandatory environment variable need to export
export PATH=
export ORACLE_BASE=
export ORACLE_HOME=
export ORACLE_SID=
export LD_LIBRARY_PATH=

#All commands need to be put here one by one with proper echo details
echo "Start date and time of monitoring:"`date`
echo "Server UP Time:"`uptime`
echo "***********Mount points analysis*************"
df -g
echo "Established Connections Count:"`netstat -a|grep -i ESTABL|wc -l`
echo "Wait Connections Count:"`netstat -a|grep -i WAIT|wc -l`

dbuser=
dbuser=
sqlplus -s $dbuser/$dbpass@$ORACLE_SID <set feed off  echo off colsep '|' verify OFF wrap OFF trimspool ON;
set numwidth 15;
set linesize 30000;
set pagesize 50000;
set serveroutput on size 10000;
set timing off;


exit;
EOF


3) mail.sh :- This file will connect the server, execute the above script and store the output of above script in one file and content of that file will be mailed to all mail IDs which are configured in the mailid.txt file

format for mail.sh file is :-

sshpass -p "" ssh -q -oPort=922 @ip < path_to_monitor.sh>monitoring.txt
cat path_to_monitoring.txt|mailx -r   -s "" ``

4) crontab.txt : This file have cron entry so that we can schedub.txtle cronjob

format for mail.sh file is :-

30 * * * * sh path_to_mail.sh>path_to_log_file

we can schedule cronjob by following command

crontab crontab.txt

 Note 1):- sshpass package should be install on your machine (if not installed then you can install by following command )

yum install sshpass

2) You system should be configure for ipv4 postfix (if not then you can follow following steps to configure)

vi /etc/postfix/main.cf

chnage the vale of "inet_protocols" from all to ipv4 and restart the postfix service by following commands

service postfix restart

No comments:

Post a Comment