思科configuration备份或重新启动与Windows脚本

我们有很多思科设备的客户,我们希望通过telnet自动备份这些设备。 我们有2003和2008服务器,最好使用tftp来备份。

我写了这个:

Set WshShell = WScript.CreateObject("WScript.Shell") Dim fso Set fso = CreateObject("Scripting.FileSystemObject") Dim ciscoList ciscoList = "D:\Scripts\SwitchList.txt" Set theSwitchList = fso.OpenTextFile(ciscoList, 1) Do While theSwitchList.AtEndOfStream <> True cisco = theSwitchList.ReadLine Run "cmd.exe" SendKeys "telnet " SendKeys cisco SendKeys "{ENTER}" SendKeys "USERNAME" SendKeys "{ENTER}" SendKeys "PASSWORD" SendKeys "{ENTER}" SendKeys "en" SendKeys "{ENTER}" SendKeys "PASSWORD" SendKeys "{ENTER}" SendKeys "copy startup-config tftp{ENTER}" SendKeys "(TFTP IP){ENTER}" SendKeys "FileName.txt{ENTER}" SendKeys "exit{ENTER}" 'close telnet session' SendKeys "{ENTER}" 'get command prompt back SendKeys "{ENTER}" SendKeys "exit{ENTER}" 'close cmd.exe On Error Resume Next WScript.Sleep 3000 Loop Sub SendKeys(s) WshShell.SendKeys s WScript.Sleep 300 End Sub Sub Run(command) WshShell.Run command WScript.Sleep 100 WshShell.AppActivate command WScript.Sleep 300 End Sub 

但是,这个问题是sendkeys发送到控制台会话,我试图find一个解决scheme,不需要用户login。

有没有人有任何想法? 我有一些关于VBS,PowerShell的知识和对批处理的很好的把握。

我想通了(这个重新启动它们,但它可以轻松地重新键入备份)这是一个PowerShell脚本

 #param([String] $remoteHost =$(throw "Please specify the Target Server"),[String] $domain = $(throw "Please specify the #recipient Domain"),[String] $sendingdomain = $(throw "Please specify the Sending Domain")) param([String] $remoteHost,[String] $domain, [String] $sendingdomain) $remotehosts ="List","Of","Cisco","IPs" $theUn = "UserName" $thePw = "Password" function readResponse { while($stream.DataAvailable) { $read = $stream.Read($buffer, 0, 1024) write-host -n -foregroundcolor cyan ($encoding.GetString($buffer, 0, $read)) "" } } $port = 23 foreach($remoteHost in $remoteHosts) { $socket = new-object System.Net.Sockets.TcpClient($remoteHost, $port) if($socket -eq $null) { return; } $stream = $socket.GetStream() $writer = new-object System.IO.StreamWriter($stream) $buffer = new-object System.Byte[] 1024 $encoding = new-object System.Text.AsciiEncoding $command = $theUn $writer.WriteLine($command) $writer.Flush() start-sleep -m 3000 readResponse($stream) write-host -foregroundcolor DarkGreen $command "" $command = $thePw $writer.WriteLine($command) $writer.Flush() start-sleep -m 2000 readResponse($stream) write-host -foregroundcolor DarkGreen $command "" $command = "en" $writer.WriteLine($command) $writer.Flush() start-sleep -m 2000 readResponse($stream)= write-host -foregroundcolor DarkGreen $command "" $command = $thePw $writer.WriteLine($command) $writer.Flush() start-sleep -m 2000 readResponse($stream) write-host -foregroundcolor DarkGreen $command "" $command = "wr" $writer.WriteLine($command) $writer.Flush() start-sleep -m 5000 readResponse($stream) write-host -foregroundcolor DarkGreen $command "" $command = "" $writer.WriteLine($command) $writer.Flush() start-sleep -m 2000 readResponse($stream) write-host -foregroundcolor DarkGreen $command "" $command = "reload" $writer.WriteLine($command) $writer.Flush() start-sleep -m 2000 readResponse($stream) write-host -foregroundcolor DarkGreen $command "" $command = "" $writer.WriteLine($command) $writer.Flush() start-sleep -m 2000 readResponse($stream) write-host -foregroundcolor DarkGreen $command "" $writer.Flush() readResponse($stream) ## Close the streams $writer.Close() start-sleep -m 120000 } 

我怀疑这是完美的,但它挑衅的作品。

这不完全回答你的问题,但我使用猕猴桃CatTools这个事情。

http://www.kiwisyslog.com/kiwi-cattools-overview/

你检查了IOS的归档指令吗? 你可以把它指向一个tftp服务器,每当configuration被改变,它只是存档.. http://www.cisco.com/en/US/docs/ios/12_3t/fun/command/reference/cfrgt_01.html# wp1094316