I am trying to write a script that will connect to Oracle from a jump server (i.e) I will execute my script from a jump server, In my script I will have a config file as below
#USERNAME PASSWORD TNSNAMES SUCCESS/FAIL
ODB ODB123 ODB1
CDC CDC123 CDC1
So , Now i will pass the config file in a loop and will execute
${ORACLE_HOME}/bin/sqlplus -S ${USER}/${PASSWORD}@${TNSNAMES}
So by executing the above query for the first time in a loop. It should try logging into the server using the above username and password and it should write into the config file like PASS if the connection succeeded and FAIL if connection failed.
#USERNAME PASSWORD TNSNAMES SUCCESS/FAIL
ODB ODB123 ODB1 PASS
CDC CDC123 CDC1 FAIL
And again it should read the updated config file and if it is PASS it should get into the database and do respective sqls we call. And it should ignore the database if FAIL.
I have tried the below script which will write the contents to other file.
#!/bin/sh
. ~/.ODBenv
cat test.txt | grep '^#' > test1.txt
cat test.txt | grep -v '^#' | awk 'NF'|while read i;do
#if [ -z "$i" ]
#then
#break;
#fi
user_name=`echo $i|awk {'print $1'}`
password=`echo $i|awk {'print $2'}`
TNS_NAME=`echo $i|awk {'print $3'}`
echo "exit" | ${ORACLE_HOME}/bin/sqlplus -S ${user_name}/${password}@${TNS_NAME} |grep -E 'ORA|SP2' > /dev/null
if [ $? -ne 0 ]
then
echo -e "${user_name}\t ${password}\t ${TNS_NAME}\t PASS">>test1.txt
else
echo -e "${user_name}\t ${password}\t ${TNS_NAME}\t FAIL">>test1.txt
fi
done
#done < test.txt|grep -v "^#" | awk "NF"
I tried writing the same contents into a new file and the above script worked.
Any idea how to write in the Original file like PASS/FAIL. Original file is as mentioned below.
#USERNAME PASSWORD TNSNAMES SUCCESS/FAIL
ODB ODB123 ODB1
CDC CDC123 CDC1
echo $i|awk {'print $1'}password=echo $i|awk {'print $2'}TNS_NAME=echo $i|awk {'print $3'}echo "exit" | ${ORACLE_HOME}/bin/sqlplus -S ${user_name}/${password}@${TNS_NAME} |grep -E 'ORA|SP2' > /dev/null if [ $? -ne 0 ] then echo -e "${user_name}\t ${password}\t ${TNS_NAME}\t PASS">>test1.txt else echo -e "${user_name}\t ${password}\t ${TNS_NAME}\t FAIL">>test1.txt fi done `