By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,345 Members | 1,790 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,345 IT Pros & Developers. It's quick & easy.

pass string to a os prompt

P: n/a
I'm writing a script that does some basic pre-configuration for our new
Macs (OSX 10.3.2). I'm trying to enable the root account automatically
with the script, but I don't know how to pass stings to the shell when
it stops and awaits input. For example,

os.popen('/usr/bin/sudo passwd root')

Cause the OS to respond with:

Password:

How do I pass my current user's password to the prompt? I know that I
need to store the password in a string in the script, but I don't know
how to feed it to the waiting shell.

P.S. I know this isn't safe. The script is for config purposes only and
will be used by sys-support personnel who know the root passwords
already. This script just *greatly* automates deployment and helps to
standardise how systems are configured in a lagre environment.

Thanks!

Jul 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Bart,
x = raw_input('enter x: ') enter x: 5 print x
5

or

d = tkSimpleDialog.askstring("","startdate",initialval ue=headDate)


Bart Nessux wrote: I'm writing a script that does some basic pre-configuration for our new
Macs (OSX 10.3.2). I'm trying to enable the root account automatically
with the script, but I don't know how to pass stings to the shell when
it stops and awaits input. For example,

os.popen('/usr/bin/sudo passwd root')

Cause the OS to respond with:

Password:

How do I pass my current user's password to the prompt? I know that I
need to store the password in a string in the script, but I don't know
how to feed it to the waiting shell.

P.S. I know this isn't safe. The script is for config purposes only and
will be used by sys-support personnel who know the root passwords
already. This script just *greatly* automates deployment and helps to
standardise how systems are configured in a lagre environment.

Thanks!


Jul 18 '05 #2

P: n/a
Bart Nessux wrote:
I'm writing a script that does some basic pre-configuration for our new
Macs (OSX 10.3.2). I'm trying to enable the root account automatically
with the script, but I don't know how to pass stings to the shell when
it stops and awaits input. For example,

os.popen('/usr/bin/sudo passwd root')

Cause the OS to respond with:

Password:

How do I pass my current user's password to the prompt? I know that I
need to store the password in a string in the script, but I don't know
how to feed it to the waiting shell.


Look at popen functions. Take one that you can redirect stdin and use
it to enter the input. You can redirect stdout and check it to wait for
"Password:".

Regards,

Nicolas
Jul 18 '05 #3

P: n/a
Bart Nessux wrote:

I'm writing a script that does some basic pre-configuration for our new
Macs (OSX 10.3.2). I'm trying to enable the root account automatically
with the script, but I don't know how to pass stings to the shell when
it stops and awaits input. For example,

os.popen('/usr/bin/sudo passwd root')


Try something like this:

os.system('echo newpass | /usr/bin/sudo passwd --stdin root')

(This works without the sudo while I was logged in as root, but I didn't
try it using sudo.)

-Peter
Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.