Multiple server monitoring script
This script logic is useful when you want to extract the data (from database or from OS) from different servers.
For example I have to extract data from 4 servers.
Prerequisites :- Below are the prerequisites
1) Connectivity should be there from your desktop to all servers from where you want to extract the data.
2) "sshpass" package should be installed on your desktop machine (Desktop machine should be Linux machine)
3) You should have Credentials (User/Password and IP) for all servers
Note :- 1) To check the connectivity you can use below command from terminal
ssh -oPort=922 user@IP1
2) To install the "sshpass" package you can use below command
sudo yum -y install sshpass*
Step1:- Make a separate directory for same by below command
mkdir monitoring
Step2:- Move to that directory by below command
cd monitoring
Step3:- Make a report.sh script with below code
cat>report.sh
#!/bin/bash
sshpass -p "password" ssh -q -oPort=922 user@IP1FINAL.txt
sshpass -p "password" ssh -q -oPort=922 user@IP2>FINAL.txt
sshpass -p "password" ssh -q -oPort=922 user@IP3>FINAL.txt
sshpass -p "password" ssh -q -oPort=922 user@IP4>FINAL.txt
Ctr+d (For Save and Exit)
Step4:-Now make host1.sh,host2.sh,host3.sh and host4.sh
Sample code for host1.sh
cat>host1.sh
#!/bin/bash
~/.bash_profile
export ORACLE_HOME=
export ORACLE_SID=
export PATH=$ORACLE_HOME/bin:$PATH:$ORACLE_HOME/OPatch:/usr/bin:/etc:$ORACLE_HOME/lib:/usr/sbin:/usr/ucb:$HOME/bin:/usr/bin/X11:/pacs:.
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/pacs/lib:$LD_LIBRARY_PATH
export LIBPATH=$ORACLE_HOME/lib
sqlplus -s db_user/db_pass<set feedback off;
set heading off;
!echo "Employee Data"
select * fro emp;
!echo "Department Details"
select * from dept;
exit;
STMT
Same way you can create other host script .
Step5:- Give the executable permission to all scripts by below command
chmod a+x *.sh
Step6:- Now execute the report.sh and you will get the all data in FINAL.txt
sh report.sh
For example I have to extract data from 4 servers.
Prerequisites :- Below are the prerequisites
1) Connectivity should be there from your desktop to all servers from where you want to extract the data.
2) "sshpass" package should be installed on your desktop machine (Desktop machine should be Linux machine)
3) You should have Credentials (User/Password and IP) for all servers
Note :- 1) To check the connectivity you can use below command from terminal
ssh -oPort=922 user@IP1
2) To install the "sshpass" package you can use below command
sudo yum -y install sshpass*
Step1:- Make a separate directory for same by below command
mkdir monitoring
Step2:- Move to that directory by below command
cd monitoring
Step3:- Make a report.sh script with below code
cat>report.sh
#!/bin/bash
sshpass -p "password" ssh -q -oPort=922 user@IP1
sshpass -p "password" ssh -q -oPort=922 user@IP2
sshpass -p "password" ssh -q -oPort=922 user@IP3
sshpass -p "password" ssh -q -oPort=922 user@IP4
Ctr+d (For Save and Exit)
Step4:-Now make host1.sh,host2.sh,host3.sh and host4.sh
Sample code for host1.sh
cat>host1.sh
#!/bin/bash
~/.bash_profile
export ORACLE_HOME=
export ORACLE_SID=
export PATH=$ORACLE_HOME/bin:$PATH:$ORACLE_HOME/OPatch:/usr/bin:/etc:$ORACLE_HOME/lib:/usr/sbin:/usr/ucb:$HOME/bin:/usr/bin/X11:/pacs:.
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/pacs/lib:$LD_LIBRARY_PATH
export LIBPATH=$ORACLE_HOME/lib
sqlplus -s db_user/db_pass<
set heading off;
!echo "Employee Data"
select * fro emp;
!echo "Department Details"
select * from dept;
exit;
STMT
Same way you can create other host script .
Step5:- Give the executable permission to all scripts by below command
chmod a+x *.sh
Step6:- Now execute the report.sh and you will get the all data in FINAL.txt
sh report.sh
No comments:
Post a Comment