#include #include ; ip, port, user, pass, cmdstring, what to search for, field# to return $data = getdata("192.168.99.99", "22", "user", "password", "df -h | grep /Data", "%", 3) ; ip, port, user, pass, cmdstring, what to search for, field# to return Func getdata($ip, $port, $user, $pass, $cmdstring, $search, $field) $socket = _SSHConnect($ip, $port, $user, $pass) ; connect to linux $ret = _SSHSend($socket, $cmdstring & @lf) ; send command $safety = 0 While 1 $recv = _SSHRecv($socket) if $recv = "" then sleep(10) ; slows cycles from 57,000 to 22. ; seems a more logical and stable concept Else $line = StringSplit($recv, @CRLF) ; slowing the insanity we get multiple lines per chunk for $i=1 to $line[0] if StringInStr($line[$i], $search) Then $line = StringStripWS($line[$i], 4) $line = StringSplit($line, " ") $data = $line[$field] ; finally what I want $data = StringReplace($data,"G","") ; just dumps the G from the field ExitLoop 2 ; drop to last 2 lines EndIf next EndIf $safety = $safety +1 if $safety > 500 then ; roughly 5 seconds, crude but effective ConsoleWrite("Error" & @CRLF) ; that SHTF moment we all love $data = "error" ExitLoop EndIf WEnd ; the pid gets treated as a socket somehow ProcessClose($socket) ; plink keeps running otherwise Return $data EndFunc Func _SSHConnect($_IPAddr, $_port = "22", $_login = "", $_passwd = "") $_cmd = @ScriptDir & "\plink.exe -t -no-antispoof " & $_login & "@" & $_IPAddr & " -pw " & $_passwd ;ConsoleWrite($_cmd & @CRLF) $_path = @ScriptDir $_socket = Run($_cmd, $_path, "", $STDIN_CHILD + $STDERR_MERGED) Return $_socket EndFunc Func _SSHSend($_socket, $_data) Return StdinWrite($_socket, $_data) EndFunc Func _SSHRecv($_socket, $_maxlen = 1, $_flag = 0) $StdoutRead = StdoutRead($_socket) Return $StdoutRead ;StdoutRead($_socket) EndFunc