cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
15175
Views
35
Helpful
20
Replies

TcL Script to shut down port on a time schedule

burleyman
Level 8
Level 8

Is there a way to have a TcL script shut and no shut ports on a schedule? for example; shut down the ports at 7:00am and no shut the port at 3:30pm?

Thanks,

Mike

1 Accepted Solution

Accepted Solutions

You'll need this:

puts [open "flash:shut_ports.tcl" w] {set ports [lindex $argv 0]
ios_config "int $ports" "shut" "end"
}

View solution in original post

20 Replies 20

burleyman
Level 8
Level 8

Here is what I was going to try that I found.

event manager applet shutdown-IntGi1-1

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

 action 1.0 cli command "enable"

 action 2.0 cli command "config t"

 action 3.0 cli command "interface gi1/1"

 action 4.0 cli command "shut"

 action 5.0 cli command "end"

event manager applet no-shut-IntGi1-1

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

 action 1.0 cli command "enable"

 action 2.0 cli command "config t"

 action 3.0 cli command "interface gi1/1"

 action 4.0 cli command "no shut"

 action 5.0 cli command "end"

Would this work?

Mike

You asked for Tcl, but these are applet policies.  Your second applet will not work, either.  The cron-entry should be:

event timer cron cron-entry "30 15 * * *"

Also, have a look at https://supportforums.cisco.com/discussion/13076291/automated-shutdown which was a recent thread on a similar topic.

Yes, that is where I found this.

I got mixed up on TcL and EEM, sorry very new to both of these.

I have a 2960-x that I need to shut some ports down between 7:00am and 3:30pm can this be done on this switch with either TcL or EEM?

Mike

The 2960-X does not support full EEM.  Have a look at the "kron" commands.  This will allow you to schedule these same commands without Tcl.

Here is what I am going to test now.

kron policy-list policy_IntShut
cli config t
cli interface Gi1/0/1
cli shut
exit

kron policy-list policy_IntNoShut
cli config t
cli interface Gi1/0/1
cli no shut
exit


kron occurrence policy_IntShut at 16:00 tue recurring
no policy-list policy_IntShut
exit

kron occurrence policy_IntNoShut at 18:30 tue recurring
no policy-list policy_IntNoShut
exit

Sorry I had no in the above post. This is what I was entering.

kron policy-list policy_IntShut
cli config t
cli interface Gi1/0/1
cli shut
exit

kron policy-list policy_IntNoShut
cli config t
cli interface Gi1/0/1
cli no shut
exit


kron occurrence policy_IntShut at 16:00 tue recurring
policy-list policy_IntShut
exit

kron occurrence policy_IntNoShut at 18:30 tue recurring
policy-list policy_IntNoShut
exit

Just tested and it does not work, am I missing something?

I haven't used kron in a while, and I got used to the NX-OS scheduler.  Kron doesn't work with config commands.  You'll need to use a kron with a Tcl script.  Your Tcl scripts should have:

ios_config "int gi1/0/1" "shut" "end"

===

ios_config "int gi1/0/1" "no shut" "end"

Then you can schedule the script to run with the "tclsh flash:/path/to/script" CLI command.

Ok I will see if I can figure it out. I have never programmed TcL but I will give it a go.

Mike

Switch#tclsh
Switch(tcl)#puts [open "flash:shut_port.tcl" w+] "set ports [lindex argv 0] \n ios_config "int $ports" "shut" "end"
Switch(tcl)#exit
Switch#wr mem

Than to call the script at a certain time configura this.

kron policy-list policy_IntShut
tclsh flash:shut_port.tcl "Gi1/0/1"

Does this look right?

You'll need this:

puts [open "flash:shut_ports.tcl" w] {set ports [lindex $argv 0]
ios_config "int $ports" "shut" "end"
}

Thank you. I will give it a go.

Mike

It worked swimmingly, thank you for your help. I do have a some questions....

I understand the puts [open "flash:shut_ports.tcl" w] puts the file to flash but what does the "w" do?

Also what does the line set ports [lindex $argv 0] mean?

lindex means?

$argv 0 means?

the line ios_config "int $ports" "shut" "end" I think I get, this lets it know this is an ios configuration and the $ports is the port that is called out in the line cli tclsh flash:shut_ports.tcl "Gi1/0/1"

Now for the kron occurrence part, is there an easy way to schedule this say Monday through Friday with out creating a separate kron occurrence for each day?

Again thank you for your help.

Here is my end configuration.

!This will create a TcL script and save it to flash
!and it will shut down port Gi1/0/1 at 11:30 every Wednesday
!
tclsh
puts [open "flash:shut_ports.tcl" w] {
set ports [lindex $argv 0]
ios_config "int $ports" "shut" "end"
}
tclquit
config t

kron policy-list policy_IntShut
cli tclsh flash:shut_ports.tcl "Gi1/0/1"

kron occurrence policy_IntShut at 11:30 Wed recurring
policy-list policy_IntShut

exit
exit
wr mem
**************************************************
!This will create a TcL script and save it to flash
!and it will no shut the port Gi1/0/1 at 11:32 every Wednesday
!
tclsh
puts [open "flash:No_shut_ports.tcl" w] {
set ports [lindex $argv 0]
ios_config "int $ports" "no shut" "end"
}
tclquit
config t

kron policy-list policy_IntNoShut
cli tclsh flash:No_shut_ports.tcl "Gi1/0/1"

kron occurrence policy_IntNoShut at 11:32 Wed recurring
policy-list policy_IntNoShut

exit
exit
wr mem

The 'w' means open the file for writing and create a new file if it doesn't exist.

The lindex command pulls out an element from a list (element 0 in this case).

$argv is the argument vector passed to the script at execution time.

To schedule every day at a specific time, use:

occurrence NAME at 11:32 recurring

Just don't specify a day.

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: