Create A Batch File Or Shortcut To PuTTY (ssh) That Opens A Session And Runs A Command


Answer :

Use the commandline PuTTY version plink.exe to initate a SSH connection to a host of choice. Use the -ssh switch to connect with SSH. With the -m switch you can include a command file:



plink.exe -ssh host1 -m C:\path\to\commands.txt


You can download plink.exe from here.



Last step would be to create a shortcut including plink.exe with the desired parameters.



Check out the Plink documentation for other various parameters:
Plink.exe documentation



To automate a command execution, use Plink (from PuTTY package), not PuTTY itself.



Plink accepts a command on its command line:



plink.exe user@host command





If you want to keep using PuTTY, you can use -m switch to specify a command file (Plink supports the -m switch too).



You can use putty configurations to achieve this.



Load putty and configure your session.



Enter the remote command that you'd like to run here:



Putty remote command box



Then, before clicking "Open", go back to the "Session" tab (at the top), and save your configuration.



Now, create a shortcut to putty.exe, adding the -load flag, for example:



%PATH_TO_PUTTY%\putty.exe -load my_config


Now, you can just click on the shortcut and it will load your session, executing your command.



Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable