Reputation: 965
I have a simple bash script:
echo "Hello!"
read varname
echo "you entered " $varname
So it outputs "Hello!" and then accepts user input and outputs text that was entered.
The script can be successfully executed using PuTTY.
Also I can run the script using Plink via Windows cmd
. I connect to host:
plink.exe -batch -i C:\path\to\key.ppk user@host
And then I change directory and run the script:
cd mydir
bash myscript.sh
The script works as required: prints "Hello!" and then ask for input and prints the input.
However if I run the script with the same string with Plink connection:
plink.exe -batch -i C:\path\to\key.ppk user@host bash ./mydir/myscript.sh
I get the following misfunction: I see "Hello!" output and the cursor is blinking on the next line. But I can't type any character there. The console simply does not react on any key and even on Enter. The only one way to continue is to press Ctrl+C to close the connection.
So how to solve this and make the script to accept input using cmd + Plink if a script is executed using a single line?
Upvotes: 3
Views: 1974
Reputation: 202262
When you specify a command on Plink command-line, it executes the command in non-interactive session (without a terminal emulation).
Use -t
switch to force a use of an interactive session (terminal emulation):
plink.exe -batch -t -i C:\path\to\key.ppk user@host bash ./mydir/myscript.sh
Upvotes: 4