Get the details from many servers at Desktop (Script for Multiple Servers Monitoring at Desktop)
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.
Pre-requisites :- Below are the pre-requisites
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 <host1.sh>FINAL.txt
sshpass -p "password" ssh -q -oPort=922 user@IP2 <host2.sh>>FINAL.txt
sshpass -p "password" ssh -q -oPort=922 user@IP3 <host3.sh>>FINAL.txt
sshpass -p "password" ssh -q -oPort=922 user@IP4 <host4.sh>>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=<value for ORACLE_HOME>
export ORACLE_SID=<value for 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<<STMT
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
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.
Pre-requisites :- Below are the pre-requisites
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 <host1.sh>FINAL.txt
sshpass -p "password" ssh -q -oPort=922 user@IP2 <host2.sh>>FINAL.txt
sshpass -p "password" ssh -q -oPort=922 user@IP3 <host3.sh>>FINAL.txt
sshpass -p "password" ssh -q -oPort=922 user@IP4 <host4.sh>>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=<value for ORACLE_HOME>
export ORACLE_SID=<value for 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<<STMT
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
0 comments:
Post a Comment
Note: only a member of this blog may post a comment.