
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2016 04:29 AM
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
Solved! Go to Solution.
- Labels:
-
EEM Scripting
Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2016 02:22 PM
You'll need this:
puts [open "flash:shut_ports.tcl" w] {set ports [lindex $argv 0]
ios_config "int $ports" "shut" "end"
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2016 07:11 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2016 08:01 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2016 08:07 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2016 08:10 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2016 08:46 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2016 10:12 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2016 10:31 AM
Just tested and it does not work, am I missing something?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2016 10:39 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2016 11:59 AM
Ok I will see if I can figure it out. I have never programmed TcL but I will give it a go.
Mike

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2016 01:21 PM
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?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2016 02:22 PM
You'll need this:
puts [open "flash:shut_ports.tcl" w] {set ports [lindex $argv 0]
ios_config "int $ports" "shut" "end"
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2016 03:58 AM
Thank you. I will give it a go.
Mike

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2016 05:24 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2016 07:41 AM
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.
