Jump to content

Using AutoIt to control putty


LGC
 Share

Recommended Posts

putty is a telnet client, although I'm sure most of you know that.

You input the ip address of the computer your sending the commands to, and putty opens a window that is named " 'ip address' - putty "

That would be fine if I was using the script for one ip address but i am not.

I was thinking that autoit can ask me for the ip address then use the ip address I input to launch putty and also use the ip address as a variable to control the window, but I can't figure out how to do that.

here are some screen caps from putty so that you can get a better idea:

Posted Image

Posted Image

Posted Image

Only problem is, I don't know how to do that. lol.

Any help would be appreciated.

Link to comment
Share on other sites

  • 5 weeks later...

One way to do it is log onto the system and allow putty to accept the key. Afterwards the authentication box will no longer appear. I have scripted a few AutoIT scripts because we do a lot of remote administration of Unix systems and use putty on a daily basis with dozens of different servers.

Func do_backup()
    Send("cd dba ; tail `ls -tr *backup* | tail -1` | (grep Finished && ls -ltr *backup*) || (tail -f `ls -tr *backup* | tail -1`){ENTER}")
EndFunc

Func get_idpw()
#region --- GuiBuilder code Start ---
; Script generated by AutoBuilder 0.6 Prototype

    GuiCreate("Enter ID/Password", 197, 110,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))

    $Input_id = GuiCtrlCreateInput("Input1", 80, 20, 110, 20)
    $Label_2 = GuiCtrlCreateLabel("ID", 10, 20, 40, 20)
    $Label_3 = GuiCtrlCreateLabel("Password", 10, 50, 60, 20)
    $Input_pw = GuiCtrlCreateInput("Input4", 80, 50, 110, 20)
    $Button_5 = GuiCtrlCreateButton("OK", 50, 80, 60, 20)

    GuiSetState()
    While 1
        $msg = GuiGetMsg()
        Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        case $msg = $Button_5
            ExitLoop
        Case Else
            ;;;
        EndSelect
    WEnd

    $id = GUICtrlRead($Input_id)
    $pw = GUICtrlRead($Input_pw)
    
    GUIDelete()

#endregion --- GuiBuilder generated code End ---

EndFunc

Func send_idpw()
    Send( $id & "{ENTER}" )
    Sleep (3000)
    Send( $pw & "{ENTER}" )
    Sleep (3000)
EndFunc

Of course this only works when the putty window is active, next step is to incorporate plink into AutoIT.

Edited by cpuobsessed
Link to comment
Share on other sites

  • 5 years later...

my sample, not read window..... conect on

$user = "root"
$password =""
$host ="5.0.0.1"
$port ="22"

$puty_exe = @ScriptDir & "\putty.exe"; putty salve local folder script

; putty -ssh -l usuario 5.0.0.1 p "port" -pw senha

;input

$command = RunWait(@comspec & " /C "&$puty_exe&" -ssh -l "&$user&" "&$host&" p "&$port&" -pw "&$password,@ScriptDir, @SW_HIDE, 1)
;$command = RunWait(@comspec & " /C "&$puty_exe&" system scripts run mario",@ScriptDir, @SW_HIDE, 1)
While 1
$data = StdoutRead($command)
ConsoleWrite($data&@CRLF)
If @error Then ExitLoop
Wend

:bike: 

Att...Cleber Antônio Made in Bio zonte Minas Gerais  :sweating:

Link to comment
Share on other sites

  • 11 months later...
  • Moderators

tito,

We ask peopel not to necro-post for two main reasons:

- 1. The language advances and the functionality might well be included in core or UDF code by now.

- 2. The changes in language syntax mean that it is likely that code from more than a couple of years ago may well not run under the current release interpreter without significant modification.

Clear enough? :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • 4 years later...
  • 11 months later...

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...