Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
  #1  
Old 04-19-2011, 07:10 AM
pustekuchen pustekuchen is offline
Registered User
 
Join Date: Jan 2011
Posts: 7
Crt.Screen.Get

Hi,

I use SecureCRT in combination with Cisco and 3Com now for about 2 months. Now I have the Crt.Screen.Get issue commands, so I get information from the Cisco switch. Normally I have to add as brackets and the parentheses are the rows and columns inside written. For example Crt.Screen.Get (43,28,56,28). The problem is only when I add a new Cisco command, move the whole line, so I have to adjust the row again. I would like to add here a dynamic value.

Can you help me please

Greetings
pustekuchen
Reply With Quote
  #2  
Old 04-19-2011, 08:06 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi pustekuchen,

Thanks for the question. Scripting is a way to perform automatically, that which can be performed manually. What you will need to determine is how you can tell that the position on the screen that needs to be captured has changed when you perform the task manually, and then translate this to a script. This may or may not be possible.

Another option may be to use the ReadString method of the Screen object. This would allow you to capture data from the point a command is sent to the remote to a pre-defined end point. You could then use different methods to parse the data that was captured to obtain the data you need.

Does this information help you accomplish your goal?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #3  
Old 04-19-2011, 08:25 AM
pustekuchen pustekuchen is offline
Registered User
 
Join Date: Jan 2011
Posts: 7
Hi rtb,

thanks so much for your answer, but I donīt know how I should make this command complete.

PHP Code:
' Change interfaceFastEthernet0/1
        crt.Screen.Send "show interfaces status" & vbCr
        crt.Screen.WaitForString "#"
        nVlan = Crt.Screen.Get(43,43,43,43)
        MsgBox "VLAN: " & nVlan
            If nVlan = 5 Then
                crt.Screen.Send "configure t" & vbCr
                crt.Screen.WaitForString "(config)#"
                crt.Screen.Send "interface fastEthernet 0/1" & vbCr
                crt.Screen.WaitForString "(config-if)#"
                crt.Screen.Send "switchport access vlan 1" & vbCr
                crt.Screen.WaitForString "(config-if)#"
                crt.Screen.Send "exit" & vbCr 
                crt.Screen.WaitForString "(config)#"
                crt.Screen.Send "exit" & vbCr 
                crt.Screen.WaitForString "#"
            ElseIf nVlan = 1 Then
                crt.Screen.Send "configure t" & vbCr
                crt.Screen.WaitForString "(config)#"
                crt.Screen.Send "interface fastEthernet 0/1" & vbCr
                crt.Screen.WaitForString "(config-if)#"
                crt.Screen.Send "switchport access vlan 5" & vbCr
                crt.Screen.WaitForString "(config-if)#"
                crt.Screen.Send "exit" & vbCr 
                crt.Screen.WaitForString "(config)#"
                crt.Screen.Send "exit" & vbCr 
                crt.Screen.WaitForString "#"
            End If 
Here is my actually script without the readstring command.

Best
Pustekuchen
Reply With Quote
  #4  
Old 04-19-2011, 10:00 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi Pustekuchen,

Thanks for the additional information. To be able to help, I need to know more about the output the remote is sending. Would you be able to post a screenshot of the output and indicate what part of the output you need to capture?

If not, would you be able to send this data to support@vandyke.com with a subject of Attn: Todd - Forum thread 7397?

What is the significance of row 43 and column 43?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730

Last edited by rtb; 04-19-2011 at 10:03 AM.
Reply With Quote
  #5  
Old 04-20-2011, 12:43 AM
pustekuchen pustekuchen is offline
Registered User
 
Join Date: Jan 2011
Posts: 7
Hi rtb,

thanks for your response. I have attached this picture. I need all the green marked zone information and the (43,43,43,43) is the red marked zone.

I think this could be a good information:

I need the VLAN IDīs because if the Script running and changes some interfaces the VB-Script should look which VLAN is actually running or set. Then the VB-Script should get a info with the Crt.Screen.Get or an other command. Then the Script should go into a loop as long as something is true until. If the VLAN ID for example 5 the Script should do nothing and is the VLAN ID is 1 the Script should do a command which i had set.

PS: Can you help here, I need a command if the link to the switch did not work go to the next switch.

The Command should come after this
PHP Code:
' Connect 
        crt.Screen.Synchronous = True
        crt.Session.Connect cnxnString
        If protocol = "Telnet" Then
            Dim index
            index = crt.Screen.WaitForStrings("Username:", "Password:")
            
            If index = 1 Then 
                crt.Screen.Send username & vbCr    
                crt.Screen.WaitForString "Password:"
                 crt.Screen.Send loginPassSSH & vbCr
            Elseif index = 2 Then
                crt.Screen.Send password & vbCr
            End If
        End If 
