Include structured command printout in EEM output
From CT3
The Mail multiple printouts from EEM applet document describes how you can send multiple router-generated printouts in a single E-mail message triggered by the Embedded Event Manager. To generate a more structured e-mail in which heading lines separate the various printouts, use one of the following options:
- Store each heading in a separate file on router's embedded flash and include these files into the merged printout with the more commands;
- Use this Tcl script that generates the heading together with the command printout.
Contents |
Installation
Download the source file into flash:include.tcl. Configure alias exec include flash:include.tcl. Invoke with include command.
By default, the script appends the printouts into the flash:output.txt file. Change the source code if your device does not have the flash: file system.
Usage guidelines
Usage: include command-to-execute
Command line parameters:
- command-to-execute: Cisco IOS command to execute. The results of this command are appended to flash:output.txt.
Usage example
To send formatted printout from the router after a reload event, configure the following EEM applet (see also the Mail multiple printouts from EEM applet document for more details).
event manager applet RouterReload event syslog occurs 1 pattern "%SYS-5-RESTART" action 1.0 cli command "delete /force flash:output.txt" action 1.1 cli command "include show version" action 1.2 cli command "include show logging" action 1.3 cli command "more flash:output.txt" action 2.0 info type routername action 2.1 mail server "$_mail_smtp" to "$_mail_rcpt" from "$_info_routername@$_mail_domain" → subject "Reload: $_info_routername" body "$_cli_result"
Author
Ivan Pepelnjak, © 2008 NIL Data Communications
Source code
if { [catch { set results [exec $argv] } err ] } {
puts "Cannot execute '$argv'";
return;
}
if { [catch { set ofile [open "flash:output.txt" a] } err] } {
puts "Cannot open flash:output.txt for append $err";
return;
}
puts $ofile "";
puts $ofile "==========================================";
puts $ofile $argv;
puts $ofile "==========================================";
puts $ofile $results;
close $ofile;
BlogMarks
del.icio.us
digg
Facebook
LinkedIn
Newsvine
reddit
Slashdot