Koffee
Koffee

Reputation: 33

Running Unix scripts remotely from Windows terminal and passing back prompts

I'm using plink to run a script on a remote server (Linux) from a Windows machine. Part of the script prompts for inputs (authentication to various other remote servers that use different credentials). I don't want to store the password in the script as each use will be using their own for auditing reasons.

I need the prompt to be transmitted to the Windows terminal window and I need the input transmitted back to the Linux box. Additionally I need to write log all this into a file, like this:

plink username@unixbox /etc/scrips/myscript.bash > report.txt

At the moment the above works but all that prints to report.txt is the prompts

please enter password for reportBox1?
please enter password for reportBox2?

Instead I need it to send the password prompt and input to the Linux box to continue running the script as it normally would, only remotely. So the output of report.txt would read:

please enter password for reportBox1? *
File 1
File 2
File 3
please enter password for reportBox2? *
Data a
data b
data b

Hope that makes sense. If there's something better than plink can be used such as putty's ssh.exe please let me know that one instead.

Upvotes: 1

Views: 769

Answers (1)

zb226
zb226

Reputation: 10529

First off: plink is PuTTY's ssh.exe.

If you want to be able to answer the password prompt on the Windows machine, you need to tell plink to allocate a pseudo-terminal with -t:

plink -t username@unixbox /etc/scrips/myscript.bash

Now you get the prompt and input will be sent back. But if you redirect STDOUT to report.txt...

plink -t username@unixbox /etc/scrips/myscript.bash > report.txt

...you won't see the prompt, because it's redirected into report.txt (although the script still runs and waits for your input). To get around this, you need some tool which allows you to redirect the output to multiple destinations - STDOUT and report.txt at the same time. In the *nix world, the command for this is tee. There are ports of tee for Windows:

Having set one of those up, you'd do:

plink -t username@unixbox /etc/scrips/myscript.bash | tee report.txt

Security note: If the password prompts in the script on the Linux machine echo what was input, the passwords will of course also be logged in report.txt, which might be a problem.

Upvotes: 1

Related Questions