2

I am writing an automation script with Python in Linux. It calls another process which requires the user to enter a password.

I have implemented it using pexpect where I just spawn the command and then do an interact.

Is there an alternative method? I cannot use pexpect as I need to run a script on a machine which does not have pexpect installed.

1 Answer 1

1

I've seen code that does this with ssh by using things like popen/subprocess and standard streams.

But this is a very bad practice (requires to keep the password in clear text in a relatively easily-accessible place and doesn't allow to change it easily).

  • In fact, the code I mentioned caused a problem at my previous occupation: I installed a client key on the server, and the script didn't any longer see the password prompt when it expected to!

So I do recommend to run the program in such a way (options, configuration files, sudo etc.) that entering a password manually is not needed.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.