Jump to content
Sign in to follow this  
charlieb

SSH using Plink / Putty

Recommended Posts

charlieb

I have a CMD batch file that contains the following.

putty -i key.ppk -R 12345:localhost:22 user@mycompany.com -pw testing123

GOAL:  I'd like AutoIt script to run the same exact command above, but ASK for a number, and whatever  number is inputted in the response to automatically REPLACE the 12345 number above with the entered number by the user and run the command.  So when a user enters for example, 9876, then the scripts run the command below...

putty -i key.ppk -R 9876:localhost:22 user@mycompany.com -pw testing123

Thank you for any assistance.

Share this post


Link to post
Share on other sites
badcoder123

I have no idea on how to use any of that but I think this is what you're looking for?

$input = InputBox("Key", "Enter the numeric key.")
Run(@ComSpec & " /c " & 'putty -i key.ppk -R ' & $input & ':localhost:22 user@mycompany.com -pw testing123', "", @SW_SHOW) ;Change flag to @SW_HIDE

 

  • Like 1

Share this post


Link to post
Share on other sites
charlieb

thx badcoder123 it works when I run the script, but I should of corrected my own CMD script.  

It is actually .\putty -i .\key.ppk -R 9876:localhost:22 user@mycompany.com -pw testing123  as you can see I have .\ prepending the command putty and key.ppk because I create an EXE that run my cmd script file with that content along with putty and the key.ppk file - all 3 files together in an EXE created by IEXPRESS.  IEXPRESS just happends to extract those 3 files together to a temporary directory and executes the batch file and calls those other 2 files; hence .\ prepend.  If I combine replace the cmd with your EXE based script, it doesn't execute.  I did this and it didn't work.  How do I ensure that when EXE that extracts this 3 files in temp dir that it calls them or refers to them.  Thank you.

$input = InputBox("Key", "Enter the numeric key.") Run(@ComSpec & " /c " & '.\putty -i .\key.ppk -R ' & $input & ':localhost:22 user@mycompany.com -pw testing123', "", @SW_SHOW) ;Change flag to @SW_HIDE

Share this post


Link to post
Share on other sites
Earthshine
Posted (edited)

you will probably want to change to that temp directory then beforehand, else provide full path names. i would find the temp and make it the working dir.

https://www.autoitscript.com/autoit3/docs/functions/FileChangeDir.htm

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
charlieb

Ok, it works now.  Thanks  all.

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×