0

I have the current script written to get me into the router.

"plink.exe" -ssh username@host -pw password < "input.txt"

The problem is once I am in the router I need it to enable and then enter another password in before I can execute commands. When I run this script it gets to the enable part but does not enter in the password. From what I am understanding in my "input.txt" I have the command "enable" which it executes, but if I put anything after that it runs it as a new command. After I enter in the "enable" command I need it to enter a password before executing more commands and I can't just put it right underneath "enable" in the "input.txt."

Is there a way to fix this?

Here is the input.txt I have set up

enable
password
config t
(I would like to enter different commands here once in configuration mode)

Thank you for your help.

User7673
  • 1
  • 1
  • 1
    In UNIX systems you can use the `expect` command for this. See if you can install a port of it to windows. Maybe from Mingw or cygwin. – konsolebox Jan 07 '22 at 09:55
  • I will look into that. If I was to use expect where would I put into the script? I am unfamiliar with the expect command. @konsolebox – User7673 Jan 07 '22 at 11:10
  • Expect is more a scripting language so you'd have to look for tutorials and examples on how to use it. It's like a shell as well but is more adept at handling output and controlling input of called processes. – konsolebox Jan 07 '22 at 11:14
  • The password is not a command. It's input of the `enable` "command". So, see [How to pass user input automatically using plink.exe](https://stackoverflow.com/q/34477728/850848). – Martin Prikryl Jan 07 '22 at 11:34
  • I do not your commands/router. But I assume you want to put `enable`, `password`, `config t` lines (+ something like `exit`) to the `input.txt`. – Martin Prikryl Jan 07 '22 at 13:06
  • In your question above, you do not have that. You have `-m "commands file"`, that's not the same as `< "commands file"`. Also, you have `Echo` in each line, what is wrong in either case. So are you saying that neither `< "commands file"` works (without the `echo`s)? Then please edit your question to say that you have tried that, what exactly does your command file look like and give us way more detailed description of the behavior. – Martin Prikryl Jan 07 '22 at 14:09
  • I have corrected the description of behavior. Please let me know if you have any other suggestions or comments. @MartinPrikryl – User7673 Jan 07 '22 at 14:22
  • *"but if I put anything after that it runs it as a new command"* – it does not, not in the case of `<` (it's true for `-m` only). – What exactly happens? Does it get stuck on the password prompt? Where *exactly* is the cursor? Post a screenshot. – Three things to try 1) Try adding `-t` or `-T` to Plink command-line. 2) Try unix line ending in the "command file" 3) Try delaying the `password` input, see [Wait between sending login and commands to serial port using Plink](https://stackoverflow.com/q/55851109/850848). – Martin Prikryl Jan 07 '22 at 14:31
  • Does this answer your question? [How to pass user input automatically using plink.exe](https://stackoverflow.com/questions/34477728/how-to-pass-user-input-automatically-using-plink-exe) – Martin Prikryl Jan 20 '22 at 06:37

0 Answers0