{"id":2223,"date":"2017-03-24T15:39:35","date_gmt":"2017-03-24T15:39:35","guid":{"rendered":"http:\/\/mccltd.net\/blog\/?p=2223"},"modified":"2017-06-15T15:08:46","modified_gmt":"2017-06-15T14:08:46","slug":"archive-dhcp-bindings-from-cisco-router-using-eem","status":"publish","type":"post","link":"http:\/\/darenmatthews.com\/blog\/?p=2223","title":{"rendered":"Archive DHCP Bindings from Cisco Router using EEM"},"content":{"rendered":"<p>This recipe describes a simple method to send DHCP bindings from a Cisco router to a remote TFTP server running on Windows. \u00a0A batch file renanes and date-stamps the file and another batch file removes the archived files after a retention period:<\/p>\n<p><strong>EEM SCRIPT ON CISCO\u00a0ROUTER:<\/strong><\/p>\n<blockquote><p>(<strong>Note:<\/strong> the cron entry sends the file every 5 minutes)<br \/>\nevent manager session cli username &#8220;your_username&#8221; \u00a0(NOTE: this is required if tacacs+ is running on the router)<br \/>\nevent manager applet copy-dhcp-bindings<br \/>\nevent timer cron cron-entry &#8220;*\/5 * * * * &#8221;<br \/>\naction 0.5 cli command &#8220;enable&#8221;<br \/>\naction 1.0 cli command &#8220;show ip dhcp binding | redirect tftp:\/\/[ip_address]\/bindings.txt&#8221;<br \/>\n!<br \/>\nend<!--more--><\/p>\n<p><strong>BATCH FILE ON TFTP SERVER TO DATE-STAMP FILES RECEIVED:<\/strong><br \/>\n@echo off<br \/>\n:loop<br \/>\nfor \/f &#8220;delims=&#8221; %%a in (&#8216;wmic OS Get localdatetime ^| find &#8220;.&#8221;&#8216;) do set &#8220;dt=%%a&#8221;<br \/>\nset &#8220;YY=%dt:~2,2%&#8221;<br \/>\nset &#8220;YYYY=%dt:~0,4%&#8221;<br \/>\nset &#8220;MM=%dt:~4,2%&#8221;<br \/>\nset &#8220;DD=%dt:~6,2%&#8221;<br \/>\nset &#8220;HH=%dt:~8,2%&#8221;<br \/>\nset &#8220;Min=%dt:~10,2%&#8221;<br \/>\nset &#8220;Sec=%dt:~12,2%&#8221;<\/p>\n<p>set datestamp=%YYYY%%MM%%DD%<br \/>\nset timestamp=%HH%%Min%%Sec%<br \/>\nset fullstamp=%YYYY%-%MM%-%DD%_%HH%-%Min%-%Sec%<\/p>\n<p>ren &#8220;bindings.txt&#8221; &#8220;bindings &#8211; %fullstamp%.txt&#8221;<br \/>\npowershell -command &#8220;Start-Sleep -s 5<br \/>\ngoto loop<\/p>\n<p><strong>BATCH FILE CONTENTS &#8211; RETENTION PERIOD OF 3 DAYS<\/strong><br \/>\n@echo off<br \/>\n:loop<br \/>\npowershell -command &#8220;Start-Sleep -s 259200<br \/>\ndel bindings*.*<br \/>\ngoto loop<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This recipe describes a simple method to send DHCP bindings from a Cisco router to a remote TFTP server running on Windows. \u00a0A batch file renanes and date-stamps the file and another batch file removes the archived files after a retention period: EEM SCRIPT ON CISCO\u00a0ROUTER: (Note: the cron entry sends the file every 5 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[83,67],"tags":[],"_links":{"self":[{"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2223"}],"collection":[{"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2223"}],"version-history":[{"count":5,"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2223\/revisions"}],"predecessor-version":[{"id":2231,"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2223\/revisions\/2231"}],"wp:attachment":[{"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2223"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2223"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2223"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}