pass string to a os prompt

Discussion in 'Python' started by Bart Nessux, Feb 20, 2004.

  1. Bart Nessux

    Bart Nessux Guest

    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!
     
    Bart Nessux, Feb 20, 2004
    #1
    1. Advertising

  2. Bart Nessux

    wes weston Guest

    Bart,

    >>> x = raw_input('enter x: ')

    enter x: 5
    >>> print x

    5

    or

    d = tkSimpleDialog.askstring("","startdate",initialvalue=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!
    >
     
    wes weston, Feb 20, 2004
    #2
    1. Advertising

  3. 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
     
    Nicolas Fleury, Feb 20, 2004
    #3
  4. Bart Nessux

    Peter Hansen Guest

    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
     
    Peter Hansen, Feb 20, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Amelyan
    Replies:
    1
    Views:
    701
    Karl Seguin
    Jul 3, 2005
  2. McGeeky

    Prompt user for connection string

    McGeeky, May 7, 2007, in forum: ASP .Net
    Replies:
    12
    Views:
    573
    McGeeky
    May 7, 2007
  3. gaurav kashyap
    Replies:
    2
    Views:
    646
    gaurav kashyap
    Oct 30, 2008
  4. gaurav kashyap
    Replies:
    3
    Views:
    715
    gaurav kashyap
    Oct 31, 2008
  5. Mel
    Replies:
    10
    Views:
    3,193
    Sailaja Appi
    Feb 13, 2009
Loading...

Share This Page