How do I respond to a prompt for password in a shell script?

1k views Asked by At

I'm writing a shell script to set a VNC password using vncpasswd.

The only way to use vncpasswd is in interactive mode (enter password, return, confirm password, return).

How can I respond to the prompts in my shell script so I can set the password automatically? (i.e. non-interactive).

Thanks! Chris.

1

There are 1 answers

0
Danny Faught On BEST ANSWER

If the program is reading from your terminal instead of stdin, you'll find that it ignores any data you send in using file redirection. If that's the case, then you can use a program like expect to automate interactions with the terminal using a pseudy-tty. This is exactly the sort of problem it was designed to solve.