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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

change user 1

Status
Not open for further replies.

cantubas

Programmer
Jan 8, 2004
45
FR
can I change the user in a script??

 
Ok, I have a script I use for passing a username/password to log into Oracle. The same method should be able to be used for what you are attempting. I have not tried it, give me some time, and I will try it for you.

First script you would call is get_pw. get_pw calls variable pwfile. pwfile gives the path to a file named do_not_delete which contains the username and password you want to pass in the script. To ensure security, the file do_not_delete is compressed, and renamed. Both files are also hidden.

Example 1: "get_pw"
#!/bin/sh

pwfile=${OPATH}/.do_not_delete

if [ -f $pwfile ]
then
host=$1
sid=$2
account=$3
passwd=`zcat <$pwfile| awk '$1=="'$host'" && $2=="'$sid'" && $3=="'$account'"{print $4}'`
if [ -z "$passwd" ]
then
echo "****Error*** No password found for specified parameters"
exit 1
else
echo $passwd
fi
else
echo "***Error*** You are not set up to use this utility"
exit 1
fi

Note in get_pw: The OPATH is not defined in this script. I am using this as an added level of safety. Since under normal circumstances, this script is called from another script which has set the OPATH variable. If someone with
priviledges runs this script directly, the absense of this variable will cause it to fail.


Example 2: do_not_delete
node sid id pw
hostname ORA1 username password
 
FYI, the following comes from the getpass(3c) man page:

[tt]The getpass() function opens the process' controlling terminal, writes to that device the null-terminated string prompt, disables echoing, reads a string of characters up to the next newline character or EOF, restores the terminal state and closes the terminal.[/tt]

This is the function that is normally used to read passwords. As you can see, it reads the password directly from the terminal and not from stdin.

Dennis
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top