Best
pustekuchen
Attached Images
File Type: jpg untitled.JPG (268.4 KB, 760 views)
Reply With Quote
  #6  
Old 04-20-2011, 04:00 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi pustekuchen,

Thanks for the screenshot. Based on what you have said, it is still not entirely clear what it is you want to accomplish. If all you need to do is get the vlan, I am working on an example and will post this tomorrow.

If you need to do more than find the vlan, then please let me know what it is that you need to accomplish.
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #7  
Old 04-21-2011, 01:04 AM
pustekuchen pustekuchen is offline
Registered User
 
Join Date: Jan 2011
Posts: 7
Hi rtb,

at first i need only the VLAN IDīs from the Cisco or 3Com Switch. I can only find out the VLAN IDīs with the command "show interfaces status". If you know a better command, I will be glad.

With the information from the switch i would like to make an if-Loop.

Can you give me also a command which going to the next device if the connection will be failed.

If this information not to much for you please let me know it.

Best
pustekuchen
Reply With Quote
  #8  
Old 04-21-2011, 01:47 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi pustekuchen,

Here is an example of how to read the data and parse it.
Code:
strCommand = "show interfaces status" & vbcr ' <--This may need to be changed
crt.Screen.Synchronous = True
crt.Screen.Send strCommand
crt.Screen.WaitForString strCommand
strShowInt = crt.Screen.ReadString("$") ' <--This may need to be changed
vElems = Split(strShowInt, vbcr)
For i = 1 to Ubound(vElems)
    nStatus = Mid(vElems(i), 43, 1) ' <--This may need to be changed
    If IsNumeric(nStatus) Then
        Select Case nStatus
            Case 5
                ' Do work -- This is where you perform the work that needs to be done
            Case 1
                ' Do work -- This is where you perform the work that needs to be done
        End Select
    End If
Next
It is important to note that using Mid is not robust, and may be to limited for a complex scenario. You may need to use a method other than Mid to parse the data captured by ReadString.

You should be able to use the following example from the SecureCRT help files to move past devices to which the script is not able to connect:
Code:
On Error Resume Next
crt.Session.Connect "/SSH2 /PASSWORD password username@hostname", True
If Err.Number <> 0 Then
    MsgBox "Connection Failed"
Else
    MsgBox "Connection Successful"
End If
Is this information helpful?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730

Last edited by rtb; 04-22-2011 at 10:34 AM.
Reply With Quote
  #9  
Old 04-22-2011, 07:20 AM
pustekuchen pustekuchen is offline
Registered User
 
Join Date: Jan 2011
Posts: 7
Hi rtb,

thank you, i will test it out now. Can you tell me what case 5 mean?
Should i put in there my commands about if nVLAN = 5 ??

best
pustekuchen
Reply With Quote
  #10  
Old 04-22-2011, 07:51 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi pustekuchen,

Thanks for the question. The Select Case statement is like an If statement. Basically, the code says, get nStatus, and do one of the following (Case 5, Case 1, etc.) depending on the value.

To answer your question, you would replace the ' Do work line with the commands you need to perform if Vlan is equal to 5. You would do the same thing for the case where Vlan is equal to 1. You can also add other cases if they exist.

Does this help to answer your question?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #11  
Old 04-22-2011, 08:10 AM
pustekuchen pustekuchen is offline
Registered User
 
Join Date: Jan 2011
Posts: 7
Ok. If i run the script now, then he stopped at this line and do nothing:

strShowInt = crt.Screen.ReadString("$")

if i insert to $ the number 5 then the script is running sucessfully, but he doesn´t change the interface

The Script to move past devices doesn´t work.

Can i send my full script with email to you, that you could have a look at it?

Last edited by pustekuchen; 04-22-2011 at 08:17 AM.
Reply With Quote
  #12  
Old 04-22-2011, 08:42 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi pustekuchen,

Thanks for the update. You are welcome to send your script to support@vandyke.com with a subject of Attn: Todd - Forum thread 7397. With regards to the problem you are seeing. I have posted an example. You will need to make modifications as necessary.

If using strShowInt = crt.Screen.ReadString("$") is not working, then you will need to modify what ReadString is looking for. In your case the "$" should be "CAT-99#".

Does this help to resolve the issue?

I will need to see the script for assistance with the issue where the script is not moving past devices.
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #13  
Old 04-22-2011, 08:53 AM
pustekuchen pustekuchen is offline
Registered User
 
Join Date: Jan 2011
Posts: 7
Hi rtb,

well i have add now:
strShowInt = crt.Screen.ReadString(""& name &"") because i will a dynamicially script, but he doesnīt go into a "loop" or work the case statement through.

best
pustekuchen
Reply With Quote
  #14  
Old 04-22-2011, 09:44 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi pustekuchen,

Thanks for the update. Please see my e-mail response for the suggestions that I have.
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 03:38 PM.