1
我不是程序員,所以我不想過分激怒本論壇中的好人。我的問題是,我想使用VBScript Telnet到Linux設備上,發出一個DF命令,並將所有響應輸出到日誌文件,我可以稍後解析。我最初發現了一種成功實現Telnet的方法,但是我一直在試驗文本文件輸出要求沒有成功。下面的代碼當然不起作用,但我想知道我是否接近正確的方法?如何使用VBScript將命令提示符輸出到日誌文件
Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec("cmd /c dir")
WshShell.run"cmd" '*** open command window ***
WScript.Sleep 250
WshShell.SendKeys("{Enter}")
WshShell.SendKeys"telnet 10.13.2.2"
WshShell.SendKeys("{Enter}")
WScript.Sleep 2000
WshShell.SendKeys"root"
WshShell.SendKeys("{Enter}")
WScript.Sleep 1500
WshShell.SendKeys"password"
WshShell.SendKeys("{Enter}")
WScript.Sleep 1500
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objLogFile = objFSO.OpenTextFile("C:\VBSmemSize.txt", 2, True)
WshShell.SendKeys"df /mnt/cf"
WshShell.SendKeys("{Enter}")
Do
strFromProc = oExec.Stdout.Readline()
WScript.Echo strFromProc
Loop While Not objLogFile.StdOut.atEndOfStream
你可能比'telnet'使用'ssh'成功分批。如果你還沒有設置這個,我警告你這不是微不足道的,但完全值得。 –