Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

asking for password on db2 script

Status
Not open for further replies.

cougartrace

Technical User
Sep 9, 2003
29
US
I have a script that does DB2 HADR monitoring, however during execution it asks me for the user password - is there anyway to pass that password in the script?


DB2HADRDBNAME=TDWD
#Get the local DB2 instance name
DB2INST=db2tdwd
HADRROLE="UNKNOWN"
HADRSTAT="UNKNOWN"
HADRROLE=$(su - $DB2INST -c "db2pd -hadr -db $DB2HADRDBNAME" |grep -p "HADR Information" |grep -v HADR |grep -v Role | awk '{print $1}')
HADRSTAT=$(su - $DB2INST -c "db2pd -hadr -db $DB2HADRDBNAME" |grep -p "HADR Information" |grep -v HADR |grep -v Role | awk '{print $2}')
if [[ $? = "0" ]];
then
echo "Info: $DB2HADRDBNAME ROLE IS $HADRROLE,
state is in $HADRSTAT state"
exit 0
else
echo "ERROR: CAN NOT GET INFORMATION FOR
$DB2HADRDBNAME "
exit 1
fi
 
Which part asks for a password? The db2pd programme?

Most programmes that ask for a password communicate directly with the terminal, so you usually can't cheat by stuffing the password into standard input. Usually expect works well in those situations. It comes with an autoexpect recording tool which is handy for writing your expect script if you prefer not to do so manually.

Incidentally, seting the variables to "UNKNOWN" is superfluous as those values will be overwritten by the subsequent lines, irrespective of their success or failure.

Also for efficiency I recommend you capture the db2pd output only once and just echo it to your awk and/or grep filters twice to pull out the required pieces of information.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top