07-18-2016 03:10 PM - edited 03-01-2019 04:59 AM
Hi,
in my DC environment, I have two 7k, connected to 5k. 5k is further connected to 2k as top of rack switch. each 5k has 10 FEX connected to it.
with VM ESXi build up project, we have to configure lot of FEX ports every day. just as trunk port. sample config is like this
conf t
int Eth101/1/1
spanning-tree port type edge
desc Connect to ESXi
switchport access vlan 10
no shut
I would like to perform this work with scripting. either using Python or Perl. my switch IOS is 5.1 kickstart version.
Can someone suggest how to do scripting for this so that script will run from a Linux box, ssh to the 5548 switch, run these commands, check for output after running the commands, and send it in notepad file as email to me.
check commands are like
sh int Eth101/1/1
sh int trunk
etc
your help is greatly appreciated.
Thanks
07-22-2016 10:15 AM
is there anyone in this forum can advise where I should find related material for my question posted above?
your help is greatly appreciated.
Thanks in advance !!
01-31-2017 05:04 AM
Hi,
Create a script in Windows with .vbs extension.
Then insert the following into the script below.
This works fine with Telnet, I tested it.
Unfortunately I have not figured out yet how to use it with ssh.
I've installed putty's plink.exe and it does login to the switch via ssh, but some characters gets mixed up on the fly, so for example the enable password part does not work.
I'll update this when I figured out how to use it.
####
set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "cmd"
WScript.Sleep 100
WshShell.AppActivate "C:\Windows\system32\cmd.exe"
WScript.Sleep 300
WshShell.SendKeys "telnet 10.0.1.10{ENTER}"
WScript.Sleep 300
WshShell.SendKeys "username"
WshShell.SendKeys "{ENTER}"
WScript.Sleep 300
WshShell.SendKeys "password"
WshShell.SendKeys "{ENTER}"
WScript.Sleep 300
WshShell.SendKeys "enable"
WshShell.SendKeys "{ENTER}"
WScript.Sleep 300
WshShell.SendKeys "password"
WshShell.SendKeys "{ENTER}"
WScript.Sleep 300
WshShell.SendKeys "configure terminal"
WshShell.SendKeys "{ENTER}"
WScript.Sleep 300
WshShell.SendKeys "interface fastethernet0/17"
WshShell.SendKeys "{ENTER}"
WScript.Sleep 300
WshShell.SendKeys "no shutdown"
WshShell.SendKeys "{ENTER}"
WScript.Sleep 300
WshShell.SendKeys "end"
####
01-31-2017 07:44 AM
HI Jigar,
I suspect this is way too late to be of use to you but thought I would toss it out in any case. I would urge you to look at the Netmiko module for python. Its a module by Kirk Byers based on the paramiko module with many "efficiencies" built it which makes it ideal for just what you are trying to do.
https://pynet.twb-tech.com/blog/automation/netmiko.html
The code excerpt below shows trying to log in, then trying to go into enable mode, then sending a command set which could very easily be your interface config snippet.
Hope this helps! Lots more good info on Kirk's Pynet site.
from netmiko import ConnectHandler
from netmiko import NetMikoAuthenticationException
from netmiko.ssh_exception import NetMikoTimeoutException
from paramiko.ssh_exception import SSHException
import sys
import getpass
try:
dev_conn = ConnectHandler(device_type=device_cls, ip=ip_addr, username=uname, password=upwd, secret=epwd)
login_success = True
except NetMikoAuthenticationException:
print "NetMikoAuthenticationException: Device failed to enter enable mode."
login_success = False
except (EOFError, SSHException, NetMikoTimeoutException):
print('SSH is not enabled for this device.')
login_success = False
except Exception, e:
print "General Exception: ERROR!:" + str(sys.exc_info()[0]) + "==>" + str(sys.exc_info()[1])
print str(e)
login_success = False
if login_success:
try:
dev_conn.enable()
enable_success = True
except Exception, e:
print str(e)
print "Cannot enter enter enable mode on device!"
enable_success = False
if enable_success:
output = dev_conn.send_config_set(commands)
dev_conn.exit_config_mode()
dev_conn.disconnect()
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide