我的需求是自動化遠程網路設備,我的vbs內容如下
Dim pm, folder, file, timestamp, network, hostname
Set shell = CreateObject("WScript.Shell")
Set pm = WScript.CreateObject("WScript.Shell")
Set network = CreateObject("WScript.Network")
hostname = network.ComputerName
timestamp = Year(Now) & Right("0" & Month(Now), 2) & Right("0" & Day(Now), 2)
file = "C:\Users\frank\Downloads" & timestamp & "-" & hostname & ".log"
Set folder = CreateObject("Scripting.FileSystemObject")
Set file = folder.CreateTextFile(file, True)
shell.Run "putty -ssh admin@192.168.123.168 -P 22"
WScript.Sleep 500
pm.SendKeys "admin"
pm.SendKeys "{ENTER}"
pm.SendKeys "enable"
pm.SendKeys "{ENTER}"
pm.SendKeys "cisco"
pm.SendKeys "{ENTER}"
pm.SendKeys "terminal length 0"
pm.SendKeys "{ENTER}"
pm.SendKeys "show version"
pm.SendKeys "{ENTER}"
pm.SendKeys "terminal length 24"
pm.SendKeys "{ENTER}"
pm.SendKeys "copy running-config startup-config"
pm.SendKeys "{ENTER}"
pm.SendKeys "{ENTER}"
執行結果如下
我需求是
1.生成檔名必須是網路設備hostname,例如20250107-WAN-R1.log,而不是20250107-WIN11.log這種微軟主機的hostname。
2.我的腳本雖然在putty執行成功,可是無法輸出到目標檔案.log,打開竟然是空的。
以上請教大神,小弟應如何修改...