944,184 Members | Top Members by Rank

Ad:
Jan 14th, 2005
0

Passing a variable with a password to the SU command

Expand Post »
I am trying to install 2 rpm files that need root privileges. However, I don't want to prompt the user twice. Currently I am doing the following in my script:

echo "*************************************************************"
echo "In order to install acme package, you need to log in as root"
echo "*************************************************************"
su -c "ACME_QUIET=y rpm -ivh /home/acmeUser/acme_install/components/acme/acme*"
echo "**************************************************************************"
echo "In order to install acmebase package, you need to log in as root."
echo "**************************************************************************"
su -c "rpm -ivh /home/acmeUser/acme_install/components/acme/acmebase*"

The above works just fine. However, they have to login twice.

I would like to do something like this:


echo "*************************************************************"
echo "In order to install acme package, you need to log in as root"
echo "*************************************************************"
read PASSWORD

I would then like to give the $PASSWORD variable to the SU command somehow. I just can't seem to figure it out. Another option would be to use SUDO (so people tell me), but I thought you had to configure it before hand. This is a script that is run on many many machines and I can't configure SUDO for this purpose. Does anyone have an idea on how to get around this?

Thanks!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
stharmon is offline Offline
8 posts
since Nov 2004
Jan 14th, 2005
0

Re: Passing a variable with a password to the SU command

Quote originally posted by stharmon ...
I am trying to install 2 rpm files that need root privileges. However, I don't want to prompt the user twice. Currently I am doing the following in my script:

echo "*************************************************************"
echo "In order to install acme package, you need to log in as root"
echo "*************************************************************"
su -c "ACME_QUIET=y rpm -ivh /home/acmeUser/acme_install/components/acme/acme*"
echo "**************************************************************************"
echo "In order to install acmebase package, you need to log in as root."
echo "**************************************************************************"
su -c "rpm -ivh /home/acmeUser/acme_install/components/acme/acmebase*"

The above works just fine. However, they have to login twice.

I would like to do something like this:


echo "*************************************************************"
echo "In order to install acme package, you need to log in as root"
echo "*************************************************************"
read PASSWORD

I would then like to give the $PASSWORD variable to the SU command somehow. I just can't seem to figure it out. Another option would be to use SUDO (so people tell me), but I thought you had to configure it before hand. This is a script that is run on many many machines and I can't configure SUDO for this purpose. Does anyone have an idea on how to get around this?

Thanks!
whats wrong with using the & command?

--HV
Reputation Points: 10
Solved Threads: 4
Junior Poster in Training
HawkeVIPER is offline Offline
72 posts
since Jan 2005
Jan 17th, 2005
0

Re: Passing a variable with a password to the SU command

Quote originally posted by stharmon ...
Another option would be to use SUDO (so people tell me),
That was what I was going to suggest :cheesy:

You can pass the password using a pipe I guess ~ :-|
I know how to do this in perl, but not in bash at the moment ~
Reputation Points: 10
Solved Threads: 0
Light Poster
YUPAPA is offline Offline
42 posts
since Dec 2004
Jan 18th, 2005
0

Re: Passing a variable with a password to the SU command

It looks like I was able to use ; to separate the commands and it worked just fine. I had problems using &

Thanks for the help!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
stharmon is offline Offline
8 posts
since Nov 2004
Jan 18th, 2005
0

Re: Passing a variable with a password to the SU command

I understand what ; does on a command prompt and what not. What I DON'T understand, is how you were able to pass the password to SU with multiple commands (using ; )? So how'd you do it?
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Jan 18th, 2005
0

Re: Passing a variable with a password to the SU command

Quote originally posted by Comatose ...
I understand what ; does on a command prompt and what not. What I DON'T understand, is how you were able to pass the password to SU with multiple commands (using ; )? So how'd you do it?
I wasn't able to "pass" the password to SU. Instead, I combined the commands into one (using . That way the users were only prompted once during the install... If you ever find out how to pass the password to SU, I would like to know as well...
Reputation Points: 10
Solved Threads: 0
Newbie Poster
stharmon is offline Offline
8 posts
since Nov 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: "shell scripting tutorials?"
Next Thread in Shell Scripting Forum Timeline: Why my shell script doesn't delete a file ??





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC