0

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.

cjm2671
  • 18,348
  • 31
  • 102
  • 161
  • Does it accept data from standard input? Can you pipe the input to it? – Etan Reisner Jun 17 '15 at 14:57
  • I'm not sure; how would I test it? vncpasswd | password\npassword\n ? – cjm2671 Jun 17 '15 at 14:59
  • Test it with `vncpassword <<< password`. Beware though that many programs do not use stdin for passwords for security reasons. – cdarke Jun 17 '15 at 15:01
  • `vncpassword <<<$'password\npassword\n'` or similar. Does vncpasswd *really* require confirmation of the password during login? Or just when setting up the session? Does it really not support a configuration file? – Etan Reisner Jun 17 '15 at 15:07
  • It supports a configuration file, however the password inside it is encrypted. In an ideal world, I'd just run the cypher myself and update the file; but I have no idea what cypher to use and haven't got time to really dig into it. – cjm2671 Jun 17 '15 at 16:58
  • No, it's not, define password simply like that: https://stackoverflow.com/a/61532640/2073804 – ron190 Apr 30 '20 at 21:08

1 Answers1

1

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.