-1

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

kostix
  • 51,517
  • 14
  • 93
  • 176
Dan
  • 2,020
  • 5
  • 32
  • 55

1 Answers1

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

kostix
  • 51,517
  • 14
  • 93
  • 176
  • Hmm, I suspect that `exec cd` is _very_ unlikely to do what he wants. – Donal Fellows Jan 30 '14 at 22:40
  • 1
    @DonalFellows, that was my immediate reaction, too but I then realised I really have no idea what they did to Tcl in Cisco IOS, so my take is to try to debug the thing. `catch` (unless somehow overridden) should catch the error should `exec cd` fail. – kostix Jan 31 '14 at 08:49
  • @DonalFellows, to this same venue... `cd` with a relative pathname also smells bad in my book unless some guide on the system explicitly states what's the `cwd` of an executing script. – kostix Jan 31 '14 at 08:50
  • Oh, I don't know what it does either, but I _really_ think it's more likely that he wants a multi-line script fed into some kind of interpreter. But I don't know where the outer Tcl script is running or any of this stuff. It's possible that running ssh inside expect and connecting to the router before sending an inner Tcl script is the right approach. Well, maybe… – Donal Fellows Jan 31 '14 at 09:26