At what capacity do you script?
Just a feeler question/skills check. For those more exposed to networking than systems, at what capacity do you do any python/perl/bash scripting? What sort of tasks do you script for?
Comments
-
shodown Member Posts: 2,271when you have 500 devices to configure and they are all the same.Currently Reading
CUCM SRND 9x/10, UCCX SRND 10x, QOS SRND, SIP Trunking Guide, anything contact center related -
astorrs Member Posts: 3,139 ■■■■■■□□□□- When it's a task that's going to be repeated again and again (especially if performed by different people) to ensure it's always done the same way
- When the time to script it is <= the time to do it manually -
phoeneous Member Posts: 2,333 ■■■■■■■□□□I guess I should've asked, how much do you script on a daily basis? Thats what I meant by capacity.
-
fiftyo Member Posts: 71 ■■□□□□□□□□I guess I should've asked, how much do you script on a daily basis? Thats what I meant by capacity.
-
onesaint Member Posts: 801Our network engineers do little to no scripting and are very Windows friendly. We on the systems side end up scripting everything and have a very good grasp of the network.
The smartest network engineers I know can script just as well as I can as a Linux Admin (Python / Perl, Bash, etc.). Those folks are worth their weight in gold and are paid accordingly.
ETA: scripting is called for when repetitive tasks are found. That can happen as little as once a week or as often as daily. I think the answer is largely dependant on the engineer's scripting ability and the demand within the network. Or how lazy the person is!Work in progress: picking up Postgres, elastisearch, redis, Cloudera, & AWS.
Next up: eventually the RHCE and to start blogging again.
Control Protocol; my blog of exam notes and IT randomness -
fiftyo Member Posts: 71 ■■□□□□□□□□Can you post a few examples?
cat <file with switchnames>| while read line; do <ssh script for auto login> -c "show <insert what to show>" >> $line.log; done
or if you configure you'd need to shoot multiple commands in most cases;
while read line; do <ssh script> <<EOF;configure; set <w/e>;EOF;done <file with names
can also be done via
while read line; do <ssh script> -c "configure; set <w/e>;";done <file with names
In this case I'm pretty luck and already have files with name of all the switches, however seeing it's both outofband and inband switches you have to edit them with awk/sed. SSH script is done by expect.
It's early in the morning and written by hand so there might be some errors
As of right now I'm trying to learn python. -
phoeneous Member Posts: 2,333 ■■■■■■■□□□Im starting to play around with bash scripts for use with the net-snmp library. I did a lot of vb in college so at least some of the underlying concepts are the same i.e. loops, variables, etc..
-
veritas_libertas Member Posts: 5,746 ■■■■■■■■■■I started studying Powershell yesterday. Cool stuff. After that I'm going to start on Python.
http://cli.learncodethehardway.org/book/
-
moreland11 Member Posts: 24 ■□□□□□□□□□Can someone send me a link on the scripting used with Cisco Switches ?? I'm very interested in this. I've had some experience on the server side with powershell,vbs, and batch files. Speeding up the process of finding popped ports or a mac address on switch would be great. Also I often have to change port configs from one access vlan to another and setup voice vlan with priority. Thanks!!
-
lsud00d Member Posts: 1,571veritas_libertas wrote: »I started studying Powershell yesterday. Cool stuff. After that I'm going to start on Python.
http://cli.learncodethehardway.org/book/
I like how Powershell commands are aliased to linux commands (MS did something right!), but those dern cmdlets are a bore :yawn: -
ptilsen Member Posts: 2,835 ■■■■■■■■■■Just to chime in, Cmdlets are no bore if you're working primarily in a Windows-centric role. Cmdlets have saved me a lot of time compared to writing equivalent commands in batch or vbscript or using GUI tools. It's literally five times as much work at a minimum to do a shell or WMI call in vbscript than to use a cmdlet that's designed to do what you need the call for in vbscript, and cmdlets cover about 75% of what you would do (maybe 80% in 3.0). Easier, simpler syntax and clearer debugging means almost everything is faster to write. Of the major changes in PowerShell, aliasing to Linux commands is probably the least interesting or important for anyone not from a Linux background. Even for people from a Linux background, it's not like BASH really translates to PowerShell. A few simple commands are aliased, but the platforms are still very different.
Anyway, as far as scripted network device configuration goes, I would probably use PowerShell if using Windows and Python if not, or just Python if I didn't know PowerShell. Bash would be a third choice.
Astorr's answer is the best pretty much regardless of the context of the question. Whether it's systems or networking, those are about the only criteria to consider. -
amb1s1 Member Posts: 408I do script on the daily basic using python. I used it for creating reports. Let say that we want to know if we have the standard IOS on all of our switches (more than 1k switches). I do a python script that will go and ssh into each device and will grab the IOS version and save all that info in an spreadsheet. Also, if we have a project, I create a pre and post script to audit everything that was touch. Is pretty cool especially when you work on a big company, you see different department fighting for your time.
-
veritas_libertas Member Posts: 5,746 ■■■■■■■■■■@amb1s1: Very cool. I would be interested in seeing the scripts.
-
amb1s1 Member Posts: 408I would post later on. I use couple of python module. I started learning python like just 6 month ago. I'm now working on making my scripts look better because my scripts work, bu they are ugly. I just need more experience.
-
NetworkVeteran Member Posts: 2,338 ■■■■■■■■□□Rarely. If it's about automating a repetitive task, there's usually someone I can delegate it to, and have it done tomorrow. I am glad I have expert scripting skills, so I know when it can help, for when I need it now, and so I can check those engineers' work!Or how lazy the person is!
-
amb1s1 Member Posts: 408I uploaded the code with all the files needed to my github:
https://github.com/amb1s1/config_pull
Here is the code of the main script, but is better if you download the script from github because there is more files that it needs and the format get messup in here:
I also put the code on my blog: ipnet.tumblr.com#!/usr/bin/python # Version 1.0 import os,sys,string sys.path.append('/home/user/python/lib/lib/python') import pexpect import xlwt import credential os.system('rm Devices_Config_Pull.xls') #This will remove previews created spreadsheet os.system('rm Devices_Config_Pull.zip') #This will remove previews created zip list_devices=open('list.txt').readlines() #This will read the list of devices that file is on the same location as the script email, UID, passwd, enable = credential.cred() #This is a module that I created that will store all of credential connection = sys.argv[1] connection = int(connection) ### If the argument is 1 it will telnet into the devices if the argument is 2 it will ssh into the devices if connection == 1: tunnel = 'telnet ' conmess = 'telnet' elif connection == 2: tunnel = ('ssh -o StrictHostKeyChecking=no -l ' + UID + ' ') conmess = 'SSH' ######## This for loop block. is the loop for telnet/ssh into the devices wbk = xlwt.Workbook() #Create an excel workbook font = xlwt.Font() font.bold = True style = xlwt.XFStyle() style.font = font for i in list_devices: rowHostname = 0 rowIp = 1 rowTittle = 2 rowOutput = 4 col1 = 0 IP = "" IP2 = "" x = i.strip().split() if len(x) == 2: r = 0 else: r =1 while r<3: if r == 1: hostname, IP,IP2 = i.strip().split() print r print IP print IP2 print hostname sheet = wbk.add_sheet(hostname) f_write = file (hostname+'_Device_1.txt','wb') sheet.write(rowHostname,0,hostname+"_Device_1", style) sheet.write(rowIp,0,"IP: "+IP, style) sheet.write(rowTittle,0,"Config", style) elif r == 2: IP = IP2 col1 = 1 sheet.write(rowHostname,1,hostname+"_Device_2", style) f_write = file (hostname+'_Device_2.txt','wb') sheet.write(rowIp,1,"IP: "+IP, style) sheet.write(rowTittle,1,"Config", style) elif r == 0: hostname, IP = i.strip().split() print r print IP print IP2 print hostname sheet = wbk.add_sheet(hostname) f_write = file (hostname+'_Device_1.txt','wb') sheet.write(rowHostname,0,hostname+"_Device_1", style) sheet.write(rowIp,0,"IP: "+IP, style) sheet.write(rowTittle,0,"Config", style) r=3 r+=1 print "connecting to " + IP +" " +hostname print 'trying to ' + conmess +' ' + IP child = pexpect.spawn(tunnel + IP) m = child.expect (['assword:','[Ll]ogin:','[Uu]sername',pexpect.TIMEOUT,pexpect.EOF]) if m==0: child.sendline(passwd) elif m==1: child.sendline(UID) elif m==2: child.sendline(UID) elif m==3: print "login error" continue elif m==4: print "no login prompt error" continue q = child.expect (['>','[Pp]assword',pexpect.TIMEOUT,pexpect.EOF]) if q==0: child.sendline ('ena') elif q==1: child.sendline (passwd) elif q==2: print "wrong password or wait too long for prompt" sheet.write(rowOutput,col1,'Wrong Password') rowOutput+=1 continue elif q==3: sheet.write(rowOutput,col1,'Prompt Timeouts') rowOutput+=1 continue q = child.expect (['assword:','>',pexpect.TIMEOUT,pexpect.EOF]) if q==0: child.sendline (enable) elif q==1: child.sendline ('enable') elif q==2: sheet.write(rowOutput,col1,'Wrong Password') rowOutput+=1 continue elif q==3: sheet.write(rowOutput,col1,'Prompt Timeout') rowOutput+=1 continue q = child.expect (['>','[Pp]assword',pexpect.TIMEOUT,pexpect.EOF, '#']) if q==0: child.sendline ('ena') elif q==1: child.sendline (enable) elif q==2: sheet.write(rowOutput,col1,'Wrong Password') rowOutput+=1 continue elif q==3: sheet.write(rowOutput,col1,'Prompt Timeout') rowOutput+=1 continue elif q==4: child.sendline(' ') q = child.expect (['>','[Pp]assword',pexpect.TIMEOUT,pexpect.EOF, '#']) if q==0: sheet.write(rowOutput,col1,'Wrong Enable Password') rowOutput+=1 continue elif q==1: sheet.write(rowOutput,col1,'Wrong Enable Password') rowOutput+=1 continue elif q==2: sheet.write(rowOutput,col1,'Wrong Password') rowOutput+=1 continue elif q==3: sheet.write(rowOutput,col1,'Prompt Timeout') rowOutput+=1 continue elif q==4: child.sendline(' ') print 'Im OK' child.expect('#') child.sendline ('show run | in hostname') #For grabbing the device histname child.expect('#') host=child.before join =host.split(" ") host = join[5] join1=host.splitlines() host = join1[0] child.sendline ('term len 0') print 'pass term' # This is the end of the process to ssh/telnet into the devices #Here start to grab the show run information command = 'sh run' q = child.expect ([host+'#',pexpect.TIMEOUT,pexpect.EOF]) if q==0: child.logfile_read = f_write child.sendline (command) elif q==1: print "command not working " + i continue elif q==2: print "command not working" + i continue command = 'show clock' q = child.expect ([host+'#',pexpect.TIMEOUT,pexpect.EOF]) if q==0: config = child.before config = config.split("\n") rowOutput = 4 for i in config: sheet.write(rowOutput,col1,i) rowOutput+=1 child.sendline (command) elif q==1: print "command not working " + i continue elif q==2: print "command not working" + i continue child.expect('#') f_write.close() child.sendline('exit') sheet.col(0).width = 6000 sheet.col(1).width = 6000 wbk.save('Devices_Config_Pull.xls') #Saving the spreadsheet os.system('zip Devices_Config_Pull Devices_Config_Pull.xls') #Send this command to the OS, in my case I use linux os.system('uuencode Devices_Config_Pull.zip Devices_Config_Pull.zip | mailx -s "Devices Configs - Spreadsheet" ' +email) #Again using the OS Command to send an email with an attachemt print ('Sending the zip file to ' +email+'.Please check your email in couple of minutes')
-
veritas_libertas Member Posts: 5,746 ■■■■■■■■■■Thanks for posting that. Is anyone familiar with TCL scripting for Cisco? I wasn't aware of this until I was googling today:
Cisco IOS Scripting with TCL Configuration Guide, Cisco IOS Release 12.4T - Cisco IOS Scripting with Tcl [Support] - Cisco Systems
Amazon.com: TcL Scripting for Cisco IOS (Networking Technology) (9781587059452): Raymond Blair, Arvind Durai, John Lautmann: Books
http://www.cisco.com/en/US/docs/ios-xml/ios/ios_tcl/configuration/15-sy/ios-tcl-15-sy-book.pdf -
networker050184 Mod Posts: 11,962 ModYeah I've seen a bit of TCL used in the real world. Junos scripts are pretty cool on the Juniper side as well.An expert is a man who has made all the mistakes which can be made.