Hi,
I have been working on a script, part of which will use plink (command line version of putty, used for making ssh connections)
to connect to a remote server run a command and return the result to a text area within the HTA.
This works fine if i have connected to the server before, but if i havent it will hang because it is not getting a response to the y/n question of storing the host keys.
To get around this i thought i could open a cmd prompt and run plink from there, thus giving me sort of an interactive session, so that if they key was known, the user would not be prompted, but if the host key was not know, the dos box would show the message about accepting the host key, and once you type yes or no the command that you passed to plink via the command line is executed.
(at first i thought i would use putty, but it does not allow you to pass a comaand as a commandline variable like plink does)
The issue i have is that when the script runs plink, the dos box pops up but then it hangs there, and my textarea is populated with
<code>
C:\Documents and Settings\%USERNAME%\Desktop\test\VB work\VBS work\VBS text>
</code>
Which is just the local path of my HTA.
The command works fine when i use it manually with the command line.
Can anyone see whats going wrong?
<code>
Sub Plink
tilltext.Value = “Checking Connection Status…”
Refresh
connect = “0”
Call TillPing(strdata2)
If connect = “1” then
tilltext.Value = “Running Command”
Set objShell1 = CreateObject(“WScript.Shell”)
Set objWshScriptExec1 = objShell1.exec(“cmd /K ” & Chr(34) & “C:\Program Files\Putty\plink” & Chr(34) & ” -ssh” & strdata2 & ” -l MYUSER -pw MYPASS ” & strplinkcmd)
Set objStdOut1 = objWshScriptExec1.StdOut
strOutput1 = objStdOut1.ReadAll
TillText.value = strOutput1
Refresh
Else
End If
End Sub
</code>
strdata2 = a variable that hold machine name
strplinkcmd = a linux command
Thanks in advance
and i made a remote-commands-script file to test.
the batchfile (test.bat) content:
c:\putty\plink -l USER -pw PASS -m c:\putty\nixscrip -ssh shell.isp.net
exit
“nixscrip” just drops a breadcrumb (tracer) to let me know it was there. nixscrip content:
echo testing>fil.fil
exit
then instead of using the .exec, i used “.run”:
set wsh=createobject(“wscript.shell”)
wsh.run(“\putty\test.bat”),1
still working on getting that damn dosbox to close though. so far it just sits there when done. why in hell MS did not build window autoclose when “exit” from batchfile?
thanks for posting your code, it motivated me to start playing with putty and plink, and i learned a lot from your code.
Hth.
update: cmd /c fixed the dosbox issue:
wsh.run (“cmd /c \putty\test.bat”)