Powershell Script to backup 2960 Stack Full Configuration
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2018 03:11 AM - edited 03-05-2019 10:54 AM
Hello ,
Im looking for a powershell script to backup my 2960 switch Stack configuration .
I prefer follow a bestpractices.
Regards,
- Labels:
-
LAN Switching
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2018 05:39 AM
Powershell ... really? :) I prefer using Python but .. anyhow have a look at this post.
https://www.sherweb.com/blog/fun-with-powershell-plink-cisco-ios-and-powershell/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2018 07:39 AM
I think PS is complicated here .could you let me know how with perl please ?
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2018 10:58 AM - edited 09-05-2018 10:59 AM
Sorry, I don't know perl :)
**BANTER Start** showing your age ;) **BANTER End**
But have look here -
https://thwack.solarwinds.com/thread/19748
If you fancy giving Python a go.
Prerequisites:
- Install Python 2.7, Paramiko and getpass
import paramiko import time import getpass import os import sys #IP = '1.1.1.2' #USER = raw_input("Username : ") #PASS = getpass.getpass("Password : ") #ENABLE = getpass.getpass("Enable : ") # ONLY FOR TESTING HARD CODE. UNCOMMENT ABOVE AND DELETE BELOW AFTER TESTING IP = '1.1.1.2' USER = 'cisco' PASS = 'cisco123' ENABLE = 'cisco123' ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(IP, port=22, username=USER, password=PASS, look_for_keys=False,allow_agent=False) remote = ssh.invoke_shell() remote.send('term len 0\n') remote.send('enable\n') remote.send('%s\n' % ENABLE) time.sleep(1) remote.send('sh run\n') time.sleep(10) output = remote.recv(65000) print output timestr = time.strftime("%Y%m%d-%H%M") with open('{}-{}.txt'.format(IP, timestr), 'a') as config: config.write(output)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2018 12:41 AM - edited 09-06-2018 12:43 AM
Just for your info you may want to look at Netmiko (written by the same guy) which uses Paramiko but takes out some of the lower level stuff for managing network devices.
So your code in Netmiko would be -
from netmiko import ConnectHandler
swp = ConnectHandler(device_type='cisco_ios', ip=IP, username=USER, password=PASS, secret=ENABLE)
swp.enable()
output = swp.send_command('sh run')
print output
Jon
