11-23-2013 06:41 AM
What im trying to do:
1. Have the switch do a showtech every 2 hours
2. Send the showtech to flash
3. The first showtech will be techinfo1.txt
4. The second will be techinfo2.txt
5. The next showtech will overwrite techinfo1.txt
6. The next showtech will overwrite techinfo2.txt and so forth.
Is this possible? In the direction of regexpressions possibly?
Write now I have it appending to flash in one file and than once it hits a certain file size, clearing the file and restarting it. I don't like doing it like that.
::cisco::eem::event_register_timer cron name tech1 cron_entry 0 */2 ***
namespace import ::cisco::eem::*
namespace import ::cisco::lib::*
array set arr_einfo [event_reqinfo]
set x = file size flash:techinfo.txt
if {$x > 5242880}
file delete flash:techinfo.txt
else{
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_exec $cli1(fd) "show tech-support | append flash:techinfo.txt"} _cli_result] {
error $_cli_result $errorInfo
}
}
catch {cli_close $cli1(fd) $cli1(tty_id)} result
Credit to Joseph Clark for the applet converter
Solved! Go to Solution.
01-13-2014 11:55 AM
Debug Output
*Jan 13 09:55:18.439: %HA_EM-6-LOG: showtech.tcl: Process Forced Exit- MAXRUN ti mer expired.
*Jan 13 09:55:18.439: %HA_EM-6-LOG: showtech.tcl: while executing
*Jan 13 09:55:18.439: %HA_EM-6-LOG: showtech.tcl: "after 100"
*Jan 13 09:55:18.439: %HA_EM-6-LOG: showtech.tcl: (procedure "cli_read" line 26)
*Jan 13 09:55:18.439: %HA_EM-6-LOG: showtech.tcl: invoked from within
*Jan 13 09:55:18.439: %HA_EM-6-LOG: showtech.tcl: "cli_read $fd"
*Jan 13 09:55:18.439: %HA_EM-6-LOG: showtech.tcl: (procedure "cli_exec" line 4)
*Jan 13 09:55:18.439: %HA_EM-6-LOG: showtech.tcl: invoked from within
*Jan 13 09:55:18.439: %HA_EM-6-LOG: showtech.tcl: "cli_exec $cli1(fd) "show tech | redirect $filename" "
*Jan 13 09:55:18.439: %HA_EM-6-LOG: showtech.tcl: invoked from within
*Jan 13 09:55:18.439: %HA_EM-6-LOG: showtech.tcl: "$slave eval $Contents"
*Jan 13 09:55:18.439: %HA_EM-6-LOG: showtech.tcl: (procedure "eval_script" l ine 7)
*Jan 13 09:55:18.439: %HA_EM-6-LOG: showtech.tcl: invoked from within
*Jan 13 09:55:18.439: %HA_EM-6-LOG: showtech.tcl: "eval_script slave $scriptname "
*Jan 13 09:55:18.439: %HA_EM-6-LOG: showtech.tcl: invoked from within
*Jan 13 09:55:18.439: %HA_EM-6-LOG: showtech.tcl: "if {$security_level == 1} { #untrusted script
*Jan 13 09:55:18.439: %HA_EM-6-LOG: showtech.tcl: interp create -safe slave
*Jan 13 09:55:18.439: %HA_EM-6-LOG: showtech.tcl: interp share {} stdin sla ve
*Jan 13 09:55:18.439: %HA_EM-6-LOG: showtech.tcl: interp share {} stdout sl ave
*Jan 13 09:55:18.439: %HA_EM-6-LOG: showtech.tcl: ..."
*Jan 13 09:55:18.439: %HA_EM-6-LOG: showtech.tcl: (file "tmpsys:/lib/tcl/bas e.tcl" line 50)
*Jan 13 09:55:18.439: %HA_EM-6-LOG: showtech.tcl: Tcl policy execute failed:
*Jan 13 09:55:18.439: %HA_EM-6-LOG: showtech.tcl: Process Forced Exit- MAXRUN ti mer expired.Process Forced Exit- MAXRUN timer expired.
*Jan 13 09:55:18.712: %HA_EM-6-LOG: showtech.tcl : DEBUG(cli_lib) : CTL : cli_op en called.
*Jan 13 09:55:18.850: %HA_EM-6-LOG: showtech.tcl : DEBUG(cli_lib) : OUT : Switch >
*Jan 13 09:55:18.851: %HA_EM-6-LOG: showtech.tcl : DEBUG(cli_lib) : IN : Switch >enable
*Jan 13 09:55:19.057: %HA_EM-6-LOG: showtech.tcl : DEBUG(cli_lib) : OUT : Switch #
*Jan 13 09:55:19.062: %HA_EM-6-LOG: showtech.tcl : DEBUG(cli_lib) : IN : Switch #config t
*Jan 13 09:55:19.300: %HA_EM-6-LOG: showtech.tcl : DEBUG(cli_lib) : OUT : Enter configuration commands, one per line. End with CNTL/Z.
*Jan 13 09:55:19.300: %HA_EM-6-LOG: showtech.tcl : DEBUG(cli_lib) : OUT : Switch (config)#
*Jan 13 09:55:19.301: %HA_EM-6-LOG: showtech.tcl : DEBUG(cli_lib) : IN : Switch (config)#file prompt quiet
*Jan 13 09:55:19.507: %HA_EM-6-LOG: showtech.tcl : DEBUG(cli_lib) : OUT : Switch (config)#
*Jan 13 09:55:19.507: %HA_EM-6-LOG: showtech.tcl : DEBUG(cli_lib) : IN : Switch (config)#end
*Jan 13 09:55:19.514: %SYS-5-CONFIG_I: Configured from console by on vty0 (EEM: showtech.tcl)
*Jan 13 09:55:19.617: %HA_EM-6-LOG: showtech.tcl : DEBUG(cli_lib) : OUT : Switch #
*Jan 13 09:55:19.617: %HA_EM-6-LOG: showtech.tcl : DEBUG(cli_lib) : IN : Switch #delete /force flash:newtech.txt
*Jan 13 09:55:19.828: %HA_EM-6-LOG: showtech.tcl : DEBUG(cli_lib) : OUT : Switch #
*Jan 13 09:55:19.828: %HA_EM-6-LOG: showtech.tcl : DEBUG(cli_lib) : IN : Switch #copy flash:oldtech.txt flash:newtech.txt
*Jan 13 09:55:20.437: %HA_EM-6-LOG: showtech.tcl : DEBUG(cli_lib) : OUT : Copy i n progress...CCCCCCCCCCCCC
*Jan 13 09:55:20.437: %HA_EM-6-LOG: showtech.tcl : DEBUG(cli_lib) : OUT : 797674 bytes copied in 0.340 secs (2346100 bytes/sec)
*Jan 13 09:55:20.437: %HA_EM-6-LOG: showtech.tcl : DEBUG(cli_lib) : OUT : Switch #
*Jan 13 09:55:20.438: %HA_EM-6-LOG: showtech.tcl : DEBUG(cli_lib) : IN : Switch #config t
*Jan 13 09:55:20.646: %HA_EM-6-LOG: showtech.tcl : DEBUG(cli_lib) : OUT : Enter configuration commands, one per line. End with CNTL/Z.
*Jan 13 09:55:20.646: %HA_EM-6-LOG: showtech.tcl : DEBUG(cli_lib) : OUT : Switch (config)#
*Jan 13 09:55:20.647: %HA_EM-6-LOG: showtech.tcl : DEBUG(cli_lib) : IN : Switch (config)#no file prompt quiet
*Jan 13 09:55:20.859: %HA_EM-6-LOG: showtech.tcl : DEBUG(cli_lib) : OUT : Switch (config)#
*Jan 13 09:55:20.859: %HA_EM-6-LOG: showtech.tcl : DEBUG(cli_lib) : IN : Switch (config)#end
*Jan 13 09:55:20.860: %SYS-5-CONFIG_I: Configured from console by on vty0 (EEM: showtech.tcl)
*Jan 13 09:55:20.966: %HA_EM-6-LOG: showtech.tcl : DEBUG(cli_lib) : OUT : Switch #
*Jan 13 09:55:20.967: %HA_EM-6-LOG: showtech.tcl : DEBUG(cli_lib) : IN : Switch #show tech | redirect flash:oldtech.txt
Script:
::cisco::eem::event_register_none maxrun 2200
#Namespace Imports
namespace import ::cisco::eem::*
namespace import ::cisco::lib::*
array set arr_einfo [event_reqinfo]
#Pass CLI Commands
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
}
#Set Variables
set filename "flash:oldtech.txt"
set nfilename "flash:newtech.txt"
#Copy New File to Old at Next Instance
if { [file exists $filename] } {
cli_exec $cli1(fd) "config t"
cli_exec $cli1(fd) "file prompt quiet"
cli_exec $cli1(fd) "end"
cli_exec $cli1(fd) "delete /force $nfilename"
cli_exec $cli1(fd) "copy $filename $nfilename"
cli_exec $cli1(fd) "config t"
cli_exec $cli1(fd) "no file prompt quiet"
cli_exec $cli1(fd) "end"
}
#Pipe Show-Technology to Set Variable
cli_exec $cli1(fd) "show tech | redirect $filename"
catch {cli_close $cli1(fd) $cli1(tty_id)} result
Applet to trigger it:
No. Class Type Event Type Trap Time Registered Name
1 applet user timer countdown Off Fri Jan 10 06:04:58 2014 techtimer
time 1000.000
maxrun 20.000
action 1.0 policy showtech.tcl
01-13-2014 12:05 PM
The redirect is likely triggering another prompt. After the copy, add:
cli_exec $cli1(fd) "delete /force $filename"
01-15-2014 06:38 AM
Great. The script works nicely. Kudos Joe for the troubleshooting help.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide