egas Posted August 10, 2015 Share Posted August 10, 2015 Good day everyone,I am having some difficulty sending keystrokes to plink.What I am trying to do is automate an SSH task to a Cisco device.While I am not a scripting guru, I have some experience with writing scripts, however none with AutoIt.$PPID = Run(@comspec & " /c" & "C:\Tools\Putty\plink.exe -ssh 10.10.10.10","",@SW_MAXIMIZE,7) StdinWrite($PPID, "admin") Sleep(5000) ExitAbove is my exact code with the exception of the IP address. The plink window lauches, but it does not send the keystrokes. What am I missing?Any feedback will be greatly appreciated. Thank you. Link to comment Share on other sites More sharing options...
spudw2k Posted August 10, 2015 Share Posted August 10, 2015 It might be a timing issue. Try putting in a delay before the StdInWrite command.The way I did this (many years ago), is I put in a StdOutRead loop until I received successful login indication.I always recommend responding based on feedback rather than a timed execution. Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX BuilderMisc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retreive SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose ArrayProjects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalcCool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
iamtheky Posted August 10, 2015 Share Posted August 10, 2015 (edited) I use plink like this to perform a grep:$Connection = "plink.exe -ssh COMPUTERNAME -l USERNAME -pw PASSWORD" $log_dir = @ScriptDir & "\" & @MON & @MDAY & @YEAR & "\" $log = ">" & $log_dir & "\REMOTE_LOGIN.log" $Command1 = "grep -i -P '(extraweb__authen HTTP)' /var/log/daily.log" runwait('cmd /c ' & $Connection & ' ' & $Command1 & $log) Edited August 10, 2015 by boththose ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
egas Posted August 10, 2015 Author Share Posted August 10, 2015 It might be a timing issue. Try putting in a delay before the StdInWrite command.The way I did this (many years ago), is I put in a StdOutRead loop until I received successful login indication.I always recommend responding based on feedback rather than a timed execution.@spudw2k, thanks for the feedback.The loop to wait for feedback makes sense, but it doesn't that long to connect.$PPID = Run("C:\Tools\Putty\plink.exe -ssh 172.19.190.2", "", @SW_SHOWDEFAULT) Sleep(10000) StdinWrite($PPID, "admin") ProcessClose($PPID) ExitI read where @comspec is only needed to run internal commands like dir, so I switched to the the standard run function. I am able to get the command window, but it still isn't sending the keystrokes for admin.Any other ideas? Link to comment Share on other sites More sharing options...
egas Posted August 10, 2015 Author Share Posted August 10, 2015 Hey @boththose, thanks for the feedback.Unfortunately, the cisco box I'm trying to connect to does not work with the username and password switches.So what I concluded that I need to do is figure out a way to send keystrokes to plink and simulate the session. Link to comment Share on other sites More sharing options...
iamtheky Posted August 10, 2015 Share Posted August 10, 2015 (edited) sux, ive only accomplished that via a putty session called from plink.as described here in 7.2.1:http://the.earth.li/~sgtatham/putty/0.60/htmldoc/Chapter7.html Edited August 10, 2015 by boththose found a link ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
gruntydatsun Posted August 10, 2015 Share Posted August 10, 2015 You could just activate the console window then send key strokes directly to it.WinActivate("Administrator:Command Prompt","<Cisco Controller>") Send("Keystrokesgohere")but stdin is probably not writing to standard io because you haven't included $STDIN_CHILD in the run statement like this: $PPID = Run("C:\Tools\Putty\plink.exe -ssh 172.19.190.2", "", @SW_SHOWDEFAULT,$STDIN_CHILD) Link to comment Share on other sites More sharing options...
egas Posted August 11, 2015 Author Share Posted August 11, 2015 Hey @gruntydatsun, thanks for the feedback.I didn't include the $STDIN_CHILD, but reason was because the script was not running. However, I learnt that I needed to do this:#include <Constants.au3>Then I started seeing some progress! But it was short lived because as it would hang at the password prompt.#include <Constants.au3> ;$PPID = Run(@comspec & " /c" & "C:\Tools\Putty\plink.exe -ssh 172.19.190.2","",@SW_SHOWDEFAULT,7) $PPID = Run("C:\Scripts\plink.exe -ssh wlcontrol", "", @SW_SHOWDEFAULT, $STDIN_CHILD) Sleep(10000) StdinWrite($PPID, "first_prompt" & @CRLF) Sleep(5000) StdinWrite($PPID, "second_prompt"& @CRLF) Sleep(15000) StdinWrite($PPID, "password"& @CRLF) Sleep(30000) StdinWrite($PPID, "ping 172.16.1.169"& @CRLF) Sleep(1000) StdinWrite($PPID, "logout "& @CRLF) Sleep(5000) ProcessClose($PPID) ExitThis is the output. Link to comment Share on other sites More sharing options...
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