How to pass argument to PuTTY command file

I have a batch file that runs PuTTY and executes the commands listed in a text file. I want to be able to pass parameters to a text file with my commands that will be executed on a remote server.

This is what I have now -

start C:\Users\putty.exe -load "server" -l userID -pw Password -m commands.txt

Is there a way to pass, for example, the version number as an argument to a file commands.txt?

+4
source share
2 answers

You need to generate commands.txton the fly:

set PARAMETER=parameter
echo ./myscript.sh %PARAMETER% > commands.txt
start C:\Users\putty.exe -load "server" -l userID -pw Password -m commands.txt

Note: to automate tasks, you should use plink.exeinstead putty.exe:

set PARAMETER=parameter
echo ./myscript.sh %PARAMETER% > commands.txt
plink.exe -load "server" -l userID -pw Password -m commands.txt

Plink can even accept a command on the command line, which simplifies your task:

plink.exe -load "server" -l userID -pw Password ./myscript.sh parameter
+4

, .

, Putty, . , Windows Bash. "Execute.txt" ,

@ECHO OFF

set prodhost[1]=host1 <br/>
set prodhost[2]=host2<br/>

ECHO Please select the box where you want to perform checkout.<br/>
ECHO 1. host1 <br/>
ECHO 2. host2<br/>
set /p host="Enter Your Option: "


echo echo "Login and switch user was successful" <br/>
echo hostname <br/>
echo sudo su - 'username' ^<^<  EOF <br/>
echo <br/>
echo EOF <br/>
)>"Execute.txt" <br/>

"plink.exe" -l %username% -ssh !prodhost[%host%]! -m Execute.txt

BottomLine: , , bash, , , Plink.

0

All Articles