Jump to content

Can't get plink/putty script to work. StdoutRead misconfusion/Help.


CrewXp
 Share

Recommended Posts

Hey, I've searched around the forums for help, but I just can't seem to get it to work.

I'm trying to ssh to my server, login, and then have it send some commands...

However, It doesn't seem to return the result of the command I send

If you look at the code, It detects the text it's supopsed to, then it's supposed to send 'n' for no. When it gets to command prompt (after Sleep 1000), I send ls (to list directories). However, I never get a second message box giving me the output.

I use plink, putty in command line form.

#include <Constants.au3>
$hostname="mysite.com"
Dim $szIPADDRESS = TCPNameToIP($hostname)

$PID = Run(@comspec & " /c C:\Users\CrewXp\Downloads\plink.exe " &$hostname& " -pw mypass -l crewxp -ssh ","",@SW_MAXIMIZE,$STDIN_CHILD + $STDOUT_CHILD + $STDERR_CHILD)
DIM $sSTDOUT = "", $sSTDERR = ""
Do
    Sleep(2000)
$OUT = StderrRead($PID)
Msgbox(0,"",$OUT)
If Stringinstr($OUT,"The server's host key") Then
    StdinWrite($PID,"n")
    Sleep(2000)
    StdinWrite($PID,"ls")
EndIf
    
Until Not ProcessExists($PID)
Edited by CrewXp
Link to comment
Share on other sites

  • 3 weeks later...

Hey, I've searched around the forums for help, but I just can't seem to get it to work.

I'm trying to ssh to my server, login, and then have it send some commands...

However, It doesn't seem to return the result of the command I send

If you look at the code, It detects the text it's supopsed to, then it's supposed to send 'n' for no. When it gets to command prompt (after Sleep 1000), I send ls (to list directories). However, I never get a second message box giving me the output.

I use plink, putty in command line form.

#include <Constants.au3>
$hostname="mysite.com"
Dim $szIPADDRESS = TCPNameToIP($hostname)

$PID = Run(@comspec & " /c C:\Users\CrewXp\Downloads\plink.exe " &$hostname& " -pw mypass -l crewxp -ssh ","",@SW_MAXIMIZE,$STDIN_CHILD + $STDOUT_CHILD + $STDERR_CHILD)
DIM $sSTDOUT = "", $sSTDERR = ""
Do
    Sleep(2000)
$OUT = StderrRead($PID)
Msgbox(0,"",$OUT)
If Stringinstr($OUT,"The server's host key") Then
    StdinWrite($PID,"n")
    Sleep(2000)
    StdinWrite($PID,"ls")
EndIf
    
Until Not ProcessExists($PID)
Edited by cpuobsessed
Link to comment
Share on other sites

  • 10 months later...

Here's what i did, though it doesn't work completely yet and it MUST be compiled as a console application:

#include <Constants.au3>
HotKeySet('`',"_read"); hit this button to read your input after hitting enter(tilde button)

$user = "";username
$pass = "";password
$host = "";host

$plink = Run("plink.exe -P 22 -l "&$user&" -pw "&$pass&" -ssh "&$host,@ScriptDir, @SW_HIDE, $STDIN_CHILD + $STDERR_CHILD + $STDOUT_CHILD)
$read = False
while 1
    $msg = StdoutRead($plink)
    if @error then ExitLoop
    if $msg <> "" Then
        ConsoleWrite($msg)
    EndIf
    if $read Then
        StdinWrite($plink,ConsoleRead())
        $read=False
    EndIf
    sleep(25)
WEnd 
StdioClose($plink)

func _read()
    $read = True
EndFunc
Edited by Descention
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...