VanDyke Software Forums

VanDyke Software Forums (https://forums.vandyke.com/index.php)
-   Scripting (https://forums.vandyke.com/forumdisplay.php?f=14)
-   -   Cisco Switch Port is Skipped (https://forums.vandyke.com/showthread.php?t=13091)

Blackeee 04-19-2018 01:19 PM

Cisco Switch Port is Skipped
 
My project is tailored specifically to cisco switches. Once in a switch im having my Vbscript show the status of all interfaces then allowing me to mass send a command to all that is labled to a specific vlan.

The only issue i am having is for whatever reason no matter the size of the switch it will always skip interface 12. There are no configuration differences between these ports also.

Please help me locate this bug.

Code:

#$language = "VBScript"
#$interface = "1.0"


Sub Main()


    crt.Screen.Synchronous = True
    crt.Screen.Send "sh int statu" & chr(13) & vbcr
    crt.Screen.WaitForString vbcr
    strCompleteOutput = ""
   
    count = 0
    Do
        crt.Screen.Send " "
        if count = 20 then exit do
        count = count + 1
    Loop

    strResult = crt.Screen.ReadString("#")
    strCompleteOutput = strCompleteOutput & strResult


    Do
        filterInput = InputBox("Type the VLAN ID you want to use to filter interfaces. Leave blank to include all.", "Filter Interfaces")
        cmdInput = InputBox("Type the command you want to run on all interfaces identified by the text filter.", "Enter Command")
        userCheck = MsgBox("You want to run '" + cmdInput + "' on all interfaces that contain '" + filterInput + "'. Is this correct?",3,"Verify")
        If userCheck = 2 Then
            Exit Sub
        ElseIf userCheck = 6 Then
            Exit Do
        End If
    Loop

    strCompleteOutput = Replace(strCompleteOutput, _
        vblf & vbcr & vbcr & " " & vbcr, vblf & vbcr)

    arrLines = Split(strCompleteOutput, vbCrLf)

    listBuffer = "int range "
    bufferCount = 0
    output = "config t" + chr(13)
    For Each line In arrLines
        If Left(line,2) = "Gi" Or Left(line,2) = "Fa" Then
            If InStr(1,line," " + filterInput + " ",1) Then
                splitLine = Split(line)
                If bufferCount = 0 Then
                    listBuffer = listBuffer + splitLine(0)
                ElseIf bufferCount < 5 Then
                    listBuffer = listBuffer + "," + splitLine(0)
                ElseIf bufferCount = 5 Then
                    output = output + listBuffer + chr(13) + cmdInput + chr(13)
                    listBuffer = "int range " + splitLine(0)
                    bufferCount = 0
                End If
                bufferCount = bufferCount + 1
            End If
        End If
    Next
   
    If bufferCount <> 0 Then
        output = output + listBuffer + chr(13) + cmdInput + chr(13) + "end" + chr(13)
    End If
   



'MsgBox output

crt.Screen.Send output

End Sub


########################

##### Typical Output #####
Code:

Switch#sh int statu

Port      Name              Status      Vlan      Duplex  Speed Type
Gi3/0/1                      notconnect  210          auto  auto 10/100/1000BaseTX
Gi3/0/2                      notconnect  210          auto  auto 10/100/1000BaseTX
Gi3/0/3                      notconnect  210          auto  auto 10/100/1000BaseTX
Gi3/0/4                      notconnect  210          auto  auto 10/100/1000BaseTX
Gi3/0/5                      notconnect  210          auto  auto 10/100/1000BaseTX
Gi3/0/6                      notconnect  210          auto  auto 10/100/1000BaseTX
Gi3/0/7                      notconnect  210          auto  auto 10/100/1000BaseTX
Gi3/0/8                      notconnect  210          auto  auto 10/100/1000BaseTX
Gi3/0/9                      notconnect  210          auto  auto 10/100/1000BaseTX
Gi3/0/10                    notconnect  210          auto  auto 10/100/1000BaseTX
Gi3/0/11                    notconnect  210          auto  auto 10/100/1000BaseTX
Gi3/0/12                    notconnect  210          auto  auto 10/100/1000BaseTX
         
Port      Name              Status      Vlan      Duplex  Speed Type
Gi3/0/13                    notconnect  210          auto  auto 10/100/1000BaseTX
Gi3/0/14                    notconnect  210          auto  auto 10/100/1000BaseTX
Gi3/0/15                    notconnect  210          auto  auto 10/100/1000BaseTX
Gi3/0/16                    notconnect  210          auto  auto 10/100/1000BaseTX
Gi3/0/17                    notconnect  210          auto  auto 10/100/1000BaseTX
Gi3/0/18                    notconnect  210          auto  auto 10/100/1000BaseTX
Gi3/0/19                    notconnect  210          auto  auto 10/100/1000BaseTX
Gi3/0/20                    notconnect  210          auto  auto 10/100/1000BaseTX
Gi3/0/21                    notconnect  210          auto  auto 10/100/1000BaseTX
Gi3/0/22                    notconnect  210          auto  auto 10/100/1000BaseTX
Gi3/0/23                    notconnect  210          auto  auto 10/100/1000BaseTX
Gi3/0/24                    notconnect  210          auto  auto 10/100/1000BaseTX
         
Port      Name              Status      Vlan      Duplex  Speed Type
Po1      CAN120            notconnect  trunk        auto  auto
Switch#                  config t
Enter configuration commands, one per line.  End with CNTL/Z.
Switch(config)#int range Gi3/0/1,Gi3/0/2,Gi3/0/3,Gi3/0/4,Gi3/0/5
Switch(config-if-range)#shut
Switch(config-if-range)#$i3/0/6,Gi3/0/7,Gi3/0/8,Gi3/0/9,Gi3/0/10     
Switch(config-if-range)#shut
Switch(config-if-range)#$i3/0/11,Gi3/0/13,Gi3/0/14,Gi3/0/15,Gi3/0/16 
Switch(config-if-range)#shut
Switch(config-if-range)#$i3/0/17,Gi3/0/18,Gi3/0/19,Gi3/0/20,Gi3/0/21 
Switch(config-if-range)#shut
Switch(config-if-range)#int range Gi3/0/22,Gi3/0/23,Gi3/0/24
Switch(config-if-range)#shut
Switch(config-if-range)#end
Switch#


ekoranyi 04-19-2018 02:29 PM

Hi Blackeee,

I haven't been able to identify the specific "bug" that you're seeing just yet. There are some scripting guidelines that we should address and I'll need a little additional information before we can get to the bottom of the issue.

In reviewing the code I noticed that the line:

Code:

crt.Screen.Send "sh int statu" & chr(13) & vbcr
is sending two carriage returns. Generally when Synchronous is set to true we need to do one send with one carriage return followed by a WaitForString. Are you intentionally sending two returns? Would removing the chr(13) be an option?

The next block of code I have questions about is:

Code:

    count = 0
    Do
        crt.Screen.Send " "
        if count = 20 then exit do
        count = count + 1
    Loop

Why are you sending 20 spaces to the remote? Is this in an effort to handle the device needing a button press to show more data? If so, have you considered turning off paging on the device to simply the process?

I am also not clear on what the following code does.
Code:

    strCompleteOutput = Replace(strCompleteOutput, _
    vblf & vbcr & vbcr & " " & vbcr, vblf & vbcr)

If the behavior of the script does not improve by removing the duplicate carriage return on your first send we may need a more detailed, Raw, log. This will help me get a better idea of what exactly the remote is sending. This may help illustrate why you need to do the replace on strCompleteOutput.

bstedh 05-01-2018 02:24 PM

I think one of the big issue you may be having is you are sending your output to the router in one big burst. You should separate your commands and wait for router prompts before sending the next command.

I re-wrote what you provided a bit and set it up interface by interface instead of with ranges. This should make it easy to see when and where there are any issues. I have not tested the code so there may be some errors in it but it should give you an idea of what I am talking about.

You can modify the end of the script to work with ranges instead. Just make sure you send your commands one at a time and wait for the router prompt before sending the next.

Code:

    crt.Screen.Synchronous = True
    crt.Screen.Send "set term len 0" & vbCr 'scroll output without breaks.
    crt.Screen.WaitForString "#" 'Router en prompt
    crt.Screen.Send "sh int statu" & vbcr
    strCompleteOutput = crt.Screen.ReadString ("#")
    crt.Screen.Send "set term len 48" & vbCr
    crt.Screen.WaitForString "#"
   
    Do
        filterInput = InputBox("Type the VLAN ID you want to use to filter interfaces. Leave blank to include all.", "Filter Interfaces")
        cmdInput = InputBox("Type the command you want to run on all interfaces identified by the text filter.", "Enter Command")
        userCheck = MsgBox("You want to run '" + cmdInput + "' on all interfaces that contain '" + filterInput + "'. Is this correct?",3,"Verify")
        If userCheck = 2 Then
            Exit Sub
        ElseIf userCheck = 6 Then
            Exit Do
        End If
    Loop
       
        strCompleteOutput = Trim(strCompleteOutput)
        Do While InStr(1,strCompleteOutput,"  ") > 0
            strCompleteOutput = Replace(strCompleteOutput,"  "," ")
    Loop

    arrLines = Split(strCompleteOutput,VbCr)

    filterInput = " " & filterInput & " "
    range = "int range " ' begining of command
    C = 0
   
    Dim intList()
    For Each line In arrLines
        If Instr(1,line,"Gi") > 0 Or InStr(1,line,"Fa") > 0 Then
            If InStr(1,line,filterInput) Then
                splitLine = Split(line," ")
                intList(C) = splitLine(0)
                C = C + 1
                ReDim Preserve intList(C)
            End If
        End If
    Next
   

        objTab.Screen.Send "config t" & vbCr
    objTab.Screen.WaitForString "#"
        For Each Interface In intList
                If Not Interface = "" Then
                        objTab.Screen.Send "int " & interface & vbCr
                        objTab.Screen.WaitForString "#"
                        objTab.Screen.Send cmdInput & vbCr
                        objTab.Screen.WaitForString "#"
                        objTab.Screen.Send "exit" & vbCr
                        objTab.Screen.WaitForString "#"
                End If
        Next
        objTab.Screen.Send "end" & vbCr
        objTab.Screen.WaitForString "#"
       
End Sub



All times are GMT -6. The time now is 01:51 AM.