Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Notices

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 02-08-2012, 08:52 AM
mybox65 mybox65 is offline
Registered User
 
Join Date: Feb 2012
Posts: 17
Red face interface configuration by script

In our company there are more than 300 cisco switchs. I would like to use secureCRT to telnet and manage them. I already know how to creat a script for the telnet connection, but I donot know how to config the following things. <I do appreciate your help!! >


1, Distinguish the type of interface (for example there are two type of interface in the switch ,FastEthernet,GigabitEthernet )


2, Due to each interface has unique configuration , I have to detect whether there is the "switchport port-security" under the interface. if it is, the script will put one more command line under the interface. for example I just want to add "switch voice vlan 111" , once the Script detects there are "switchport port-security " words under the interface. Otherwise, add noting



!
interface FastEthernet0/8
switchport access vlan 60
switchport mode access
switchport port-security
switchport voice vlan 111 -->add
srr-queue bandwidth share 10 10 60 20
srr-queue bandwidth shape 10 0 0 0
mls qos trust device cisco-phone
mls qos trust cos
auto qos voip cisco-phone
macro description cisco-phone
spanning-tree portfast
!

!
interface FastEthernet0/1 --->there r no "switchport port-security",so add nothing
switchport access vlan 60
switchport mode access
srr-queue bandwidth share 10 10 60 20
srr-queue bandwidth shape 10 0 0 0
mls qos trust device cisco-phone
mls qos trust cos
auto qos voip cisco-phone
spanning-tree portfast
!


!
interface GigabitEthernet0/1
switchport trunk encapsulation dot1q
switchport mode trunk
switchport port-security
srr-queue bandwidth share 10 10 60 20
srr-queue bandwidth shape 10 0 0 0
queue-set 2
mls qos trust cos
auto qos voip trust
spanning-tree link-type point-to-point
!

Last edited by mybox65; 02-08-2012 at 02:10 PM.
Reply With Quote
  #2  
Old 02-08-2012, 11:51 AM
miked's Avatar
miked miked is offline
Registered User
 
Join Date: Feb 2004
Posts: 2,040
Hello,

It sounds like you'll want to capture data, then work on the data later. For example, after capturing a data chunk you can search for Gigabit (task 1), and search for switchport port-security (task 2). You may even need the data later, to add "switch voice vlan 111".

Does the data that's returned look like what you typed, with the '!' characters delimiting the beginning and end of the data?
__________________
Mike
VanDyke Software
Technical Support
[http://www.vandyke.com/support]
Reply With Quote
  #3  
Old 02-09-2012, 07:08 AM
mybox65 mybox65 is offline
Registered User
 
Join Date: Feb 2012
Posts: 17
yes, firstly I let other Script send "show running-config" command to the switch and capture the Configuration to a file.

And then ,try to use script detects the name of interface is Gigabitethernet, although there is the "switchport port-security" under the Gigabitethernet interface, I won't add "switchport voice vlan 111" under it, Unless the interface is FastEthernet;

And the data that's returned look like what I typed, with the '!' characters delimiting the beginning and end of configuration of each interface.
Reply With Quote
  #4  
Old 02-09-2012, 10:53 AM
miked's Avatar
miked miked is offline
Registered User
 
Join Date: Feb 2004
Posts: 2,040
It sounds like you currently have a SecureCRT script which extracts all of the switches' running configurations into a file, or files, and now you'd like assistance creating a new script to read and modify the files?
__________________
Mike
VanDyke Software
Technical Support
[http://www.vandyke.com/support]
Reply With Quote
  #5  
Old 02-09-2012, 11:24 AM
mybox65 mybox65 is offline
Registered User
 
Join Date: Feb 2012
Posts: 17
It sounds like you currently have a SecureCRT script which extracts all of the switches' running configurations into a file, or files, and now you'd like assistance creating a new script to read and modify the files?

Yes, I have already created a script (pls,see attachment) to extracts switches's running configuration to files (file's name is switch's ip address). And Please help me to creat a new script to read and modify the configuration of switch interface in files.
Attached Files
File Type: zip Backup of switch configuration.zip (729 Bytes, 520 views)
Reply With Quote
  #6  
Old 02-09-2012, 02:14 PM
miked's Avatar
miked miked is offline
Registered User
 
Join Date: Feb 2004
Posts: 2,040
Parsing and manipulating data in a file is a little bit outside the scope of a SecureCRT support question. However, we may be able to provide some suggestions. If any forum readers already have an example they'd be able to share, it would be welcome!

I believe your question revolves around the best way to parse the block of data. Depending on your comfort level with VBScript, you might try using a VBScript Dictionary object. It sounds like your decision tree depends on name the interface value because you said you
Quote:
I won't add "switchport voice vlan 111" under it, Unless the interface is FastEthernet
. One advantage of using a dictionary is that you can easily set the key and value pair, which makes data lookup a little easier.
__________________
Mike
VanDyke Software
Technical Support
[http://www.vandyke.com/support]
Reply With Quote
  #7  
Old 02-09-2012, 08:10 PM
mybox65 mybox65 is offline
Registered User
 
Join Date: Feb 2012
Posts: 17
I checked the VBScript dictionary, but I still do not know how to use it. I am trying to do my best to use my lanuage to describute what I think about the script. I sincerely appreciate you , if you can assist me to consummate it.




a1= crt.Screen.ReadString("!") ----> just one '!' character delimiting the beginning and end of the data
a2= crt.Screen.ReadString("interface FastEthernet") ---> it is the Second dlimiting character
a3 = crt.Screen.ReadString("interface GigabitEthernet")

reading file form c:\switch.txt


step1

pre-read two row (a1 , a2/3)
If the Script detects a1 & a2 =true , go to step2
If the Script detects a1 & a3 =true , go to step3
otherwise exit

Do
step2

if crt.Screen.CurrentRow doesn't include "switchport port-security" go to search Next row, until a1 & a2 =true or a1 & a3 =true or "#" --->a1&a2 or a1&a3 are delimiting of beginning of next data chunk

if crt.screen.CurrentRow inclde "switchport port-security" , add "switchport voice vlan 111" ---> the sequence of row could be not in order


step3
if crt.Screen.CurrentRow include "switchport port-security" , delete it , then go to search Next row, until a1 & a3 =true or a1 & a3 =true or "#"


Loop

Last edited by mybox65; 02-09-2012 at 08:12 PM.
Reply With Quote
  #8  
Old 02-10-2012, 02:23 PM
miked's Avatar
miked miked is offline
Registered User
 
Join Date: Feb 2004
Posts: 2,040
Once the information has been saved to the external file, the operations you'll need to perform aren't really crt.Screen.ReadString, or anything else like that. You'll want a VBScript that reads in a text file and parses data. Whether you use a dictionary, an array, or some other method is a matter of choice and whatever you're comfortable with.

Here are two different ways you might get started. It shows how to read everything into an array. It also shows how to read data into a dictionary. I'd recommend getting that part working. You could probably take either example and morph it to what you need.

After reading data into the array or dictionary you might use the VBScript function InStr to help detect whther the data you're looking for is in a particular line. You could also add data to the array or dictionary.

Once all of that is done, then you can return to SecureCRT and start writing the file (crt.Screen.Send lines from the array or dictionary).
__________________
Mike
VanDyke Software
Technical Support
[http://www.vandyke.com/support]
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 12:41 AM.