cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1397
Views
0
Helpful
2
Replies

Quite simple question...i think so...filename on flash via variables

Hi,

i´m stumbling over my inabilty to use a variable for writing a filename to the routers flash, idea is to collect some information via EEM/kron, and send them to a central site.

Should be easy, but my problem is, i cannot append the routers hostname to the file on the flash. I have actually NO idea how i should do this, avoiding the use of tcl. And the idea is to have exactly one script i can use on all routers, without modifying it, thats for why i want to just use the variable.

Is there a restriction using variables on filesystem operations?

This one works:

event manager applet SYSREPORT
event none
action 1.000 cli command "enable"
action 1.005 cli command "delete /force flash:sysreport"
action 1.010 cli command "sh ver | t flash:sysreport"
action 1.015 cli command "dir flash: | a flash:sysreport"
action 1.020 cli command "sh pro cpu his | a flash:sysreport"
action 1.030 cli command "sh ip int brief | a flash:sysreport"
action 1.040 cli command "sh int des | a flash:sysreport"
action 1.050 cli command "sh ip ospf neigh | a flash:sysreport"
action 1.060 cli command "sh run | a flash:sysreport"

This one not, would have been nicer because i can dampen it to outputs i need:

event manager applet SYSREPORT
event none
action 1.000 cli command "enable"
action 1.005 cli command "delete /force flash:/sysreport.$_info_routername"
action 1.010 cli command "sh ver | i ^Cisco|_ID|uptime|reason|.bin"
action 1.015 cli command "more $_cli_result | t flash:/sysreport.$_info_routername"
action 1.020 cli command "sh pro cpu his"
action 1.025 cli command "more $_cli_result | a flash:/sysreport.$_info_routername"
action 1.030 cli command "sh ip int brief | e down"
action 1.035 cli command "more $_cli_result | a flash:/sysreport.$_info_routername"
action 1.040 cli command "sh int des | i up"
action 1.045 cli command "more $_cli_result | a flash:/sysreport.$_info_routername"
action 1.050 cli command "sh int des | i down"
action 1.055 cli command "more $_cli_result | a flash:/sysreport.$_info_routername"
action 1.060 cli command "sh ip ospf neigh"
action 1.065 cli command "more $_cli_result | a flash:/sysreport.$_info_routername"
action 1.070 cli command "sh ip route | i _00:"
action 1.075 cli command "more $_cli_result | a flash:/sysreport.$_info_routername"
action 1.080 cli command "sh run"
action 1.085 cli command "more $_cli_result | a flash:/sysreport.$_info_routername"

But OK, this one also not:

event manager applet SYSREPORT
event none
action 1.000 cli command "enable"
action 1.005 cli command "delete /force flash:/sysreport.$_info_routername"
action 1.010 cli command "sh ver | t flash:/sysreport.$_info_routername"
action 1.015 cli command "dir flash: | a flash:/sysreport.$_info_routername"
action 1.020 cli command "sh pro cpu his | a flash:/sysreport.$_info_routername"
action 1.030 cli command "sh ip int brief | a flash:/sysreport.$_info_routername"
action 1.040 cli command "sh int des | a flash:/sysreport.$_info_routername"
action 1.050 cli command "sh ip ospf neigh | a flash:/sysreport.$_info_routername"
action 1.060 cli command "sh run | a flash:/sysreport.$_info_routername"

I tried around with this also:

 event manager environment _info_routername $(hostname)

No effect, it´s "$(hostname)" then, as already expected.

How can i manipulate (without tcl) the filename to use variables which should exist already in EEM?

I assumed i can use the variable here:

https://supportforums.cisco.com/document/102581/eem-built-action-variables

But it seems i need to somehow use "action info type routername" to get it, because it throws me the message:

%HA_EM-3-FMPD_UNKNOWN_ENV: fh_parse_var: could not find environment variable: _info_routername

when debugging EEM.

Any help appreciated, i hope it´s just a small thing i didn´t get properly.

All i want is a file called sysreport.<ROUTERNAME> in the flash...should be not too complicated, i thought...

Thank you in advance,

Andreas

1 Accepted Solution

Accepted Solutions

Joe Clarke
Cisco Employee
Cisco Employee

Before you can use $_info_routername, you need to call the "info type routername" action.  For example:

action 0.5 info type routername

Your second applet will not work as you can't "more" a variable.  But your last applet should work once you add the action above.

View solution in original post

2 Replies 2

Joe Clarke
Cisco Employee
Cisco Employee

Before you can use $_info_routername, you need to call the "info type routername" action.  For example:

action 0.5 info type routername

Your second applet will not work as you can't "more" a variable.  But your last applet should work once you add the action above.

Many thanks Joe, you are the best!

Finished the Script now, works like a charm...every 72 hours a Sysreport-file is generated and uploaded on the FTP-server as desired, including a sortable timestamp...at least until 31.12.2019 ;)

My script now looks like this, maybe it helps others as well, to be :

