How to write a Cisco IOS script to run a set of commands at a certain time each day?

坚强是说给别人听的谎言 提交于 2019-12-14 04:23:44

问题


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 execs 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 execs 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!