Friday, February 6, 2009

Automate tedious tasks using Autoit

One of my collegues was looking for a script that would let him automate his daily ritual of opening up 4-5 putty sessions to his linux host. I had used autoit before and suggested it to him. I hadn't used it in a while and was curious as to how it worked. After downloading it took me all of 45 minutes to come up with the following script. It asks for your password, then uses it to log on to 5 different putty sessions!!
---------------------------------------------------
; this script logs you on to 5 different putty sessions

$answer =  InputBox ("enter password", "please enter your password","","*",150,80)

If $answer = "" Then
MsgBox(0, "AutoIt Example", "Enter valid password")
Exit
EndIf

Opt("WinTitleMatchMode", 2)

For $count = 1 To 5
Run("C:\Program Files\PuTTY\putty.exe -ssh username@hostname")
WinWaitActive("PuTTY")
Sleep(1500) 
;MsgBox(0,"Sending password" ,$answer)
Send($answer)
Send("{ENTER}")
Next
--------------------------------------------------------------

No comments:

Post a Comment