0
我找到了适合我需求的脚本。不过,我想加强它。如何处理参数
这是脚本:
strSSH = "C:\Program Files (x86)\PuTTY\putty.exe"
strSSHidentity1 = "C:\id_rsa.ppk"
strSSHidentity2 = "C:\id_dsa.ppk"
Select Case WScript.Arguments.Count
Case 0
WScript.Echo "No hostname provided. Aborting SSH operation."
WScript.Quit
Case Else
Set colArgs = WScript.Arguments
For i = 0 To WScript.Arguments.Count - 1
strHost = " " & WScript.Arguments.Item(i)
Next
End Select
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run """" & strSSH & """ """ & CleanHostname(strHost) & """ """ & "-i" & """ """ & strSSHidentity1 & """ """ & "-i" & """ """ & strSSHidentity1 & """"
WScript.Quit
Function CleanHostname(strHost)
strHost = Trim(strHost)
'Remove protocol if it was passed
If InStr(strHost, "ssh://") = 1 Then
strHost = Right(strHost, Len(strHost) - 6)
End If
'Remove trailing slash if present
If InStrRev(strHost, "/") = Len(strHost) Then
strHost = Left(strHost, Len(strHost) - 1)
End If
'Return cleaned hostname
CleanHostname = strHost
End Function
我用它来启动SSH://超链接。 如何修改它,以便接受用户在命令行中提供的更多参数而不仅仅是主机名? (-p 22
)。对于要求输出
例子:
CMD:
wscript ssh.vbs ssh://[email protected] -p 22 -i my_key.ppk
最终将运行:
"C:\Program Files (x86)\PuTTY\putty.exe" myhost -i C:\id_rsa.ppk -i C:\id_dsa.ppk -p 22 -i my_key.ppk
谢谢!
THX。我对输出更改提出了一些更明确的要求。 – 2015-03-25 13:54:16