Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
    
I'm adding this as a comment because it doesn't answer your specific question, but you should consider using rancid to do these backups. It's versioned, so you have a history of changes, it has a community to support it, and most importantly, it will back up stuff that tftp won't (vlan DB, hardware characteristics, etc) –  jj33 Jan 12 '11 at 17:00
    
It needs to be a Windows solution, unfortunately. I could only find documentation for Linux or OSX. –  Jeff Jan 12 '11 at 17:09

3 Answers 3

up vote 2 down vote accepted

I figured it out(this one reboots them but It can easily be rekeyed for backup) This is a PowerShell Script

#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
}

I doubt it's perfect, but it defiantly works.

share|improve this answer

This doesn't exactly answer your question, but I use Kiwi CatTools for this very thing.

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

share|improve this answer
    
I've seen that. If we really need to we can purchase this. I'd rather see if it's possible to script it. –  Jeff Jan 12 '11 at 17:39
    
They do have a free version... –  joeqwerty Jan 12 '11 at 18:06

Have you checked the archive directive of the IOS ? You could point it to a tftp server and every time a config is changed it just archive.. http://www.cisco.com/en/US/docs/ios/12_3t/fun/command/reference/cfrgt_01.html#wp1094316

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.