Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > General

Closed Thread
 
Thread Tools Display Modes
  #1  
Old 12-16-2014, 12:31 PM
jbd1300 jbd1300 is offline
Registered User
 
Join Date: Dec 2014
Posts: 18
Thumbs down For Each or Do Until----Help Please

I am building a script that can detect if a current modem is in use vs. what is open. However, I don't know what conditional loop to use?

I.E
I have a modem farm, and have currently in use.

router#sh users
Line User Host(s) Idle Location
tty 1/4 idle 00:00:06 modem5
tty 1/6 idle 00:02:13 modem5
tty vty 1 User modem5 00:00:10 IPaddr
tty vty 2 User modem7 00:02:14 IPaddr
*324 con User idle 00:00:00 IPaddr
tty con USer idle 00:01:23 IPaddr

Interface User Mode Idle Peer Address

router#

This is what i have so far. I get into an infinite loop with the following code. Anyone got a good idea of how I can pick a modem that's is open and not in use?

Sub Main()

' turn on synchronous mode
crt.Screen.Synchronous = True

crt.Screen.Send "show users" & chr(13)

Dim n
n=""

Dim modem_inuse(10)
modem_inuse(0) = "idle"
modem_inuse(1) = "modem1"
modem_inuse(2) = "modem2"
modem_inuse(3) = "modem3"
modem_inuse(4) = "modem5"
modem_inuse(5) = "modem6"
modem_inuse(6) = "modem7"
modem_inuse(7) = "modem8"
modem_inuse(8) = "modem15"
modem_inuse(9) = "modem16"

For Each modem in modem_inuse

Do Until n = "modem_found"

Dim Host_Inuse

Host_Inuse = crt.Screen.WaitForStrings(modem_inuse(0), 10)
'Tested this out as well, and doesn't work.
'Host_Inuse = crt.Screen.WaitForStrings("idle", "modem1", "modem2", "modem3" , "modem5", "modem6", "modem7", "modem8", "modem15", "modem16", 10)
Select Case Host_Inuse
Case 0
MsgBox "Timed out waiting for strings"
Exit Do
Case 1
MsgBox "Found idle string!"
Case 2
MsgBox "Found modem1 string!"

Case 3
MsgBox "Found modem2 string!"

Case 4
MsgBox "Found modem3 string!"

Case 5
MsgBox "Found modem5 string!"

Case 6
MsgBox "Found modem6 string!"

Case 7
MsgBox "Found modem7 string!"

Case 8
MsgBox "Found modem8 string!"

Case 9
MsgBox "Found modem15 string!"

Case 10
MsgBox "Found modem16 string!"

Case 11
MsgBox "All Modems are in use!"

End Select

'Exit Do

Loop

Next

End Sub
  #2  
Old 12-16-2014, 12:58 PM
jbd1300 jbd1300 is offline
Registered User
 
Join Date: Dec 2014
Posts: 18
Do I need to have this question moved?

I am new to the support forum, and was browsing around. I just found that there is a scripting section. Should i try to move this post there?

I apologize for not doing my due diligence first.

Thanks

jbd1300
  #3  
Old 12-16-2014, 02:03 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi jbd1300,

Thanks for the post. It seems like we are missing some of the equation.

I have no knowledge of your modem farm, but it seems like you don't just need to find the string "modem<x>". You need to find the string, and determine if the modem is idle or busy.

I think that I would read in the output of the "sh users" command, and then parse the data using a loop combination of some sort.

Is my understanding of your goal accurate?

What is the version of SecureCRT that you are using?

Also, you are welcome to keep this thread here. In the future you may consider posting scripting questions in the scripting forum.
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
  #4  
Old 12-16-2014, 03:42 PM
jbd1300 jbd1300 is offline
Registered User
 
Join Date: Dec 2014
Posts: 18
For Each or Do Until----Help Please

I never thought about testing on both the string and if it's idle or busy. If it shows up in show users, then it has to be in use, or the line is in use. That's the logic I was using at least.. . Yes, I need to read in the show users output, however, didn't want to read it into a log or file, but real time. So, as the command is run and displays the output, the script finds an open modem, and opens a line...such as "connect modem5" for example.

Yes, I would like to parse with a loop, but can't wrap my head around which loop to use, and what the syntax would look like.

I am using Version 6.7.4

Thank you!

jbd1300
  #5  
Old 12-16-2014, 03:43 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi jbd1300,

Thanks for the update.

If the modem is not in the output, then it is not in use?

Do you just need to know the first modem not in use, or all modems not in use?
__________________
--Todd

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

Last edited by rtb; 12-16-2014 at 03:45 PM.
  #6  
Old 12-16-2014, 04:38 PM
jbd1300 jbd1300 is offline
Registered User
 
Join Date: Dec 2014
Posts: 18
For Each or Do Until----Help Please

Correct..if the modem is not in the list, then it's open and not in use.

Yes, based on all the modems in the array, if it can find an open one, that would be exactly what i need. It doesn't necessarily have to be the first one, but just an open one. I would assume that the script would need to know all modems in order to look. I have a total of 9 modems to choose from, and which ever one i can find not in the list, that would be it.

modem_inuse(1) = "modem1"
modem_inuse(2) = "modem2"
modem_inuse(3) = "modem3"
modem_inuse(4) = "modem5"
modem_inuse(5) = "modem6"
modem_inuse(6) = "modem7"
modem_inuse(7) = "modem8"
modem_inuse(8) = "modem15"
modem_inuse(9) = "modem16"

Thanks

jbd1300
  #7  
Old 12-16-2014, 05:50 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi jbd1300,

Thanks for the confirmation. One of the problems you will encounter is duplication. The string "modem1" will always match "modem1", "modem15" and "modem16". I encountered this when I was running tests.

In this type of scenario, a dictionary and regular expressions lend themselves nicely to the solution.

I am working on testing an example. I will post it when it is finished.
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
  #8  
Old 12-17-2014, 10:17 AM
jbd1300 jbd1300 is offline
Registered User
 
Join Date: Dec 2014
Posts: 18
For Each or Do Until----Help Please

Thank you!
Closed Thread

Tags
#auto-select , #conditionalloops


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 09:53 AM.