Cisco Configuration backup with Windows Script.
- by Jeff
We have a client with a lot of Cisco Devices and we would like to automate the backups of these devices through telnet. We have both 2003 and 2008 servers and ideally use tftp to back it up.
I wrote this:
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
But the problem with this is the sendkeys are sent to the console session, I'm trying to find a solution that would not require a user to be logged in.
Does anyone have any ideas? I have some knowlage of VBS, PowerShell and a pretty good grasp on batching.