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