Note: Technical Talk being moved to:
www.nazimcricket.com/wiki


Tuesday, 13 April 2010

Oracle Shell Script - Emailing the Logfile

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@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}

No comments: