cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
7395
Views
0
Helpful
3
Replies

Tcl script to copy config to tftp server every evening

dnorris
Level 1
Level 1

Hi Guys, I have very little experience with TCL script, hoping yall can help me out.  I have a customer who is wanting to send a copy of their running config to a tftp server every evening at around 10pm thats all they want to do.  Any help on this would be greatly appreciated.             

Thanks

Darren

3 Replies 3

Jason Pfeifer
Cisco Employee
Cisco Employee

Hi Darren,

The following CLI applet should perform what you want to do:

event manager applet backer

event timer cron cron-entry "0 10 * * *"

action 1 cli command "enable"

action 2 cli command "copy running tftp:" pattern "Address"

action 3 cli command "" pattern "Destination"

action 4 cli command ""

The related TCL script would be:

::cisco::eem::event_register_timer cron cron_entry "0 10 * * *"


namespace import ::cisco::eem::*
namespace import ::cisco::lib::*


if [catch {cli_open} result] {
    error $result $errorInfo
} else {
    array set cli1 $result
}

if [catch {cli_exec $cli1(fd) "enable"} _cli_result] {
    error $_cli_result $errorInfo
}

if [catch {cli_write $cli1(fd) "copy running tftp:"} _cli_result] {
    error $_cli_result $errorInfo
}

if [catch {cli_read_pattern $cli1(fd) "Address"} _cli_result] {
    error $_cli_result $errorInfo
}

if [catch {cli_write $cli1(fd) ""} _cli_result] {
    error $_cli_result $errorInfo
}

if [catch {cli_read_pattern $cli1(fd) "Destination"} _cli_result] {
    error $_cli_result $errorInfo
}

if [catch {cli_exec $cli1(fd) ""} _cli_result] {
    error $_cli_result $errorInfo
}


# Close open cli before exit.
if [catch {cli_close $cli1(fd) $cli1(tty_id)} result] {
    error $result $errorInfo
}

One minor note, to copy at 10 pm, the cron entry would be:

event timer cron cron-entry "0 22 * * *"

or

::cisco::eem::event_register_timer cron cron_entry "0 22 * * *"

lukaszpekalski
Level 1
Level 1
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: