【发布时间】:2016-08-29 08:07:48
【问题描述】:
我有很多开关,我们每晚都会备份。我需要创建一个自动备份正在运行的配置的作业。
我目前正在使用这个,但我怎样才能使用服务器 IP 地址列表而不必重复代码。
Option Explicit
On Error Resume Next
Dim WshShell
set WshShell=CreateObject("WScript.Shell")
WshShell.run "cmd.exe"
WScript.Sleep 1000
'Send commands to the window as needed - IP and commands need to be customized
'Step 1 - Telnet to remote IP'
WshShell.SendKeys "telnet 10.1.130.91 23"
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
'Step 2 - Issue Commands with pauses'
WshShell.SendKeys ("password")
WScript.Sleep 1000
WshShell.SendKeys ("{Enter}")
WScript.Sleep 500
WshShell.SendKeys ("Enable")
WshShell.SendKeys ("{Enter}")
WScript.Sleep 500
WshShell.SendKeys ("password")
WshShell.SendKeys ("{Enter}")
WScript.Sleep 500
WshShell.SendKeys ("terminal length 0")
WshShell.SendKeys ("{Enter}")
WScript.Sleep 500
WshShell.SendKeys ("show running-config")
WshShell.SendKeys ("{Enter}")
WScript.Sleep 500
wshShell.SendKeys ("copy run tftp://10.1.211.53/file1.xls")
WshShell.SendKeys ("{Enter}")
WScript.Sleep 500
wshShell.SendKeys ("10.1.211.53")
WshShell.SendKeys ("{Enter}")
WScript.Sleep 500
wshShell.SendKeys ("file1.xls")
WshShell.SendKeys ("{Enter}")
WScript.Sleep 2000
'Step 3 - Exit Command Window
WshShell.SendKeys "exit"
WshShell.SendKeys ("{Enter}")
WScript.Sleep 500
WshShell.SendKeys "exit"
WshShell.SendKeys ("{Enter}")
【问题讨论】:
-
虽然很明显这是某种 Visual Basic 脚本,但如果您使用语言标签和/或环境标签正确地标记问题,它确实有助于为您的问题找到合适的受众。请编辑您的问题以更新您的标签。也请read about how to ask good questions.
-
我在脚本的 3 个位置看到了 IP 地址。我看到第一个是目标路由器的 telnet IP。另外2个是干什么用的?这些是否会改变,还是保持不变?在设置循环之前需要知道这一点。
-
您好,感谢您的回复。抱歉,如果我没有使用正确的标签,我是这个论坛的新手。这是唯一会改变 WshShell.SendKeys "telnet 10.1.130.91 23" ip 地址的 ip 地址是:10.10.130.91, 10.1.130.101 等等 感谢您的帮助:-)
-
嗨兰迪,是的,这是正确的。非常感谢它可以等待。别着急。