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

16,379

run multiple commands from a file after logging into putty from a bat file

You can't log-in to PuTTY. PuTTY is an SSH client application which has no authentication.

You can use PuTTY to log-in to a server computer which is providing an SSH service. Typically this would be a Linux server. It is the server that requires you log-in to it.

In my abc.txt I have written some commands which I want to be executed on putty itself

You cannot run arbitrary commands on PuTTY itself.

You can use PuTTY to run commands in a shell on the server.

Those commands must be present on the server and supported by the server's operating system.

our abc.txt has just one command: pbrun. It is saying command not found.

That means that the command pbrun is not a valid command on the server's operating system (this is nothing to do with PuTTY).

Not all Linux servers have pbrun:

$ man pbrun
No manual entry for pbrun
$ pbrun
-bash: pbrun: command not found
$ uname
Linux
$

You must also be careful with line-endings on your commands. Windows files edited with notepad are likely to have lines ending with the two ASCII control characters Carriage-Return (CR or Control-M or ^M) and Line-Feed (LF or Control-J or ^J). I would expect PuTTY to take care of this, but it may not (I have not tested this).

$ pwd
/
$ pwd^M
: command not found
$

Update

I used Notepad to create this file, "commands.txt":

echo "this command works"
echo
echo "this command works too"
sleep 20 # so I can see

I used this command:

C:\temp>"C:\Program Files (x86)\PuTTY\putty.exe" rgb@server -m commands.txt

I got this result:

this command works

                  this command works too

I imagine there is some issue with stty or PuTTY settings affecting newline operation, but basically the -m mechanism works and, with some diligent effort, I would expect to be able to make it do useful work correctly.

Share:
16,379

Related videos on Youtube

saiyam
Author by

saiyam

Updated on September 18, 2022

Comments

  • saiyam
    saiyam over 1 year

    I have written a bat file in which I have the following:

    putty.exe -t -load "ABC" -l username -pw password -m "C:\Users\pathasai\Desktop\abc.txt"
    

    In my abc.txt I have written some commands which I want to be executed on PuTTY itself, but when I run the bat file, I am not able to run the commands. I am getting the error command not found. For instance, let us say our abc.txt has just one command: pbrun. It is saying command not found. (I get this error on the putty terminal.)

    How do I get multiple commands to run one after the other from the abc.txt file?

    • saiyam
      saiyam about 9 years
      Hi i am working in windows...and it is working when i normally open putty and connect to the sever and run the commands ..... But with the way i am doing its crating trouble.... And i didnt get your last line ...
    • gogoud
      gogoud about 9 years
      yep, so was I, I mean the machine I was connecting to was linux. If you want to connect to a windows machine it needs to be set up for such remote connection. What type of machine are you connecting to?
    • saiyam
      saiyam about 9 years
      Ummmbthat i need to chk for.....but can u let me know what would be the reason for tgat command not found as from putty directly it is working fine but from txt file its not ..... Pbrun command not found ..... Any special things i need to add to the text file? Or smething like that?
    • saiyam
      saiyam about 9 years
      Ok so u suggest to oonvert that file into unix endings ...?
    • gogoud
      gogoud about 9 years
      yes, that is my suggestion.
    • Martin Prikryl
      Martin Prikryl about 9 years
      What is your SSH server? OpenSSH or other?