cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1258
Views
0
Helpful
1
Replies

workaround for using EEM on NXOS

Alex Steer
Level 1
Level 1

Hello there,

So, I've been hunting around (and stealing) other people's EEM code to produce a simple EEM script to backup an IOS device's configuration.  It looks a little like this;

 

 action 1.0 info type routername
 action 2.0 cli command "enable"
 action 3.0 cli command "show clock"
 action 4.0 regexp "([0-9]+) ([0-9]+)" "$_cli_result" match day year
 action 5.0 regexp "([a-zA-Z]+) [0-9]+ [0-9]+" "$_cli_result" match month

 action 6.0 cli command "copy running-config tftp" pattern "Address or name of remote host"
 action 7.0 cli command "X.X.X.X" pattern "Destination filename"
 action 8.0 cli command "$_info_routername.$day.$month.$year.cfg"

Thanks to the beautiful regexp Joseph put in another post this works beautifully.  Unfortunately NX-OS seems lacking in EEM support in an IOS sense for some reason.  Maybe it's just different but either way, it's frustrating that this stuff can't be standardised.  Anyway, whine over.

I've come up with this basic config to login to a nexus switch and backup a config.

 action 1.0 cli command "enable"
 action 2.0 cli command "ssh -l MYUSERNAME NE.X.US.IP" pattern "Password:"
 action 2.5 wait 5
 action 3.0 cli command "MYPASSWORD" pattern "http://www.opensource.org/licenses"
 action 4.0 cli command "copy running-config tftp://TFTP-SERVER./NEXUS.cfg vrf default" pattern "Copy complete"
 action 4.5 wait 5
 action 5.0 cli command "exit" pattern "closed by foreign host"

This also works great.

I'm trying to make it a little more complex to get the hostname and date automatically.  My applet looks something like the following;

 action 1.0 cli command "enable"
 action 1.2 cli command "ssh -l MYUSERNAME NE.XU.S.IP" pattern "Password:"
 action 1.4 wait 20
 action 1.6 cli command "MYPASSWORD" pattern "http://www.opensource.org/licenses"
 action 1.8 wait 2
 action 2.0 cli command "show run | inc hostname"
 action 2.2 regexp "hostname ([a-zA-Z0-9]+)" "$_cli_result" match hostname
 action 3.0 cli command "show clock"
 action 3.2 regexp "([0-9]+) ([0-9]+)" "$_cli_result" match day year
 action 3.4 regexp "([a-zA-Z]+) [0-9]+ [0-9]+" "$_cli_result" match month
 action 4.0 cli command "copy running-config tftp://TFTP.SERVER/$hostname.$day.$month.$year.cfg vrf default" pattern "Copy complete"
 action 4.2 wait 10
 action 9.2 cli command "exit" pattern "closed by foreign host"

 

Seems I'm failing woefully to get this to work.  Currently the applet hangs at the "show run | inc hostname" command.  It doesn't seem to matter what command I put there.  It gets no response from the Nexus switch, at least that EEM can see.  The session just dies.

024103: Aug 19 14:49:12.946 BST: %HA_EM-6-LOG: nexus1 : DEBUG(cli_lib) : : IN  : show run | inc hostname
........

Has anyone got any ideas what I'm doing wrong here?
Also, can someone advice as to whether my action 2.2 looks to be correct to regex the Nexus device hostname correctly?

Many thanks for any suggestions.

Kind regards,

 

Alex

 

1 Reply 1

Alex Steer
Level 1
Level 1

Just to follow up, it seems without a 'pattern "something"' at the end the 'action cli command' isn't very happy.  I now have the following with 'pattern' add after the show run and show clock command.  A quick correction to the regexp and I seem to have it working...

In case anyone is interested in future.

 action 1.0 cli command "enable"
 action 1.2 cli command "ssh -l MYUSERNAME NE.X.US.IP" pattern "Password:"
 action 1.4 wait 5
 action 1.6 cli command "MYPASSWORD" pattern "http://www.opensource.org/licenses"
 action 1.8 wait 2
 action 2.0 cli command "show run | inc hostname" pattern "hostname"
 action 2.2 regexp "([a-zA-Z0-9]+)" "$_cli_result" match hostname
 action 3.0 cli command "show clock" pattern "20"
 action 3.2 regexp "([0-9]+) ([0-9]+)" "$_cli_result" match day year
 action 3.4 regexp "([a-zA-Z]+) [0-9]+ [0-9]+" "$_cli_result" match month
 action 4.0 cli command "copy running-config tftp://TFTP-SERVER/$hostname.$day.$month.$year.cfg vrf default" pattern "Copy complete"
 action 4.2 wait 5
 action 9.2 cli command "exit" pattern "closed by foreign host"