Hi,
I need to execute the below script for different applications by connecting to different databases:
here iam connecting to only devmwss1 database with username and pwd test/test
now i have to run this script for other databases also. So can i use arrays concept with loop for taking username/pwd/DataBasename while connecting to the DB.
"sqlplus -s $user_name/$p_password@$d_schemaName >$SPOOLFILE "
Code :
#!/bin/sh
echo "---Start of the script---"
SUBJECT="DataBase Reports for MyWorkShop"
TO=ss54488
SPOOLFILE=/home/tmp/output.txt
user_name=test
export user_name
p_password=test
export p_password
d_schemaName=devmwss1
export d_schemaName
cd /apps/NPICOEApps_dev/oracle/10gclient/10.2.0.3/bin
. /apps/NPICOEApps_dev/utils/.oracleprofile
SPOOLFILE=/home/tmp/output.txt
sqlplus -s $user_name/$p_password@$d_schemaName >$SPOOLFILE <<EOF
@/home/tmp/test.sql
exit;
EOF
echo "Send the E-mail message..."
/usr/bin/mailx -s "${SUBJECT}" ${TO} <<-EOF
Hi,
Please find the attached file for DataBase reports
~< ! uuencode $SPOOLFILE `basename $SPOOLFILE'
Thank You
John
EOF
echo "Mailling successfully Done....!"
Below is the test.sql script:
--------------------------
Code :
prompt
prompt "These queries are for MWS"
prompt
select round(sum(bytes)/1024/1024/1024,3) as TOTAL_GB from dba_data_files;
select round(sum(bytes)/1024/1024/1024,3) as FREE_GB from dba_free_space;
exit;
Please help as early as possible...!
Thanks in advance
ss54488
---------- Post updated at 06:54 PM ---------- Previous update was at 12:02 PM ----------
Hi,
Iam able to declare and intilize array by using the below code:
Code :
#!/bin/ksh
echo "---Start of the script---"
SUBJECT="Donot Reply Automated mail for DataBase Reports"
TO=raagadeepthianumakonda@ge.com
SPOOLFILE=/home/lf689708/DataBaseReports.txt
echo "Start of my script"
# Login details for MWS
typeset array_name[0]="ec2_read"
typeset array_name[1]="ec2_read"
typeset array_name[2]="devmwss1"
# Login details for Magic
typeset array_name[3]="magic2_read"
typeset array_name[4]="magic2_read"
typeset array_name[5]="devmgcr1"
# Login details for eNPI
typeset array_name[6]="enpi_read"
typeset array_name[7]="enpi_read"
typeset array_name[8]="devnpis1"
# Login details for iTrak
typeset array_name[9]="extraview_read"
typeset array_name[10]="extraview_r3ad"
typeset array_name[11]="devtrks1"
# Login details for Trackwise
typeset array_name[12]="twsapp_read"
typeset array_name[13]="twsapp_read"
typeset array_name[14]="dev1tws"
cd /apps/NPICOEApps_dev/oracle/10gclient/10.2.0.3/bin
. /apps/NPICOEApps_dev/utils/.oracleprofile
SPOOLFILE=/home/lf689708/DataBaseReports.txt
echo "array length"
tLen=${#array_name[@]}
echo $tLen
loop=0
while [ $loop -le $tLen ];
do
echo "inside while loop"
echo ${array_name[$loop]}
echo ${array_name[$loop+1]}
echo ${array_name[$loop+2]}
echo "connecting to DB"
sqlplus -s ${array_name[$loop]}/${array_name[$loop+1]}@${array_name[$loop+2]} >$SPOOLFILE <<EOF
@/home/lf689708/test.sql
exit;
EOF
echo $loop
loop=`expr $loop + 3`
done
But when iam running this it is throwing the below error:
bash-3.00$ ./arrayEG.sh
---Start of the script---
Start of my script
array length
15
./arrayEG.sh[37]: syntax error at line 44 : `<<' unmatched
bash-3.00$
Please help..!
I need to finish it off by today