Operating System - HP-UX
1819928 Members
3054 Online
109607 Solutions
New Discussion юеВ

Need to learn how to pass user/pass as arguments.

 
SOLVED
Go to solution
Mrg_2
Advisor

Need to learn how to pass user/pass as arguments.

I am working on the below script and do not know how to pass the User ID and password as arguments. You can see I was trying to export the user_id and password but I keep getting errors. I am pretty sure that I am doing it wrong.

Thanks

# It sets up the environment variables needed by the other programs. You must pass in the Oracle User ID and Password as arguments

# ARGUMENTS: 1 - Oracle User Id
# 2 - Oracle Password

export ORACLE_USER_ID=doctor
export ORACLE_PASSWORD=4j88dk8

if [ $# -ne 2 ]
then
echo
echo "Must supply the following arguments in this order: "
echo
echo "User ID"
echo "Oracle Password"
echo
exit
fi



27 REPLIES 27
James R. Ferguson
Acclaimed Contributor
Solution

Re: Need to learn how to pass user/pass as arguments.

Hi:

"Passing arguments" infers declaring them on the command line. For example:

# cat ./showme
#!/usr/bin/sh
[ $# != 2 ] && { print -u2 "Two arguments expected!"; exit 1; }
typeset ID=$1
typeset PASS=$2
echo "ID=${ID} password=${PASS}"

Regards!

...JRF...
Mrg_2
Advisor

Re: Need to learn how to pass user/pass as arguments.

So to insert into my script I would use this format to pass the arguments?

typeset ORACLE_USER_ID=$1
typeset ORACLE_PASSWORD=$2
echo "ORACLE_USER_ID=${doctor} ORACLE_PASSWORD=${4j88dk8}"
James R. Ferguson
Acclaimed Contributor

Re: Need to learn how to pass user/pass as arguments.

Hi:

> So to insert into my script I would use this format to pass the arguments?

The script snippet I showed demonstrates just one way to test for two-arguments (seen by the shell as $1 and $2 when passed in on the command line); give them meaningful names (with or without 'typeset') and echo what was received.

You would run the script like:

# ./showme myid mypass

Regards!

...JRF...
Patrick Wallek
Honored Contributor

Re: Need to learn how to pass user/pass as arguments.

The script that your excerpt is from must be run as:

scriptname doctor 4j88dk8
Mrg_2
Advisor

Re: Need to learn how to pass user/pass as arguments.

Thanks for clearing that last part up.

Below is the text from the script based on what you are saying I would have to pass the arguments in this script then run the script like ./oraclescript.sh myid mypass?:

# This shell should be customized by each state.
# It sets up the environment variables needed by the
# other programs.

# You must pass in the Oracle User ID and Password as arguments

# ARGUMENTS: 1 - Oracle User ID
# 2 - Oracle Password

#if [ $# -ne 2 ]
#then
# echo
# echo "Must supply the following arguments in this order: "
# echo
# echo "User ID"
# echo "Oracle Password"
# echo
# exit
#fi

# ENVIRONMENT VARIABLES
# ORACLE_USER_ID - user id to log in to Oracle
# ORACLE_PASSWORD - password to log in to Oracle
# Ups_Home - path to head directory of UPS
# Ups_In - path to the Transaction update files that
#get uploaded from the units
Patrick Wallek
Honored Contributor

Re: Need to learn how to pass user/pass as arguments.

>>I would have to pass the arguments in this script

I don't understand what you mean by this.

>>then run the script like ./oraclescript.sh myid mypass?:

Yes. Just run the script like that. Nothing else should be required.
James R. Ferguson
Acclaimed Contributor

Re: Need to learn how to pass user/pass as arguments.

Hi (again):

> I would have to pass the arguments in this script then run the script like ./oraclescript.sh myid mypass?:

I suppose you want something like:

#!/usr/bin/sh
[ $# != 2 ] && { print -u2 "Two arguments expected!"; exit 1; }
typeset ORACLE_USER_ID=$1
typeset ORACLE_PASSWORD=$2
export ORACLE_USER
export ORACLE_PASSWORD

Regards!

...JRF...
Viktor Balogh
Honored Contributor

Re: Need to learn how to pass user/pass as arguments.

>typeset ORACLE_USER_ID=$1
>typeset ORACLE_PASSWORD=$2
>echo "ORACLE_USER_ID=${doctor}
ORACLE_PASSWORD=${4j88dk8}"

the last line is wrong. correction:

echo "ORACLE_USER_ID=${ORACLE_USER_ID}
ORACLE_PASSWORD=${ORACLE_PASSWORD}"

you should run your script this way:

# ./showme myid mypass
****
Unix operates with beer.
Viktor Balogh
Honored Contributor

Re: Need to learn how to pass user/pass as arguments.

oww, line breaking made here a pretty disorder...

>echo "ORACLE_USER_ID=${doctor} \
ORACLE_PASSWORD=${4j88dk8}"

the last line is wrong. correction:

echo "ORACLE_USER_ID=${ORACLE_USER_ID} \
ORACLE_PASSWORD=${ORACLE_PASSWORD}"
****
Unix operates with beer.
Mrg_2
Advisor

Re: Need to learn how to pass user/pass as arguments.

I was reading through the arguments section of the manual last night and it appears I will be able to supply the arguments like this:

#scripttorun.sh doctor 4j88dk8

doctor being the username
4j88dk8 being the password

That should work without need to modify the script. Can someone confirm else I will try it tonight and update.
James R. Ferguson
Acclaimed Contributor

Re: Need to learn how to pass user/pass as arguments.

Hi:

> I was reading through the arguments section of the manual last night and it appears I will be able to supply the arguments...[this] should work without need to modify the script. Can someone confirm else I will try it tonight and update.

Write a test script if you are in doubt, or comment-out the pieces that would cause "real work" to be done that you might not want done in a test scenario.

...JRF...
Steven Schweda
Honored Contributor

Re: Need to learn how to pass user/pass as arguments.

Just curious...

> #scripttorun.sh doctor 4j88dk8

When you get this to work, and you start
using it, will any user on the system be able
to use the "ps" command to see this password?
If so, why have a password?
Mrg_2
Advisor

Re: Need to learn how to pass user/pass as arguments.

Thanks James.

I am new to scripting so figuring out how to "pass the username and password" as arguments was really the main issue. I should be able to get it going thanks to this thread.

Steven,

As far as I can tell on my system it cannot be seen with ps. I thought ps would just show running processes not sure how it would pull the username and password or if it is even possible to see with ps. Someone more experienced would be able to answer better. As far as why, to your question, because that is how I was instructed to do it.
Steven Schweda
Honored Contributor

Re: Need to learn how to pass user/pass as arguments.

> As far as I can tell on my system it cannot
> be seen with ps. [...]

On _my_ system:

dy $ uname -a
HP-UX dy B.11.11 U 9000/785 2012616114 unlimited-user license

dy # cat slow.sh
#!/bin/sh
echo "args: $@"
sleep 300
dy # ./slow.sh abc def ghi
args: abc def ghi


Meanwhile, as a normal user:

dy $ ps -ef | grep [s]low
root 3423 1688 0 10:09:20 pts/0 0:00 /bin/sh ./slow.sh abc def ghi

Can you see the arguments? I can.

> I thought ps would just show running
> processes [...]

And your script won't be a running process?
One of us seems to be missing something.

> [...] because that is how I was instructed
> to do it.

And if someone told you to jump off a cliff,
...
Viktor Balogh
Honored Contributor

Re: Need to learn how to pass user/pass as arguments.

though, you can use "ps -efx" and this way all the parameters are listed.
Instead of this, you should prompt for the password in interactive mode, and set the echo off - this way the password won't be visible to the terminal. Here is a hint how to prompt for the password in interactive mode:

#######################################
#!/usr/bin/ksh

echo -n "Please type in your password: "
stty -echo
read PASS
stty echo
echo "\nYour pass is:\t$PASS"

#######################################

This is how it works: (it prints the password at the end)

$ ./get_pass.sh
Please type in your password:
your pass is: test
$

You could write a script that gets the username as the first parameter, and prompts for the pass at runtime...

$ ./myscript.sh username
****
Unix operates with beer.
Viktor Balogh
Honored Contributor

Re: Need to learn how to pass user/pass as arguments.

the above is linux, here is how it is done on HP-UX:

#######################################
#!/usr/bin/ksh
# getpass.sh HP-UX version

echo "Please type in your password: \c"
stty -echo
read PASS
stty echo
echo "\nYour pass is:\t$PASS"

#######################################
****
Unix operates with beer.
Mrg_2
Advisor

Re: Need to learn how to pass user/pass as arguments.

Steven,

While I don't appreciate your tone I do appreciate the content of what you posted. I don't have time to open the admin manual right now so my question is after the process finishes running it is removed from ps, correct?

Viktor,

Thanks for that. Originally that is how the code prompted for a username and password. The reason for the potential switch is that I am trying to find a possible way to cron this process nightly. What I was thinking was:

05 07 * * * /var/scripts/scrun.sh user pass

I have not researched yet if I could set up a cron like that so I may just be spinning my wheels.
Patrick Wallek
Honored Contributor

Re: Need to learn how to pass user/pass as arguments.

>>05 07 * * * /var/scripts/scrun.sh user pass

Yes you can set up a cron job like that. No problems there.

>>...so my question is after the process finishes running it is removed from ps, correct?

Yes, when a process finishes running it is removed from the process table, which is what ps queries.

The risk is that while the script is running, the user name and password WILL be visible in the ps output.

This is a big no no in some auditors eyes. If you are subject audits for SOX, HIPAA, or some of the other myriad legislation, you may get dinged for this.
Mrg_2
Advisor

Re: Need to learn how to pass user/pass as arguments.

Patrick,

Thanks for the information. Our processes are very quick, max 30 seconds. Ultimately is seems you wouldnt want to pass the username and password in that manner if avoidable.

Thanks everyone for you help.
Mrg_2
Advisor

Re: Need to learn how to pass user/pass as arguments.

Solution found in the thread, more good informatin coming. So going to reopen.
Steven Schweda
Honored Contributor

Re: Need to learn how to pass user/pass as arguments.

> Our processes are very quick, max 30
> seconds. [...]

Yeah. No one could possibly write a script
to run "ps" repeatedly, until he got the
desired result.

> Yes you can set up a cron job like that.

Storing a password in a crontab file is just
about as wise as storing it in a shell
script. Or using it on a command line.

> Oct 7, 2009 15:15:43 GMT 2 pts

But what's my opinion worth?
Viktor Balogh
Honored Contributor

Re: Need to learn how to pass user/pass as arguments.


maybe it's not too late. for what reasons do you need a password? maybe it could be solved with a simple passwordless sudo...

****
Unix operates with beer.
Mrg_2
Advisor

Re: Need to learn how to pass user/pass as arguments.

Reopened for more good information.

Viktor,

The first script calls sets the environmental variables and passes the username and password to the next script. This is all new to me so I am not even sure it "passes" it. I do know that as I recieved the first script the instructions stated "# You must pass in the Oracle User ID and Password as arguments".

Here is an snippet from the next script.

# 1. Checks environment variables
# 2. Checks for existence of files to be processed in the /home directory
# 3. Checks then for each individual Mnemomic file. If found, the file is processed by calling a stored pl/sql procedure from the database

# Make sure environment variables are set up properly

EnvironmentOk="Y"

if [ -z ${ORACLE_HOME:-""} ]
then
EnvironmentOk="N"
fi

if [ -z ${ORACLE_USER_ID:-""} ]
then
EnvironmentOk="N"
fi

if [ -z ${ORACLE_PASSWORD:-""} ]
then
EnvironmentOk="N"
fi


Viktor Balogh
Honored Contributor

Re: Need to learn how to pass user/pass as arguments.

Ok, this case step #3 of the second script should be re-written that it runs the pl/sql procedures in the name of the oracle user.
I think it would be the best to make a backup of the second script like this:

cp second.sh second_root.sh

and rewrite this second_root.sh - technically you should insert some sudo in front of the commands. And after that be sure to modify /etc/sudoers with visudo to have the passwordless sudo working!


****
Unix operates with beer.