I have developed a shell script which takes schema id and password as parameter to login into database using sqlplus,runs a query and mails the result.
Below is the code snippet:
{#!/bin/sh
#Two input parameters USER_ID and Password
DB_USER=$1
DB_PWD=$2
result=sqlplus -s $DB_USER@D1TFDDS/$DB_PWD<<EOF spool sample.txt sql query spool off EOF
v1_result=cat sample.txt | sed -e 's/ //g' | tr " " "\n"
echo "${v1_result}" > mail.txt
mailx -s "Samplemail" [email protected] < mail.txt
}
#!/bin/sh
#Two input parameters USER_ID and Password
DB_USER=$1
DB_PWD=$2
result=`sqlplus -s $DB_USER@D1TFDDS/$DB_PWD<<EOF
spool sample.txt
sql query
spool off
EOF`
v1_result=`cat sample.txt | sed -e 's/ //g' | tr " " "\n"`
echo "${v1_result}" > mail.txt
mailx -s "Samplemail" [email protected] < mail.txt
In here am passing id and password as parameter to fetch the result.I do not want to pass my credentials to the script,instead can iI store it in a .txt file with restricted permission.
And pass say environment id and schema name as parameter to the .txtfiletxt file which will give me userid and password.