I am using following command in CMD to remotely open Putty (using centos 6) and execute the commands saved inside the file commands.txt saved in the computer.

putty.exe root@ip port -pw password -t -m commands.txt

However it is only working if the commands.txt file is about 5kb size.

Have 2 questions if someone could help, please:

a) Question 1: What should I do so it can run a commands.txt file that is bigger size?

b) Question 2: In CMD if I do 3 command lines with 3 different command files, say "commands1.txt" , "commands2.txt" and "commands3.txt" and paste all jobs below together in CMD it will open 3 putties at same time and do all things at same time.

putty.exe root@ip port -pw password -t -m commands1.txt
putty.exe root@ip port -pw password -t -m commands2.txt
putty.exe root@ip port -pw password -t -m commands3.txt

How do I ask CMD to execute in exact sequence instead of opening everything at same time?

This is, will open the server, execute

putty.exe root@ip port -pw password -t -m commands1.txt

only when finish will execute

putty.exe root@ip port -pw password -t -m commands2.txt

and only when finish will execute

putty.exe root@ip port -pw password -t -m commands3.txt

How to do, so it does't do all 3 jobs together at same time but one after the other in exact order I placed it?

  • While it's a wrong approach anyway, I do not think that, when you add three putty.exe calls to .cmd file, they are executed in parallel. They are executed in sequence. – Martin Prikryl Apr 19 '17 at 19:49
  • Hello Prikryl, thanks for the answer, its working now. However each command it makes from the command.txt it beeps a sound, is there a way to disable this beep? Also, if the file is in the /home/ folder in the server, i tried this but it doesnt get, how could I ask him to get the command.txt file from specific folder? plink -P port username@host < /home/command.txt Thank you very much ! – Joao Apr 19 '17 at 20:27
  • 1) Make sure the file has unix line endings. 2) Your question was about local command file. Remote command file is a completelly different question - Though, just run it! It's also mentioned in my answer. – Martin Prikryl Apr 19 '17 at 20:39
  • Hi Prikryl, thanks replying. As for what I read here I need to convert the commands.txt to unix line endings and then include the quiet mode to not beep, correct? And as for the question here of this topic itself, this would open the command.txt from the root of server: plink -P port username@host < command.txt Would you know what do I need to include so it open command.txt from the folder /home/ ? Thanks – Joao Apr 19 '17 at 21:02
  • No! That command reads a local file, not a file from root folder of the server! – Martin Prikryl Apr 19 '17 at 21:07

The command size limitation is imposed by the server, it's not PuTTY limitation.

One solution is to upload the file to the server (e.g. using psftp or pscp), grant it x permissions and then use PuTTY to execute it.

Though the right tool to automate command execution is PLink (from PuTTY package).

The Plink is a console application, so it can read the commands from a standard input. This way, there's no limitation, as the command are read and executed one by one (as if you type those in shell):

plink -P port username@host < command.txt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.