{"id":86,"date":"2017-03-20T19:05:54","date_gmt":"2017-03-20T17:05:54","guid":{"rendered":"http:\/\/developer.ps\/?p=86"},"modified":"2017-03-21T09:05:08","modified_gmt":"2017-03-21T07:05:08","slug":"a-python-script-to-backup-cisco-routers-and-switches","status":"publish","type":"post","link":"https:\/\/developer.ps\/index.php\/2017\/03\/20\/a-python-script-to-backup-cisco-routers-and-switches\/","title":{"rendered":"A Python Script to Backup Cisco Routers and Switches"},"content":{"rendered":"#!\/usr\/bin\/python\r\n\r\nimport pexpect,sys,string,os,time,subprocess,getpass\r\n\r\nif len(sys.argv) !=2:\r\nprint (\"usage: backup [user@]hostname\")\r\nelse:\r\ninput_data = sys.argv[1]\r\ndata=input_data.split(\"@\")\r\nswitch_un = data[0]\r\nswitch_ip = data[1]\r\nswitch_pw1 = getpass.getpass(\"Enable Password:\")\r\nswitch_pw2 = getpass.getpass(\"Privilege Password:\")\r\nbasic_backup_directory = \"\/tmp\/Network_Backups\"\r\nprint (\"Please wait ...\")\r\n\r\ntry:\r\ntry:\r\nchild = pexpect.spawn('ssh %s@%s' % (switch_un, switch_ip))\r\nchild.timeout <a href=\"https:\/\/developer.ps\/index.php\/2017\/03\/20\/a-python-script-to-backup-cisco-routers-and-switches\/\" class=\"more-link\">Read more [...]<\/a>","protected":false},"excerpt":{"rendered":"<p>#!\/usr\/bin\/python import pexpect,sys,string,os,time,subprocess,getpass if len(sys.argv) !=2: print (&#8220;usage: backup [user@]hostname&#8221;) else: input_data = sys.argv[1] data=input_data.split(&#8220;@&#8221;) switch_un = data[0] switch_ip = data[1] switch_pw1 = getpass.getpass(&#8220;Enable Password:&#8221;) switch_pw2 = getpass.getpass(&#8220;Privilege Password:&#8221;) basic_backup_directory = &#8220;\/tmp\/Network_Backups&#8221; print (&#8220;Please wait &#8230;&#8221;) try: try: child = pexpect.spawn(&#8216;ssh %s@%s&#8217; % (switch_un, switch_ip)) child.timeout Read more [&#8230;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[8,7,11],"tags":[],"class_list":["post-86","post","type-post","status-publish","format-standard","hentry","category-cisco","category-networking","category-python"],"wps_subtitle":"Backup Cisco Routers and Switches ","_links":{"self":[{"href":"https:\/\/developer.ps\/index.php\/wp-json\/wp\/v2\/posts\/86","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/developer.ps\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/developer.ps\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/developer.ps\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/developer.ps\/index.php\/wp-json\/wp\/v2\/comments?post=86"}],"version-history":[{"count":2,"href":"https:\/\/developer.ps\/index.php\/wp-json\/wp\/v2\/posts\/86\/revisions"}],"predecessor-version":[{"id":94,"href":"https:\/\/developer.ps\/index.php\/wp-json\/wp\/v2\/posts\/86\/revisions\/94"}],"wp:attachment":[{"href":"https:\/\/developer.ps\/index.php\/wp-json\/wp\/v2\/media?parent=86"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/developer.ps\/index.php\/wp-json\/wp\/v2\/categories?post=86"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/developer.ps\/index.php\/wp-json\/wp\/v2\/tags?post=86"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}