Sign in to follow this  
Followers 0
llomll

Need help to send command after logged into Putty

2 posts in this topic

Hi guys,

I am new to this forums so hopefully I am asking this questions in the correct forums.

I found this script from one of the threads that allows to log into SSH session while using Putty In the background. How do I go about typing in a command after I am logged in?

For example, I was to send "ls" command once I am logged in.

Any help and guidance is greatly appreciated.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiIPAddress.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("HTSE Login Screen", 331, 238, 326, 220)
$Group1 = GUICtrlCreateGroup(" SSH Login", 8, 8, 313, 217)
$IP = GUICtrlCreateLabel("IP", 80, 48, 21, 22)
GUICtrlSetFont(-1, 11, 800, 0, "Tahoma")
$IPAddress1 = _GUICtrlIpAddress_Create($Form1, 104, 48, 130, 21)
_GUICtrlIpAddress_Set($IPAddress1, "10.10.10.50")
$User = GUICtrlCreateLabel("User", 64, 96, 39, 22)
GUICtrlSetFont(-1, 11, 800, 0, "Tahoma")
$Username = GUICtrlCreateInput("", 104, 96, 129, 21)
$Password = GUICtrlCreateLabel("Password", 24, 136, 77, 22)
GUICtrlSetFont(-1, 11, 800, 0, "Tahoma")
$Pass = GUICtrlCreateInput("", 104, 136, 129, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_PASSWORD))
$Login = GUICtrlCreateButton("Login", 104, 176, 107, 25)
GUICtrlSetFont(-1, 10, 800, 0, "Tahoma")
$Cancel = GUICtrlCreateButton("Cancel", 232, 176, 75, 25)
GUICtrlSetFont(-1, 10, 800, 0, "Tahoma")
$Label1 = GUICtrlCreateLabel("Port", 240, 48, 36, 22)
GUICtrlSetFont(-1, 11, 800, 0, "Tahoma")
$Input3 = GUICtrlCreateInput("22", 280, 48, 25, 21)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
     Case $GUI_EVENT_CLOSE
         Exit
     Case $Cancel
         Exit
     Case $Login
         $IPAddress1 = _GUICtrlIpAddress_Get($IPAddress1)
         $Username = GUICtrlRead($Username)
         $Pass = GUICtrlRead($Pass)
         ExitLoop
EndSwitch
WEnd
$Command = "putty.exe -ssh -2 -P 22 " & $Username & "@" & $IPAddress1 & " -pw " & $Pass
;MsgBox(32, 'Command to Pass', $Command & @LF & $IPAddress1) ;comment out this line for production
Run($Command)

Share this post


Link to post
Share on other sites



Haven't used it myself but PLINK (a command-line interface to the PuTTY back ends) seems to be what you need.

There is an AutoIt wrapper available for PLINK.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

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  
Followers 0