strCommand11 = "echo y | " & cstrSftp1 & " -ssh -pw " & " adhdh " & "root1@" & pHost & " /var/tmp/script "
How to suppress prompt when running Linux script from Windows?
Вопрос
I wrote the following VBScript in order to run the Linux script from windows by using the plink.exe
tool.
user - root1 , password - adhdh
my VB script:
Const Host = "110.18.3.32"
Set Sh = CreateObject("WScript.Shell")
Const cstrSftp1="""C:\Documents and Settings\Administrator\Desktop\plink.exe"""
strCommand11 = cstrSftp1 & " -ssh -pw " & " adhdh " & "root1@" & Host & " /var/tmp/script "
Sh.Run "cmd /k " & strCommand11, 1, True
Set Sh = Nothing
But there is little problem
When I run this script on the first time I get the following prompt from plink
:
Store key in cache? (y/n)
So in order to solved this issue by adding echo y
I change the line in the script as follows:
strCommand11 = echo y | cstrSftp1 & " -ssh -pw " & " adhdh " & "root1@" & Host & " /var/tmp/script "
but after I run the new script it fails with this error:
expected end of statement
I also tried
"echo y | cstrSftp1 "
But still I get other error.
Please advice what I need to change in my script?
Решение
Другие советы
Using echo y | plink.exe ...
is a rather clumsy way to solve this issue. It's better to import the remote server's public host key (e.g. /etc/ssh/ssh_host_rsa_key.pub
) into the registry to prevent the prompt from appearing in the first place. There's a Python script for converting the public key from the format used on Linux hosts to the format PuTTY uses in the Windows registry. You can write the converted value to the registry like this:
Const Host = "110.18.3.32"
Set sh = CreateObject("WScript.Shell")
sh.RegWrite "HKCU\Software\SimonTatham\PuTTY\SshHostKeys\rsa2@22:" & Host _
, "0x10001,0x9b95f6ac6cf5...", "REG_SZ"
'rest of your code here