SQL Across Multiple Servers

From NazimWIKI
Jump to navigation Jump to search

An example of a shell script which connects to multiple unix hosted databases and runs a simple SQL. This version emails the logfile to people on the mailing list.

 
#!/bin/ksh
#
# Shell script that connects to multiple database servers and runs a SQL
#

MAIL_LIST="nazim at nazimcricket.com"

# Server List
SERVERS='server1 server2 server3'

LOG="/tmp/logfile.log"

> $LOG

for SERVER in $SERVERS
do

sqlplus -s username/password@$SERVER << EOF | tee -a $LOG
select * from global_name;
exit;
EOF

done

uuencode ${LOG} ${LOG} | mail -s "Results Log" ${MAIL_LIST}