问题
I am trying to write a tcl script that will delete and un-register certain policies in my router every morning, but when I try to upload it to the device it wont work. Here is what I have done so far;
::cisco::eem::event_register_timer cron name crontimer2 cron_entry $_cron_entry
namespace import ::cisco::eem::*
namespace import ::cisco::lib::*
exec "en"
exec "cd RuBAN"
exec "delete syslogsyslog_fresh_install.tcl"
exec "delete syslogsyslog_fresh_install.cfg"
exec "delete marvin_fresh_installMarvinfieldst.tcl"
exec "conf t"
exec "no ev m p syslogsyslog_fresh_install.tcl"
exec "no ev m p marvin_fresh_installMarvinfieldst.tcl"
Is my tcl script wrong in the command I have wrote? Can any shed any insight into this, it would be much appreciated
回答1:
One example in this manual displays using of the action_syslog
command to log an event. Could you please try to replace all your exec
s with such a call and see if a message gets logged at all? That is, does your script even run? Also, when the run time of the script passes by, does anything gets currently logged on a system level (like the notice about the failed script execution or whatnot)?
If the script runs, then I suggest enclosing all your exec
s in a catch command to trap possible errors and log them, like this:
::cisco::eem::event_register_timer cron name crontimer2 cron_entry $_cron_entry
namespace import ::cisco::eem::*
namespace import ::cisco::lib::*
set code [catch {
exec "en"
exec "cd RuBAN"
exec "delete syslogsyslog_fresh_install.tcl"
exec "delete syslogsyslog_fresh_install.cfg"
exec "delete marvin_fresh_installMarvinfieldst.tcl"
exec "conf t"
exec "no ev m p syslogsyslog_fresh_install.tcl"
exec "no ev m p marvin_fresh_installMarvinfieldst.tcl"
} res]
if {$code != 0} {
action_syslog priority error msg $res
}
# OK, the commands in the `catch`ed block went well...
Please note that I have absolutely no experience with Cisco IOS so I'm thinking in terms of Tcl running on "conventional" platforms (such as POSIX and Windows).
来源:https://stackoverflow.com/questions/21454227/how-to-write-a-cisco-ios-script-to-run-a-set-of-commands-at-a-certain-time-each