Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - paaing variables from script to plink cmd

Reply
 
Old 10-06-2008   #1 (permalink)
samash40


 
 

paaing variables from script to plink cmd

Hi

I've been working on a script that takes information from a HTA screen
and then uses them as variables to run a plink command. The user input
would be device to connect too, password and command to run once
connected and then output a file with the results of the chosen
command. The plink command format is cmd /c -n|plink
administrator@xxxxxx name -pw password command to run. I am able to
get the required variables but unable to figure out how to pass it too
plink. I have tried having it call a bat file called plink.bat with
the variables on the call e.g plink.bat var1 var2 var3 , the batfile
consists of the command above as cmd /c -n|plink administrator@%1 -pw
%2 %3. Anyone have suggestions? i tried searching thru this group and
checked the putty website for hints but i must be missing something.

Thanks

My System SpecsSystem Spec
Old 10-07-2008   #2 (permalink)
Tom Lavedas


 
 

Re: paaing variables from script to plink cmd

On Oct 6, 9:05*pm, samas...@xxxxxx wrote:
Quote:

> Hi
>
> I've been working on a script that takes information from a HTA screen
> and then uses them as variables to run a plink command. The user input
> would be device to connect too, password and command to run once
> connected and then output a file with the results of the chosen
> command. The plink command format is cmd /c -n|plink
> administrator@xxxxxx name -pw password command to run. I am able to
> get the required variables but unable to figure out how to pass it too
> plink. I have tried having it call a bat file called plink.bat with
> the variables on the call e.g plink.bat var1 var2 var3 , the batfile
> consists of the command above as cmd /c -n|plink administrator@%1 -pw
> %2 %3. Anyone have suggestions? i tried searching thru this group and
> checked the putty website for hints but i must be missing something.
>
> Thanks
I don't know 'plink', but the command line you indicate ...

cmd /c -n|plink administrator@xxxxxx name -pw password command to run

is suspect. It seems to start with a command line switch of -n for
the CMD.exe processor in the place where a command string should be.
This is then piped into the plink application, which makes no sense to
me. Can you explain its intended purpose? My guess is that it is out
of place and the line should read something like ...

cmd /c plink administrator@xxxxxx -n name -pw password command to run

Oh, wait, I see it now - you want to pipe the "-n" string into the
command. If that's right, then you need to add an ECHO, as in ...

cmd /c echo -n|plink administrator@xxxxxx name -pw password command
to run

If you can get the line correctly concatenated from the variables with
the proper spaces, that should solve your problem.

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/
My System SpecsSystem Spec
Old 10-07-2008   #3 (permalink)
samash40


 
 

Re: paaing variables from script to plink cmd

Tom

Thanks for the info, actually i had something close to what you wrote,
i was trying to recal from memory the exact wording of the plink
command and i guessed wrong. I actually had to rewrite the script due
to user's needing to be prompted for the server's security key if they
had never connected to the box before. This is what i have now but i
am still not getting it. I've only been doing this for about a month
and still learning.

<html>
<head>
<title>.::HP Enclosure Scan Tool::.</title>

<HTA:APPLICATION
ID="HP Enclosure Scan Tool"
APPLICATIONNAME="HP Enclosure Scan Tool"
SCROLL="No"
SINGLEINSTANCE="yes"
WINDOWSTATE="maximize"

</head>

<SCRIPT Language="VBScript">

Sub Window_Onload
self.Focus()
self.ResizeTo 700,500
self.MoveTo 200,100
End sub

srvOA = ""
srvUser = "administrator"
srvpwd = ""


Sub RunScript
oas=DropDown1.Value
End Sub

Sub plinkcmd( srvOA )
Auth = "True"
plinkcmd = plink & " -ssh -batch " _
& srvOA & " -l " _
& srvUser & " -pw " _
& srvpwd & " -P " _
& " oas "

on error goto 0
Set objCmd = WshShell.Exec( "%COMSPEC% /c " & plinkcmd )

Do While objCmd.Status = 0
objValidation = objCmd.stdErr.ReadAll
wscript.sleep 100
Loop

if Instr( objValidation , "Access denied" ) > 0 Then
WshShell.Popup "Access Denied on " & Computer, 5, "Error"
Auth = "invalid credentials"
PromptUser()
Elseif Instr( objValidation , "Unable to open connection" ) > 0
Then
WshShell.Popup "Unable to open connection on " & srvOA,5 ,
"Error"

Elseif Instr( objValidation, "key fingerprint" ) > 0 Then
Answer = WshShell.Popup ( srvOA & " key not present in
registry" & vbcrlf _
& "Do you want to open a interactive putty
session ?" & vbcrlf _
& "Notice: it's only necessary to answer yes
when" & vbcrlf _
& "prompted by plink and then press Ctrl-C to
exit plink and continue", , "Error", vbOkCancel + vbQuestion )
if Answer = vbok Then
WshShell.Run( LocalDir & "plink " & srvOA ),1,true
Auth = "False"
Else
WshShell.Run( "cmd /c echo " & srvOA & " key not present;
%date%;%time%>> " & chr(34) & NoServerKey & chr(34) ),0,true
Auth = "True"
End if
Else
wscript.echo "Logged on " & srvOA
End if
End Sub

</SCRIPT>

<style>
body
{
background-color: buttonface;
font-family: Helvetica;
font-size: 12pt;
margin-top: 2px;
margin-left: 8px;
margin-right: 3px;
margin-bottom: 3px;
}
</style>

<body STYLE="
filterrogidXImageTransform.Microsoft.Gradient
(GradientType=1, StartColorStr='#CCCCCC', EndColorStr='#FFFFFF')">
<H2 align="center">HP Enclosure Scan Tool</H2>
<table border="0" cellpadding="0" cellspacing="0" style="width: 565px;
height: 104px">
<tr>
<td valign="top" style="height: 30px">
Input Enclosure:</td>
<td valign="top" style="height: 30px">
Admin Password:</td>
<td valign="top" style="height: 30px">
Select Command to Run:</td>
</tr>
<tr>
<td valign="top" style="width: 284px; height: 15px;">
<input type="text" id="srvOA" name="srvOA" value="" size="15" />&nbsp;
</td>

<td valign="top" style="width: 284px; height: 15px;">
<input type="text" id="srvpwd" name="srvpwd" value="" size="15" /
Quote:

>&nbsp;
</td>

<td valign="top" style="width: 289px">
<select size="1" name="DropDown1" onChange="RunScript">
<option value="0"></option>
<option value="show rack name"> "show rack name" </option>
<option value="show enclosure info"> "show enclosure info" </option>
<option value="show oa status"> "show oa status" </option>
<option value="show power"> "show power" </option>
<option value="show interconnect port map all"> "show interconnect
port map all" </option>
<option value="show server info all"> "show server info all" </option>
<option value="show enclosure temp"> "show enclosure temp" </option>
<option value="show server temp all"> "show server temp all" </option>
</select></td>
<td valign="top" style="width: 284px">
</tr>
</table>
<input id=runbutton class="button" type="button" value="Run Button"
name="run_button" onClick="plinkcmd">
</body>
</html>



My System SpecsSystem Spec
Old 11-08-2008   #4 (permalink)
Sadanand Karve


 
 

Re: paaing variables from script to plink cmd

Hi all,

If you are refering to plink from putty, then the following might be useful
to you.

I first did an interactive login to the server using Putty. This I think
stores the private keys on my system

cd \Prog*
cd putty
plink -ssh -l <myusername> -pw <mypassword> <myhost> ./myshellscript&
exit

The following command also works from dos prompt

set myuser=<myusername>
set mypass=<mypassword>
cmd /c "plink -ssh -l %myuser% -pw %mypass% <myhost> <mylinuxshellcmd>"

I use the folloing the link to look up the putty/plink related
documentation. Might be useful to you.

http://the.earth.li/~sgtatham/putty/0.58/htmldoc/

thanks.
Sadanand




-
Sadanand


"samash40@xxxxxx" wrote:
Quote:

> Tom
>
> Thanks for the info, actually i had something close to what you wrote,
> i was trying to recal from memory the exact wording of the plink
> command and i guessed wrong. I actually had to rewrite the script due
> to user's needing to be prompted for the server's security key if they
> had never connected to the box before. This is what i have now but i
> am still not getting it. I've only been doing this for about a month
> and still learning.
>
> <html>
> <head>
> <title>.::HP Enclosure Scan Tool::.</title>
>
> <HTA:APPLICATION
> ID="HP Enclosure Scan Tool"
> APPLICATIONNAME="HP Enclosure Scan Tool"
> SCROLL="No"
> SINGLEINSTANCE="yes"
> WINDOWSTATE="maximize"
>
> </head>
>
> <SCRIPT Language="VBScript">
>
> Sub Window_Onload
> self.Focus()
> self.ResizeTo 700,500
> self.MoveTo 200,100
> End sub
>
> srvOA = ""
> srvUser = "administrator"
> srvpwd = ""
>
>
> Sub RunScript
> oas=DropDown1.Value
> End Sub
>
> Sub plinkcmd( srvOA )
> Auth = "True"
> plinkcmd = plink & " -ssh -batch " _
> & srvOA & " -l " _
> & srvUser & " -pw " _
> & srvpwd & " -P " _
> & " oas "
>
> on error goto 0
> Set objCmd = WshShell.Exec( "%COMSPEC% /c " & plinkcmd )
>
> Do While objCmd.Status = 0
> objValidation = objCmd.stdErr.ReadAll
> wscript.sleep 100
> Loop
>
> if Instr( objValidation , "Access denied" ) > 0 Then
> WshShell.Popup "Access Denied on " & Computer, 5, "Error"
> Auth = "invalid credentials"
> PromptUser()
> Elseif Instr( objValidation , "Unable to open connection" ) > 0
> Then
> WshShell.Popup "Unable to open connection on " & srvOA,5 ,
> "Error"
>
> Elseif Instr( objValidation, "key fingerprint" ) > 0 Then
> Answer = WshShell.Popup ( srvOA & " key not present in
> registry" & vbcrlf _
> & "Do you want to open a interactive putty
> session ?" & vbcrlf _
> & "Notice: it's only necessary to answer yes
> when" & vbcrlf _
> & "prompted by plink and then press Ctrl-C to
> exit plink and continue", , "Error", vbOkCancel + vbQuestion )
> if Answer = vbok Then
> WshShell.Run( LocalDir & "plink " & srvOA ),1,true
> Auth = "False"
> Else
> WshShell.Run( "cmd /c echo " & srvOA & " key not present;
> %date%;%time%>> " & chr(34) & NoServerKey & chr(34) ),0,true
> Auth = "True"
> End if
> Else
> wscript.echo "Logged on " & srvOA
> End if
> End Sub
>
> </SCRIPT>
>
> <style>
> body
> {
> background-color: buttonface;
> font-family: Helvetica;
> font-size: 12pt;
> margin-top: 2px;
> margin-left: 8px;
> margin-right: 3px;
> margin-bottom: 3px;
> }
> </style>
>
> <body STYLE="
> filterrogidXImageTransform.Microsoft.Gradient
> (GradientType=1, StartColorStr='#CCCCCC', EndColorStr='#FFFFFF')">
> <H2 align="center">HP Enclosure Scan Tool</H2>
> <table border="0" cellpadding="0" cellspacing="0" style="width: 565px;
> height: 104px">
> <tr>
> <td valign="top" style="height: 30px">
> Input Enclosure:</td>
> <td valign="top" style="height: 30px">
> Admin Password:</td>
> <td valign="top" style="height: 30px">
> Select Command to Run:</td>
> </tr>
> <tr>
> <td valign="top" style="width: 284px; height: 15px;">
> <input type="text" id="srvOA" name="srvOA" value="" size="15" />
> </td>
>
> <td valign="top" style="width: 284px; height: 15px;">
> <input type="text" id="srvpwd" name="srvpwd" value="" size="15" /
Quote:

> >
> </td>
>
> <td valign="top" style="width: 289px">
> <select size="1" name="DropDown1" onChange="RunScript">
> <option value="0"></option>
> <option value="show rack name"> "show rack name" </option>
> <option value="show enclosure info"> "show enclosure info" </option>
> <option value="show oa status"> "show oa status" </option>
> <option value="show power"> "show power" </option>
> <option value="show interconnect port map all"> "show interconnect
> port map all" </option>
> <option value="show server info all"> "show server info all" </option>
> <option value="show enclosure temp"> "show enclosure temp" </option>
> <option value="show server temp all"> "show server temp all" </option>
> </select></td>
> <td valign="top" style="width: 284px">
> </tr>
> </table>
> <input id=runbutton class="button" type="button" value="Run Button"
> name="run_button" onClick="plinkcmd">
> </body>
> </html>
>
>
>
>
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Retaining variables after script execution PowerShell
Include another script, keep variables in included script? PowerShell
Need help with PHP Script variables Network & Sharing
Pop-up to enter variables to pass to script PowerShell
Passing variables to script PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46