Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
196 views
in Technique[技术] by (71.8m points)

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...