Showing results for 
Search instead for 
Did you mean: 

Command output redirect question

Liam Devine

Hi guys,

I am putting in a kron function to transfer the command output from all the switches and routers on our network to a tftp server.

I have the kron occurence and policy lists set up the way I want them and have tested the redirection of the command line output to the server.

The problem I have is that I want to back up the switches 3 or 4 times once a week to compare the configs to make sure that no unwanted changes are being made over the course of the month.

Is there a way to use a variable to change the file name when it redirects? Currently when the occurence runs the file modified time on the tftp server changes but the output doesnt append as I had hoped it would, i.e one file having the config copy in to the file over and over.

Thanks for your help

2 Replies 2



I can imagine few ways to do it...

First and very simple way is to use some TCL/expect script from some unix machine and log it(log_file -noappend yourfilename.txt) to text file.

For example You can send to remote box:

send "show platform info inventory full pa-shelf pa 0 assembly-id \n"
expect "assembly-id : $"

After script execution You can rename it to for ex. "date".

Finally for comparing config text files You can use unix DIFF command.

It can be something like this:

#!/usr/bin/expect -f

spawn ssh remote-user@
                        expect "*password: $"
                        send -- "mypassword\n"
                        log_file -noappend myloglie.txt
                        expect "*> $"
                        send "show platform info inventory full chassis assembly-id \n"
                        expect "assembly-id : $"

send "exit\n"

SSH You can change to TELNET or what ever You want :-)

Joe Clarke
Hall of Fame Cisco Employee Hall of Fame Cisco Employee
Hall of Fame Cisco Employee

You might want to consider the built-in Config Archive feature instead of kron.  With Config Archive, you can periodically take backups of your config (even to a network server), and you can adjust the filenames using either date or hostname (or both).  Check out the documentation at for more details.

In addition to Config Archive, you also have the option of going with the Embedded Event Manager.  EEM also has a cron feature which will allow you to run CLI commands periodically.  Depending on your IOS version, it may be possible to do what you want using a simple EEM applet, or you might have to use a Tcl script policy.  More on EEM can be found at .

All that said, most TFTP servers have a security requirement that a file must exist on the server before one can write to it.  Therefore, if you try and create new files (i.e. a new file each day), the TFTP server may reject the WRITE REQUEST unless a file with that name already exists.  In light of that, you may need to use something like SCP or FTP instead.

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community:

Recognize Your Peers