{"id":1554,"date":"2020-10-05T23:00:00","date_gmt":"2020-10-05T22:00:00","guid":{"rendered":"https:\/\/www.balajibandi.com\/?p=1554"},"modified":"2024-12-14T09:02:04","modified_gmt":"2024-12-14T09:02:04","slug":"eem-back-using-regex-time-stamp","status":"publish","type":"post","link":"https:\/\/www.balajibandi.com\/?p=1554","title":{"rendered":"EEM backup configuration using Regex-time stamp with device name and time stamp."},"content":{"rendered":"\n<p><strong>Make sure you understand below event script before executing :<\/strong><\/p>\n\n\n\n<p>event manager applet DAILY_RUN_CONFIG_BACKUP<\/p>\n\n\n\n<p>description Daily Run Config Backup To Local TFTP Server<\/p>\n\n\n\n<p>event timer watchdog time 400<\/p>\n\n\n\n<p>event none<\/p>\n\n\n\n<p>action 01 cli command &#8220;enable&#8221;<\/p>\n\n\n\n<p>action 02 cli command &#8220;show clock&#8221;<\/p>\n\n\n\n<p>action 03 regexp &#8220;(2[0-3]|[01][0-9]):([0-6][0-9]):([0-6][0-9])&#8221; &#8220;$_cli_result&#8221; time hour minute second<\/p>\n\n\n\n<p>action 04 puts &#8220;$time&#8221;<\/p>\n\n\n\n<p>action 05 puts &#8220;$hour&#8221;<\/p>\n\n\n\n<p>action 06 puts &#8220;$minute&#8221;<\/p>\n\n\n\n<p>action 07 puts &#8220;$second&#8221;<\/p>\n\n\n\n<p>action 08 cli command &#8220;show clock&#8221;<\/p>\n\n\n\n<p>action 09 regexp &#8220;(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) ([1-9]|0[1-9]|[1-2][0-9]|3[0-1]) (20[1-9][0-9])&#8221; &#8220;$_cli_result&#8221; time2 month day year<\/p>\n\n\n\n<p>action 10 puts &#8220;$time2&#8221;<\/p>\n\n\n\n<p>action 11 puts &#8220;$month&#8221;<\/p>\n\n\n\n<p>action 12 puts &#8220;$day&#8221;<\/p>\n\n\n\n<p>action 13 puts &#8220;$year&#8221;<\/p>\n\n\n\n<p>action 14 cli command &#8220;copy \/noconfirm running-config tftp:\/\/10.10.9.254\/ASA-NAME_RUN_CONFIG-$year$month$day-$hour$minute$second.txt&#8221;<\/p>\n\n\n\n<p>action 15 syslog priority informational msg &#8220;Configuration backup to TFTP successfully executed&#8221;<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Some notes :<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>The above script works with Router and Switches also.<\/li>\n\n\n\n<li>puts just output &#8211; you can remove that lines once the EEM Script working.<\/li>\n\n\n\n<li>if you are using AAA make a note: &#8211; If your device uses&nbsp;AAA, you must ensure that the EEM scripts configured on the device are either configured with an AAA user able to run the commands in the script, or that authorization bypass is configured with&nbsp;the command&nbsp;<strong>authorization bypass<\/strong>&nbsp;in the script definition.  ( example &#8211; <strong>event manager applet DAILY_RUN_CONFIG_BACKUP<\/strong>  <strong>authorization bypass<\/strong>)<\/li>\n<\/ol>\n\n\n\n<p>Some good references updated on cisco IOS XE :<\/p>\n\n\n\n<p><a href=\"https:\/\/www.cisco.com\/c\/en\/us\/support\/docs\/ios-nx-os-software\/ios-xe-16\/216091-best-practices-and-useful-scripts-for-ee.html\">https:\/\/www.cisco.com\/c\/en\/us\/support\/docs\/ios-nx-os-software\/ios-xe-16\/216091-best-practices-and-useful-scripts-for-ee.html<\/a><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>If you see any Error in IOS XE as below :<\/p>\n\n\n\n<p><strong>%HA_EM-3-FMPD_UNKNOWN_ENV: fh_parse_var: could not find environment variable: XXX<\/strong><\/p>\n\n\n\n<p>This indicates that you have AAA configured and you need to add <strong>&#8220;authorization bypass&#8221;<\/strong><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>event timer watchdog time 400<\/strong>  &#8211; this is watch dog in seconds &#8211; so it run every 400 Seconds<\/p>\n\n\n\n<p>You can also run using Cron example :<\/p>\n\n\n\n<p><strong>event timer cron name Daily cron-entry &#8220;00 01 * * *&#8221;<\/strong>  &#8211; this run every day at 1:00am (https:\/\/crontab.guru\/ &#8211; give you good example)<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>If you like to run EEM applet to test it :<\/p>\n\n\n\n<p>#<strong>event manager run Mybackup<\/strong><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>If you like to send email backup success :<\/strong><\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><\/h4>\n\n\n\n<p>event manager environment _email_to  email-address<\/p>\n\n\n\n<p>event manager environment smtp.bb.com<\/p>\n\n\n\n<p>event manager environment senderemail<\/p>\n\n\n\n<p>(config)#event manager applet backup_success_email<br>(config-applet)#event syslog pattern &#8220;%HA_EM-6-LOG: Mybackup: Configuration change detected. Write to TFTP succesfully executed&#8221;<br>(config-applet)#action 1.0 mail server &#8220;$_email_server&#8221; to &#8220;$_email_to&#8221; from &#8220;$_email_from&#8221; subject &#8220;$_event_pub_time: Login via SSH&#8221; body &#8220;$_syslog_msg&#8221;<br>(config-applet)#action 1.5 syslog msg priority 5 &#8220;LOGIN SUCCESS &#8211; Mail Sent&#8221;<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><\/h1>\n\n\n\n<p><strong>Same way you can redirect the Logs to TFTP :<\/strong><\/p>\n\n\n\n<p>event manager applet MyLog authorization bypass<br>event none<br>action 1.0 cli command &#8220;enable&#8221;<br>action 2.0 info type routername<br>action 3.0 cli command &#8220;show clock&#8221;<br>action 3.1 regexp &#8220;(2[0-3]|[01][0-9]):([0-6][0-9]):([0-6][0-9])&#8221; &#8220;$_cli_result&#8221; time hour minute second<br>action 3.6 cli command &#8220;show clock&#8221;<br>action 3.7 regexp &#8220;(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) ([1-9]|0[1-9]|[1-2][0-9]|3[0-1]) (20[1-9][0-9])&#8221; &#8220;$_cli_result&#8221; time2 month day year<br>action 4.0 cli command &#8220;show logging | redirect tftp:\/\/x.x.x.x\/$_info_routername-$year$month$day-$hour$minute$second.log&#8221;<br>action 6.0 syslog priority informational msg &#8220;Configuration change detected. Write to TFTP succesfully executed&#8221;<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>EEM Script to capture from log and store in Flash :<\/strong><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>event manager applet logtest authorization bypass<br>event none<br>action 1.0 cli command &#8220;enable&#8221;<br>action 1.1 set cmd01 &#8220;show logging | in BULK&#8221;<br>action 1.2 cli command &#8220;$cmd01&#8221;<br>action 1.3 file open fh flash:error.txt w<br>action 1.4 file write fh &#8220;$_cli_result&#8221;<br>action 1.5 file close fh<\/p>\n\n\n\n<p><strong>#event manager run logtest<\/strong><\/p>\n\n\n\n<p><strong>#more flash:error.txt<\/strong><\/p>\n\n\n\n<p>12:29:49.054: %EWLC_HA_LIB_MESSAGE-6-BULK_SYNC_STATE_INFO: Switch 2 R0\/0: wncmgrd: INFO: Bulk sync status : COLD\/n slot memory init failed for 1<br>12:32:37.785: %EWLC_HA_LIB_MESSAGE-6-BULK_SYNC_STATE_INFO: Switch 1 R0\/0: wncmgrd: INFO: Bulk sync status : HOT<br>12:32:37.591: %EWLC_HA_LIB_MESSAGE-6-BULK_SYNC_STATE_INFO: Switch 2 R0\/0: wncmgrd: INFO: Bulk sync status : HOT<br>12:32:45.428: %HA_CONFIG_SYNC-6-BULK_CFGSYNC_SUCCEED: Bulk Sync succeeded<\/p>\n\n\n\n<p>Happy Labbing &#8230;.!!!!!<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Make sure you understand below event script before executing : event manager applet DAILY_RUN_CONFIG_BACKUP description Daily Run Config Backup To Local TFTP Server event timer watchdog time 400 event none action 01 cli command &#8220;enable&#8221; action 02 cli command &#8220;show clock&#8221; action 03 regexp &#8220;(2[0-3]|[01][0-9]):([0-6][0-9]):([0-6][0-9])&#8221; &#8220;$_cli_result&#8221; time hour minute second action 04 puts &#8220;$time&#8221; action [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-1554","post","type-post","status-publish","format-standard","hentry","category-cisco"],"_links":{"self":[{"href":"https:\/\/www.balajibandi.com\/index.php?rest_route=\/wp\/v2\/posts\/1554","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.balajibandi.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.balajibandi.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.balajibandi.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.balajibandi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1554"}],"version-history":[{"count":31,"href":"https:\/\/www.balajibandi.com\/index.php?rest_route=\/wp\/v2\/posts\/1554\/revisions"}],"predecessor-version":[{"id":2436,"href":"https:\/\/www.balajibandi.com\/index.php?rest_route=\/wp\/v2\/posts\/1554\/revisions\/2436"}],"wp:attachment":[{"href":"https:\/\/www.balajibandi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1554"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.balajibandi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1554"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.balajibandi.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1554"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}