Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Seemingly simple question, which yields slightly undesired results.

Execute putty to start a script on a remote linux server which requires user input

The remote script does a read -p "Please enter name" NAME
I can use plink to execute a script over SSH, the following attempts and problems are shown below :- Note the -load ns is to load a session that doesnt exist, ie ensure no defaults are used

1) plink.exe -load ns <ip_addr> -l <user> -pw <password> <script path/name> Problem) Doesn't allow/show user input, ie its non-interactive.

2) Add -t to allocate a pty :-
plink.exe -t -load nc <ip_addr> -l <user> -pw <password> <script path/name> Problem) Ok, so now the user input can be seen, but I get Ctrl+H (^H) when backspace is pressed, ok if the user doesnt make a mistake!

3) Use putty instead with a saved session
putty.exe -load "SavedSession"
Problem) (a) Get a new window opened, not a biggy, but not as nice. (b) saved session cannot be easily moved. (c) Get password prompt, cannot provide password like with plink, I know I know, use keys, but this is a closed, private network, and its easier not to bother with keys!

So ideally, I would like the SSH to execute in-line, that is from within the batch file/command line shell I am in, not prompt for username/password, run the linux script and allow prompts and delete/backspace to work.

Many thanks for any ideas/solutions in advance.

share|improve this question
up vote 2 down vote accepted

Add -t to allocate a pty ... Ok, so now the user input can be seen, but I get Ctrl+H (^H) when backspace is pressed

Make your script run [ -t 0 ] && stty erase ^H and the Backspace key should be accepted.

An even better solution is to use a port of OpenSSH – for example, that from Cygwin or MinGW – it will give you full terminal emulation as PuTTY does, but keep it in the console window. (The plink tool is designed for raw 8-bit data transfers.)

Edit: A downside of Cygwin might be its lack of IPv6 support (if I remember correctly).

Get password prompt, cannot provide password like with plink

[...] but this is a closed, private network, and its easier not to bother with keys!

And yet you have a problem which setting up keys would solve :)

(I'll feel bad for saying this, but PuTTY also accepts -pw.)

share|improve this answer
Thanks, but I dont understand how to use the [ -t 0 ] && stty erase ^H, is that on the windows side? ie something like plink.exe [ -t 0 ] && stty erase ^H -load nc <ip_addr> -l <user> -pw <password> <script path/name> obviously doesnt work. – IanVaughan Jun 27 '11 at 11:56
Yes I know, use keys! I could use -pw but not in conjunction with loading a Saved Session, of which is the only way to launch a script/command with Putty. ie either putty.exe -load SessionName (allows a script to be saved in the session settings, and ran) Or putty.exe -t -load nc <ip_addr> -l <username> -pw <password> just dumps you in a shell, I have to write this for dummies to use, so no typing in the shell! – IanVaughan Jun 27 '11 at 12:00
re Comment#1, Ok, i was being stupid! Added it into the Linux shell script and it seems to work great! Will check back in a min when fully tested! Cheers!!! – IanVaughan Jun 27 '11 at 12:03
And re OpenSSH via Cygwin or MinGW, would be nice, but this is a portable upgrade script, of which I can ship putty/plink binaries with the scripts, which tho not imposable with Cygwin (no idea about MinGW) is slightly harder to create portable versions of (or so I believe, anyway im going off-topic..) – IanVaughan Jun 27 '11 at 12:11
@IanVaughan: Well, AFAIK, you only need to ship ssh.exe, cygwin1.dll (or the equivalent MinGW runtime DLLs) and maybe libssl.dll. – grawity Jun 27 '11 at 12:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .