jp10558 Posted July 6, 2011 Posted July 6, 2011 I'm trying to interact with some programs on a remote linux server via SSH in a script. I have plink, which seems to be the way to do so. I can log in and get a shell with plink at the command line. My issue is I really need to be able to have autoit type in commands, and then parse the output. When I try that with plink, I get as much as "Using username foo" and then I get the handle is invalid. . . it looks like plink is creating a new PID? Is there a better way to do this? I can send commands to a PuTTY window also, but I can't read out the data from there. . .
enaiman Posted July 6, 2011 Posted July 6, 2011 Plink is the way to go. I don't know what have you been using but I certainly remember about a post in Example Scripts, where somebody wrote an UDF for putty/plink. Try that one - it might solve your problem. If you already used that, consider posting some code - otherwise you are asking for generic answers. SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :)
jp10558 Posted July 13, 2011 Author Posted July 13, 2011 I've managed to almost get this working with the plink UDF. My problem is I need to forward a port... I try using Run w/ plink Run("plink " & $username & "@computer -pw " & $password & ' -L 159'& $vnc & ':computer:59'&$vnc,"",@SW_SHOW,0x8) but it seems like plink is immediately exiting for me there. . . not keeping the port open. I'm not really sure what I'm doing wrong...
spudw2k Posted July 13, 2011 Posted July 13, 2011 I use plink for an automated SCP copy script. Here is some snippet functions that may be a good example for you. expandcollapse popupFunc _Connect($host,$usr,$pass) $exec = @ScriptDir & "\PLINK.EXE" If Not FileExists($exec) Then _Err("PLINK.EXE Not Found!",0) ;If $debug Then ;$pid = Run($exec & " -ssh -pw " & $pass & " " & $usr & "@" & $host, @SystemDir, @SW_SHOW, 0x1 + 0x8) ;Run SSH.EXE ;Else $pid = Run($exec & " -ssh -pw " & $pass & " " & $usr & "@" & $host, @SystemDir, "", 0x1 + 0x8) ;Run SSH.EXE ;EndIf If Not $pid Then _Err("Failed to connect",0) $currentpid = $pid $rtn = _Read($pid) ;Check for Login Success - Prompt If StringInstr($rtn,"(y/n)") Then _Send($pid,"y" & @CR) $rtn = _Read($pid) EndIf If StringInstr($rtn,"yes/no") Then _Send($pid,"yes" & @CR) $rtn = _Read($pid) EndIf If StringInstr($rtn,"Access denied") Or StringInstr($rtn,"FATAL")Then _Err($rtn,$pid) Return $pid EndFunc Func _Read($pid) If Not $pid Then Return -1 Local $dataA Local $dataB Do $dataB = $dataA sleep(100) $dataA &= StdOutRead($pid) If @error Then ExitLoop Until $dataB = $dataA And $dataA And $dataB ;If $debug Then FileWriteLine(@ScriptDir & "\log.txt",$dataA & @CRLF) Return $dataA EndFunc Func _Send($pid,$cmd) StdinWrite($pid,$cmd) EndFunc Func _Err($data,$pid) If $data And $data <> -1 Then MsgBox(0,"An Error has Occured",$data,5) _Exit($pid) EndFunc Func _Exit($pid) ProcessClose($pid) EndFunc 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 Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF
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