Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 09-29-2015, 02:07 PM
benitocamela benitocamela is offline
Registered User
 
Join Date: Sep 2015
Posts: 5
loop in vbs script

I'm trying to make a loop to check the machine status after throwing some commands, ex:


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

Const ForReading = 1
Const ForWriting = 2

Sub Main

'Dim logfile
'logfile = "C:\TEMP\mysession.log"
'crt.Session.LogFileName = logfile
Dim fso, file, str
Set fso = CreateObject("Scripting.FileSystemObject")
'crt.Session.Log true
' Note: A runtime exception will be generated if 'input.txt' doesn't exist.
'
Set file = fso.OpenTextFile("C:file.txt", ForReading, False)
crt.Screen.Synchronous = True
crt.Screen.Clear

Do while file.AtEndOfStream <> True

str = file.Readline
' Send the line with an appended CR
crt.Screen.Send str & Chr(13)



crt.Screen.WaitForString "assword:",2
' Send your password followed by a carriage return
crt.Screen.Send "password" & VbCr

crt.Screen.WaitForString "@"
crt.Screen.Send "command-1" & VbCr
crt.Screen.WaitForString "@"

crt.Screen.Send "command-2" & VbCr
crt.Screen.WaitForString "@"

After that, i need to launch a command to check the router status.

If the result of this is OK, continuos the script, with a write command for example.

If the result is not OK, the command to check must be launched with a one minute interval until the router is ok,

Do not know how this loop, in the first loop.

Can you help me.

Thanks
Reply With Quote
  #2  
Old 09-29-2015, 02:18 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi benitocamela,

Thanks for the post. We can help answer any specific questions you might have.

We already have an example script that illustrates how you might accomplish your goal. You may need to modify it to meet your specific needs. Here is the location of the script:
https://forums.vandyke.com/showthrea...7294#post37294
Does this help continue to write your script?
__________________
--Todd

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

Last edited by rtb; 10-03-2015 at 12:12 PM.
Reply With Quote
  #3  
Old 10-01-2015, 12:49 PM
benitocamela benitocamela is offline
Registered User
 
Join Date: Sep 2015
Posts: 5
Thanks rtb
IŽm looking the way to make the loop repeat the command, while the equipment status is not ok.
But when this loop is finished, the script not continuous with the rest:

Quote:

# $language = "VBScript"
# $interface = "1.0"
' This script demonstrates how to open a text file and it line by
' line to a server.
' Constants used by OpenTextFile()

Const ForReading = 1
Const ForWriting = 2

Sub Main

'Dim logfile
'logfile = "C:\TEMP\mysession.log"
'crt.Session.LogFileName = logfile
Dim fso, file, str
Set fso = CreateObject("Scripting.FileSystemObject")


'crt.Session.Log true
' Note: A runtime exception will be generated if 'input.txt' doesn't exist.
'
Set file = fso.OpenTextFile("C:\TEMP\mysession.log", ForReading, False)

crt.Screen.Synchronous = True
crt.Screen.Clear

Do while file.AtEndOfStream <> True

Str = file.Readline
' Send the line with an appended CR

crt.Screen.Send str & VbCr
crt.sleep 1000

crt.Screen.WaitForStrings "assword:",2
' Send your password followed by a carriage return
crt.Screen.Send "PASWORD" & VbCr

crt.Screen.WaitForString "@"
crt.Screen.Send "COMMAND-1" & VbCr
crt.Screen.WaitForString "@"

crt.Screen.Send "CHECK-STATUS-COMMAND" & VbCr

Do While crt.Screen.WaitForString ("busy" & VbCr)
crt.sleep 20000
crt.Screen.Send "CHECK-STATUS-COMMAND" & VbCr
Loop


crt.Screen.WaitForString "@"
crt.Screen.Send "exit" & VbCr
crt.Screen.WaitForString "@"


Loop
End Sub


which may be the fault?
Reply With Quote
  #4  
Old 10-01-2015, 03:02 PM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,635
Hi benitocamela,

Todd (rtb) is not available.

Your WaitForString() call will never return if "busy" is not found, because you are not providing a timeout.

You will want to add a timeout parameter that will cause WaitForString() to exit if it does not find "busy" in 5 or 10 seconds.

For example:

Code:
nTimeout = 5
Do While crt.Screen.WaitForString ("busy" & VbCr, nTimeout) 
    crt.sleep 20000 
    crt.Screen.Send "CHECK-STATUS-COMMAND" & VbCr
Loop
__________________
Thanks,
--Brenda

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

Last edited by bgagnon; 10-05-2015 at 07:08 AM. Reason: Name was incorrect
Reply With Quote
  #5  
Old 10-02-2015, 04:13 PM
benitocamela benitocamela is offline
Registered User
 
Join Date: Sep 2015
Posts: 5
The scripts works fine.

You solved my problem !!!!

Thank you Brenda!!!

The final script works like this:

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

Const ForReading = 1
Const ForWriting = 2

Sub Main

Dim logfile
logfile = "C:\TEMP\mysession.log"
crt.Session.LogFileName = logfile

Dim fso, file, str
Set fso = CreateObject("Scripting.FileSystemObject")
'crt.Session.Log true
' Note: A runtime exception will be generated if 'input.txt' doesn't exist.
'
Set file = fso.OpenTextFile("C:\MY_ROUTERS.txt", ForReading, False)
crt.Screen.Synchronous = True
crt.Screen.Clear

Do while file.AtEndOfStream <> True

str = file.Readline
' Send the line with an appended CR
crt.Screen.Send str & VbCr
crt.sleep 1000


crt.Screen.WaitForString "assword:",2
' Send your password followed by a carriage return
crt.Screen.Send "My_PASSWORD" & VbCr

crt.Screen.WaitForString ">"
crt.Screen.Send "COMMAND_1" & VbCr
crt.Screen.WaitForString ">"

crt.Screen.Send "CHECK_STATUS" & VbCr

nTimeout = 5
Do While crt.Screen.WaitForString ("busy", nTimeout)
crt.sleep 60000
crt.Screen.Send "CHECK_STATUS" & VbCr
Loop
crt.Screen.Send VbCr
crt.Screen.WaitForStrings ">"
crt.Screen.Send "exit" & VbCr

crt.Screen.WaitForString "~]$"

Loop

End sub
Reply With Quote
  #6  
Old 10-05-2015, 07:08 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,635
Hi benitocamela,

Great, thanks for posting an update!
__________________
Thanks,
--Brenda

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