Running batch commands through PuTTY serial connection

3

1

I have a sequence of commands which I use to update the firmware on my Linux machine. When I connect to the machine using a serial connection I can type the commands one-by-one and they work fine. I would like to automate this procedure by running the commands in a batch file.

I have a profile for my serial connection saved as 'i5IS-COM4' so I run my first batch file , 'send.bat' , which reads:

commands.bat |  putty -load i5IS-COM4

and commands.bat reads:

echo "this command works!"

When I run 'send.bat' it correctly opens a terminal and connects to my Linux machine but the echo command is not working. If anyone could help me get my batch file to work it would be greatly appreciated!

I have looked over the following post and a number of others, but I have yet to find a solution to my problem.

Run multiple commands from a file after logging into PuTTY from a bat file

edit:

When I use command redirection using plink instead of putty, I just get an empty terminal. Running the following command: start plink.exe -load i5IS-COM4 < commands.txt with commands.txt as follows: echo "this command works!"; /bin/bash returns the following terminal: enter image description here

foxymop

Posted 2018-04-04T21:54:55.873

Reputation: 33

Answers

2

PuTTY is GUI application, not a console application. You cannot use input/output redirection with a GUI application.

There's no way to execute a command on the server automatically with PuTTY over a serial connection.


Though you should be able to use Plink (PuTTY command-line connection tool).

Plink is an equivalent of PuTTY, except that it is a console application, so you can use input/output redirection with it:

commands.bat | plink -load i5IS-COM4

Though as your "bat" file is actually not a batch file (that would produce the commands for the device), but a text file that directly contains the commands for the device, you want to use the contents of the file as an input, rather than output of its execution:

plink -load i5IS-COM4 < commands.bat

Martin Prikryl

Posted 2018-04-04T21:54:55.873

Reputation: 13 764

Thanks for your response Martin. I have used plink instead of PuTTY and I am able to get a terminal open, but neither the syntax you have posted, nor 'start plink.exe -load i5IS-COM4 < commands.bat' have successfully run my commands. – foxymop – 2018-04-17T17:44:57.173

So what did it do? Show us. – Martin Prikryl – 2018-04-18T05:55:36.927

I open a terminal and log into my linux server, then I run the batch file containing the following line: start plink.exe -load i5IS-COM4 < commands.txt commands.txt contains the following line: echo "this command works!"; /bin/bash When I run the batch file I just get a blank plink terminal and if I hit enter I get a prompt from the root user. – foxymop – 2018-04-18T17:30:07.997

Why start? That does not make sense. Remove it. – Martin Prikryl – 2018-04-18T18:29:01.990

Thanks Martin! I just had to remove the 'start' from my file and change the line endings to Unix in my text editor, now I am able to run a sequence of commands through plink! – foxymop – 2018-04-18T20:29:53.567