TheRauchster101 Posted February 25, 2015 Posted February 25, 2015 Currently I have a working script, but I'd like to add one last tweak to make it perfect so that it's usable while I work on other things. I am trying to monitor and track the error count of a specific cable in our system. Our tracking system only takes a count every 15 minutes, and I need more specific data, so I'm creating a program that will use my remote terminal session with PuTTY to automatically send the command every 5 seconds. expandcollapse popupGlobal $WndHan, $SendCount, $SleepCount, $Paused HotKeySet("{PAUSE}", "TogglePause") HotKeySet("{ESC}", "End") HotKeySet("+!d", "PullInfo") ; Shift-Alt-d Opt("WinTitleMatchMode", 2) $SendCount = 0 $SleepCount = 5 While 1 Sleep (500) ToolTip ("Waiting for Start-up command. Shift+Alt+D" & @LF & "Pause/Break to Pause" & @LF & "Escape to Exit" & @LF & "Created by Adam Rauch", 5, 5) WEnd Func PullInfo() WinWait ("Shawnee, OK - PuTTY", "") ToolTip ("Waiting for Window to Activate" & @LF & "Escape to Exit" & @LF & "Created by Adam Rauch", 5, 5) $WndHan = WinGetHandle("Shawnee, OK - PuTTY", "") If @error Then MsgBox(65552, "", "An error occurred when trying to retrieve the window handle of Notepad.") Exit Else ControlSend ($WndHan,"", "", "show int cable 5/0/14{ENTER}") $SendCount = $SendCount + 1 Tooltip ("Window Handle is " & $WndHan & " - Sending command, Time #" & $SendCount & @LF & "Escape to Exit" & @LF & "Created by Adam Rauch", 5, 5) Call ("SleepCount") EndIf EndFunc Func TogglePause() $Paused = Not $Paused While $Paused Sleep(100) ToolTip("Script is Paused" & @LF & "Pause/Break to Resume" & @LF & "Escape to Exit" & @LF & "Created by Adam Rauch", 5, 5) WEnd ToolTip("") EndFunc Func End() Exit EndFunc Func SleepCount() If $SleepCount > 1 Then ToolTip ("Window Handle is " & $WndHan & " - Waiting " & $SleepCount & " seconds before sending next command." & @LF & "Have currently sent " & $SendCount & " commands." & @LF & "Escape to Exit" & @LF & "Created by Adam Rauch", 5, 5) $SleepCount = $SleepCount - 1 Sleep (1000) Call ("SleepCount") ElseIf $SleepCount = 1 Then ToolTip ("Waiting " & $SleepCount & " seconds before sending next command." & @LF & "Have currently sent " & $SendCount & " commands." & @LF & "Escape to Exit" & @LF & "Created by Adam Rauch", 5, 5) Sleep (1000) $SleepCount = 5 Call ("PullInfo") EndIf EndFunc This code works fine, the problem is not with that. I pull the window handle just fine, and the program attempts to send to the PuTTY window, but I think a feature of PuTTY is that it doesn't send commands without being the active window. Anyone have prior experience with this program and know a workaround?
caramen Posted February 25, 2015 Posted February 25, 2015 I have experience with putty but i guess you have to use memory read to do that .... I have not the skilledge My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki
iamtheky Posted February 25, 2015 Posted February 25, 2015 (edited) I would recommend plink, eliminating the GUI completely. Edited February 25, 2015 by boththose ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
ViciousXUSMC Posted February 25, 2015 Posted February 25, 2015 WinActivate to make the window active Also maybe try ControlSetText Going the way of a cmd driven program sounds like a good solution as well, but then you would need to start over. If I was going to use Putty and the first 2 things did not work I would run it on another computer so that the window is not in the way, keep the window off screen, or run it in a VM and keep the VM minimized.
iamtheky Posted February 25, 2015 Posted February 25, 2015 (edited) Plink does not involve starting over... http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html Plink (a command-line interface to the PuTTY back ends) For your case something similar to: $Connection = "plink.exe -ssh COMPUTERNAME -l USERNAME -pw PASSWORD" $log_dir = @ScriptDir & "\" & @MON & @MDAY & @YEAR & "\" Func _CableTest() $log = ">" & $log_dir & "\CableTestLog.log" $Command1 = "show int cable 5/0/14" runwait('cmd /c ' & $Connection & ' ' & $Command1 & $log) EndFunc ;_CableTest() Edited February 25, 2015 by boththose ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now