SQL Across Multiple Servers

From NazimWIKI
Revision as of 22:01, 8 November 2019 by Admin (talk | contribs) (Created page with "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. <blockquot...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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}