ip ftp username <FTP-USERNAME>
ip ftp password <FTP-PASSWORD>
!
event manager applet SYSREPORT
event none sync yes
action 1.000 info type routername
action 1.010 set month "XX"
action 1.020 set _month0 "XX"
action 1.030 set day "0"
action 1.040 set _day0 "XX"
action 1.050 set year "XXXX"
action 2.000 cli command "enable"
action 3.000 cli command "show clock"
action 3.005 regexp "Jan" "$_cli_result" _month0
action 3.010 regexp "Feb" "$_cli_result" _month0
action 3.015 regexp "Mar" "$_cli_result" _month0
action 3.020 regexp "Apr" "$_cli_result" _month0
action 3.025 regexp "May" "$_cli_result" _month0
action 3.030 regexp "Jun" "$_cli_result" _month0
action 3.035 regexp "Jul" "$_cli_result" _month0
action 3.040 regexp "Aug" "$_cli_result" _month0
action 3.045 regexp "Sep" "$_cli_result" _month0
action 3.050 regexp "Oct" "$_cli_result" _month0
action 3.055 regexp "Nov" "$_cli_result" _month0
action 3.060 regexp "Dec" "$_cli_result" _month0
action 3.100 if $_month0 eq "Jan"
action 3.101 set month "01"
action 3.102 end
action 3.105 if $_month0 eq "Feb"
action 3.106 set month "02"
action 3.107 end
action 3.110 if $_month0 eq "Mar"
action 3.111 set month "03"
action 3.112 end
action 3.115 if $_month0 eq "Apr"
action 3.116 set month "04"
action 3.117 end
action 3.120 if $_month0 eq "May"
action 3.121 set month "05"
action 3.122 end
action 3.125 if $_month0 eq "Jun"
action 3.126 set month "06"
action 3.127 end
action 3.130 if $_month0 eq "Jul"
action 3.131 set month "07"
action 3.132 end
action 3.135 if $_month0 eq "Aug"
action 3.136 set month "08"
action 3.137 end
action 3.140 if $_month0 eq "Sep"
action 3.141 set month "09"
action 3.142 end
action 3.145 if $_month0 eq "Oct"
action 3.146 set month "10"
action 3.147 end
action 3.150 if $_month0 eq "Nov"
action 3.151 set month "11"
action 3.152 end
action 3.155 if $_month0 eq "Dec"
action 3.156 set month "12"
action 3.157 end
action 3.160 puts "Zeile 3.160 Variable Monat=*$month*"
action 4.000 cli command "show clock"
action 4.005 regexp ".. 201." "$_cli_result" _day0
action 4.010 regexp ".. " "$_day0" _day1
action 4.015 regexp "([0-9.]+)" "$_day1" day
action 4.100 if $day eq "1"
action 4.101 set day "01"
action 4.102 end
action 4.105 if $day eq "2"
action 4.106 set day "02"
action 4.107 end
action 4.110 if $day eq "3"
action 4.111 set day "03"
action 4.112 end
action 4.115 if $day eq "4"
action 4.116 set day "04"
action 4.117 end
action 4.120 if $day eq "5"
action 4.121 set day "05"
action 4.122 end
action 4.125 if $day eq "6"
action 4.126 set day "06"
action 4.127 end
action 4.130 if $day eq "7"
action 4.131 set day "07"
action 4.132 end
action 4.135 if $day eq "8"
action 4.136 set day "08"
action 4.137 end
action 4.140 if $day eq "9"
action 4.141 set day "09"
action 4.142 end
action 4.150 puts "Zeile 4.150 Variable Tag=*$day*"
action 5.000 cli command "show clock"
action 5.005 regexp "201." "$_cli_result" year
action 5.010 puts "Zeile 5.010 Variable Jahr=*$year*"
action 5.020 cli command "conf term"
action 5.030 cli command "file prompt quiet"
action 5.040 cli command "end"
action 6.000 cli command "delete /force flash:/sysreport.$_info_routername"
action 6.010 cli command "sh ver | t flash:/sysreport.$_info_routername"
action 6.020 cli command "dir flash: | a flash:/sysreport.$_info_routername"
action 6.030 cli command "sh proc cpu his | a flash:/sysreport.$_info_routername"
action 6.040 cli command "sh ip int brief | a flash:/sysreport.$_info_routername"
action 6.050 cli command "sh int des | a flash:/sysreport.$_info_routername"
action 6.060 cli command "sh ip ospf neigh | a flash:/sysreport.$_info_routername"
action 6.070 cli command "sh run | a flash:/sysreport.$_info_routername"
action 6.080 cli command "copy flash:/sysreport.$_info_routername ftp://<IP-ADDRESS-OF-FTP-SERVER>/sysreport.$_info_routername.$year$month$day.txt"
action 6.090 cli command "conf term"
action 6.100 cli command "no file prompt quiet"
action 6.110 cli command "end"
action 7.000 puts "Datum=* Jahr:$year Monat:$month Tag:$day *"
action 7.005 exit
!
kron occurrence 3DAY-SCHEDULE in 3:0:0 recurring system-startup
policy-list SYSREPORT-SCHEDULE
!
kron policy-list SYSREPORT-SCHEDULE
cli event manager run SYSREPORT