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 01-12-2007, 02:54 PM
Srinath Srinath is offline
Registered User
 
Join Date: Aug 2006
Posts: 7
Post Question abt "WaitforStrings"!!!

Hello,
I'm trying to automate the Hardware testing process of a Nortel router through Secure CRT and have been using a set of "$crt->Screen->Send()" &
"$crt->Screen->WaitforStrings()" commands to achieve this goal. What I've have been experiencing is that the "WaitforStrings()" command acts a little inconsistent with the way it functions. To give you a quick idea:

#Fabric Test
$crt->Screen->Send("lock sh fab/x"."\015");
$crt->Screen->WaitforStrings("Shelf FabricCard/x",1000);
$crt->Screen->Send("unlock sh fab/x"."\015");
$crt->Screen->WaitforStrings("Shelf FabricCard/x",9000);
$crt->Screen->Send("d sh fab/x"."\015");
$crt->Screen->WaitforStrings("ok",10000);

$crt->Screen->Send("lock sh fab/y"."\015");
$crt->Screen->WaitforStrings("Shelf FabricCard/y",1000);
$crt->Screen->Send("set sh fab/y test duration 20"."\015");
$crt->Screen->WaitforStrings("ok",1000);
$crt->Screen->Send("start sh fab/y test"."\015");
$crt->Screen->WaitforStrings("Test stopped.",200000);

Marked in red, I wanted a wait time of "10000" seconds to receive an "ok" string & then go ahead with a "lock sh fab/y". But it doesn't work as expected and increasing time values seems useless! What happens is that the next command gets throwed in ("lock sh fab/y") causing a failure of the entire test process.

I also tried providing manual delays like the following:
$crt->Screen->WaitforStrings("",1000);
$crt->Screen->Send("\015");

While adding it did provide some delays it skips the "lock sh fab/y" command altogether and gets to the third line after that. It acts very randomly depending on the nature of the commands that I execute through the script, although granted, I have my delays factored in appropriately. Am I missing something here? Is there a way to achieve a tighter control on the time and the output that I receive?

Also wanted to ask on how accurate the string specified in the "WaitforStrings" fn needs to be. For eg:
4>
--- Response 2 continued ...
Shelf FabricCard/x
ok 2007-01-12 21:01:18.17

In the above cmd output I would like to WaitforStrings to read "Shelf FabricCard/x" string or even "ok" but not the time as I don't want to start writing a complex code to start syching-up with N/w clocks now and it does catch it from my experiencing running the script number of times. But is it expected to catch specific strings as well?

Any suggestions would be of great help. Thanks for your help in advance!
Thanks
Reply With Quote
  #2  
Old 01-14-2007, 10:31 PM
eazy2001x eazy2001x is offline
Registered User
 
Join Date: Jan 2007
Posts: 17
The wait commands are not counted in seconds.. Correct me if Iím wrong but 1000=1 second so your 10000=10 seconds. So if you want to wait for 10000 seconds it will look more like 10000000. Someone else can chime in if my counting is off.
Reply With Quote
  #3  
Old 01-15-2007, 08:37 AM
tnygren's Avatar
tnygren tnygren is offline
Registered User
 
Join Date: May 2005
Posts: 1,408
Hi Srinath,

If I understand correctly, it appears that the ok and other strings being waited for are not being seen by the script.

Is this correct?

If so, this can happen when the 'crt.screen.synchronous' object is not set to 'true'. In the piece of code that you posted, I do not see this object being used.

Is it used in this script?

If not, does added this prevent the lines from being missed.

If this was not correct, could you tell me more about what is happening?


Hi Eazy2001x,

Thanks for your post!

This can be confusing.

The timeout for the waitforstring object is entered in seconds rather then milliseconds. This is different from say the 'crt.sleep'object when milliseconds is used.
__________________
Thanks,

Teresa

Teresa Nygren
Reply With Quote
  #4  
Old 01-16-2007, 02:38 PM
Srinath Srinath is offline
Registered User
 
Join Date: Aug 2006
Posts: 7
Unhappy

Thanks for all your responses. Below is the complete code for your reference. Yes I have enabled the 'Synchronous mode' setting as you can see below. To restate my problem more clearly, everything works absolutely as planned till the line marked in red. When the sh fab/x test completes after 20 minutes the shelf fabric needs to be unlocked (unlock sh fab/x) before continuing to "lock sh fab/y" which is the line in blue. But it fails every time at the statement marked in red. What happens is that SecureCRT sees the string "Test Stopped" , throws the string "unlock sh fab/x" into the switch and WITHOUT WAITING FOR 9000 seconds to expire nor for the "Shelf FabricCard/x" string to appear, it immidiately proceeds with the following statements "lock sh fab/y" causing the whole test sequence to collapse cause there should be atleast one shelf fab available at any instant (X or Y).

Interestingly enough I had success in conducting the same test for 1 minute instead of 20 minutes. Nothing changed except for the test duration and "WaitforStrings" did exactly what I wanted it to do.

As stated previously I even tried sending a few null strings to manually add delays but the results were pretty unpredictable and random.This leads me to question the stability & integrity of the "WaitForStrings" function. Any suggestions/comments will be of invaluable help.
Thanks


# $language = "PerlScript"
# $interface = "1.0"
use Win32::OLE;
Win32::OLE->Option(Warn => 3);

# define some useful constants
$true = 1;
$false = 0;
$StartLog = $true;
$StopLog = $false;
$Append = $true;
$Overwrite = $false;
$Raw = $true;
$Not_raw = $false;

# NOTE: Set your logfile path here
$LogFilePath = "C:\\Documents and Settings\\PP 15k Turn-ups";

# Enable synchronous mode to prevent missed output.
$crt->Screen->{'Synchronous'} = $true;

# Connect to each session using the "/s sessionname" argument.
$crt->Session->Connect("/s " . ELkridge6);

# Wait for 5 seconds, or until the login prompt appears.
$crt->Screen->Send("\015");
$crt->Screen->WaitForString("Enter login:", 5);
$crt->Screen->Send("ABC"."\015");
$crt->Screen->WaitForString("Enter password:", 5);
$crt->Screen->Send("123"."\015");

# Set the name of the logfile for this session.
$crt->Session->{'LogFileName'} = $LogFilePath . "log-" . EKRGMD92GT6;

# Enable logging
$crt->Session->Log($StartLog, $Append, $Not_raw);

#Fabric Test
$crt->Screen->Send("lock sh fab/x"."\015");
$crt->Screen->WaitforStrings("Shelf FabricCard/x",1000);
$crt->Screen->Send("set sh fab/x test duration 20"."\015");
$crt->Screen->WaitforStrings("ok",10);
$crt->Screen->Send("start sh fab/x test"."\015");
$crt->Screen->WaitforStrings("Test stopped.",200000);
$crt->Screen->Send("unlock sh fab/x"."\015");
$crt->Screen->WaitforStrings("Shelf FabricCard/x",9000);


$crt->Screen->Send("lock sh fab/y"."\015");
$crt->Screen->WaitforStrings("Shelf FabricCard/y",1000);
$crt->Screen->Send("set sh fab/y test duration 20"."\015");
$crt->Screen->WaitforStrings("ok",1000);
$crt->Screen->Send("start sh fab/y test"."\015");
$crt->Screen->WaitforStrings("Test stopped.",200000);
$crt->Screen->Send("unlock sh fab/y"."\015");
$crt->Screen->WaitforStrings("Shelf FabricCard/y",50000);
$crt->Screen->Send("\015");
$crt->Screen->WaitforStrings("",1000);
$crt->Screen->Send("\015");

$crt->Session->Log($StopLog);
$crt->Session->Disconnect();

# turn off synchronous mode
$crt->Screen->{'Synchronous'} = $false;

Last edited by Srinath; 01-16-2007 at 02:41 PM.
Reply With Quote
  #5  
Old 01-16-2007, 03:23 PM
tnygren's Avatar
tnygren tnygren is offline
Registered User
 
Join Date: May 2005
Posts: 1,408
Hi Srinath,

Thanks for posting the complete script.

Although I don't think that this is the issue, I did want to let you know that you may want to use the 'WaitForString' object instead of the 'WaitForStrings' object as you are waiting for only one string to appear.

The 'WaitForStrings' object is used to look for multiple strings that may appear when a command is run. For example, if a command is run to move a file, you may want to use 'WaitForStrings' to wait for the possible responses such as file not found, permission denied or the command prompt when the command completes successfully.

For example (using VBScript and exiting the script when the command does not complete successfully):

Code:
  
Do
    nresult = crt.screen.WaitForStrings ("File Not Found", "Permission Denied", "->", 100)
    Select Case nResult
        Case 1
            ' The file was not found.
            msgbox "The file was not found!"
        Case 2
            'Permission was denied
            msgbox "Permission was denied!"
        Case 3
            ' The prompt appeared... the command is finished.
            exit do
        Case 0
            ' The string was not found and the wait timed out
            msgbox "None of the strings were found before the timeout occurred!"
            exit do
     End Select
Loop

If I understand correctly from the script, you do not want the script to continue until the specific string is found on in the terminal window.

Is this correct?

If so, I would suggest removing the timeout from all the 'WaitForString' lines in the script. Without a timeout, SecureCRT will just wait for the string to appear and then continue with the script once it is found.

With a timeout parameter specified, the string may not have appeared within the specified time and the script will continue with the next line of code. However, the remote may not be ready to receive data, causing the data to be "lost".

Without a timeout, the WaitForString() function will not return untill the string has been found, ensuring that subsequent Send() commands will send the next piece of data only when the remote is ready to receive it.

Another option would be to check the result of the WaitForString function. If WaitForString times out before finding the string, the result will be '0', versus '1' (or 'found'). If you supply a timeout parameter to the WaitForString function, checking its return value would allow you to take corrective action (stop the script) if needed.

If the timeouts are removed, does the script run properly or stop at a different line in the script?
__________________
Thanks,

Teresa

Teresa Nygren

Last edited by jdev; 01-16-2007 at 04:33 PM.
Reply With Quote
  #6  
Old 01-20-2007, 03:02 PM
Srinath Srinath is offline
Registered User
 
Join Date: Aug 2006
Posts: 7
Post Nothing changed!

Teresa - Thankyou very very much for your responses. To start with let me answer a few questions of yours.
A) If I understand correctly from the script, you do not want the script to continue until the specific string is found on in the terminal window.
ANS: Yes.

b) If the timeouts are removed, does the script run properly or stop at a different line in the script?
Ans. When the timeouts are removed the script performs the same way as before; getting messed up exactly at the same line as I had mentioned previously. Below is the revised code replacing "WaitFotStrings" to "WaitForString" and removing all timeouts.

# $language = "PerlScript"
# $interface = "1.0"
use Win32::OLE;
Win32::OLE->Option(Warn => 3);

# define some useful constants
$true = 1;
$false = 0;
$StartLog = $true;
$StopLog = $false;
$Append = $true;
$Overwrite = $false;
$Raw = $true;
$Not_raw = $false;

# NOTE: Set your logfile path here
$LogFilePath = "C:\\Documents and Settings\\PP 15k Turn-ups";

# Enable synchronous mode to prevent missed output.
$crt->Screen->{'Synchronous'} = $true;

# Connect to each session using the "/s sessionname" argument.
$crt->Session->Connect("/s " . T6);

# Wait for 5 seconds, or until the login prompt appears.
$crt->Screen->Send("\015");
$crt->Screen->WaitForString("Enter login:");
$crt->Screen->Send("ABC"."\015");
$crt->Screen->WaitForString("Enter password:");
$crt->Screen->Send("123"."\015");

# Set the name of the logfile for this session.
$crt->Session->{'LogFileName'} = $LogFilePath . "log-" . T6;

# Enable logging
$crt->Session->Log($StartLog, $Append, $Not_raw);

#Fabric Test
$crt->Screen->Send("lock sh fab/x"."\015");
$crt->Screen->WaitforString("Shelf FabricCard/x");
$crt->Screen->Send("set sh fab/x test duration 20"."\015");
$crt->Screen->WaitforString("ok");
$crt->Screen->Send("start sh fab/x test"."\015");
$crt->Screen->WaitforString("Test stopped.");
$crt->Screen->Send("unlock sh fab/x"."\015");
$crt->Screen->WaitforString("ok");

$crt->Screen->Send("lock sh fab/y"."\015");

$crt->Screen->WaitforString("Shelf FabricCard/y");
$crt->Screen->Send("set sh fab/y test duration 20"."\015");
$crt->Screen->WaitforString("ok");
$crt->Screen->Send("start sh fab/y test"."\015");
$crt->Screen->WaitforString("Test stopped.");
$crt->Screen->Send("unlock sh fab/y"."\015");
$crt->Screen->WaitforString("ok");

#$crt->Session->Log($StopLog);
#$crt->Session->Disconnect();

# turn off synchronous mode
$crt->Screen->{'Synchronous'} = $false;

Below is the switch O/p when the above code is executed. After the test for "Shelf Fabrix X "stopped (lines in green), the "unlock sh fab/x" command was sent by the script after it validated the receipt of the "Test Stopped" string. Next the script had to wait for the string "ok" before throwing in the next command "lock sh fab/y", but if you look it never did (look at the lines in red). For some reason or the other it never waited for the "ok" string and went ahead with the next line "sh fab/y" which disrupted the entire testing sequence as atleast one shelf fabric had to be ative before the other one could be taken down. In our case sh fab/x was still coming up (which it did eventually; lines is Magenta) and since the script did not wait for the "ok" before issuing the "lock sh fab/y" command it totally messed-up everything.

Why would "WaitForString" that could wait for 20 minutes to receive "Test Stopped" string not wait for about a minute to receive an "ok" after it executes the "unlock sh fab/x" command. This makes me think that this function perfoms inconsistently. Looking forward to your inputs/suggestions.
Thanks


1> lock sh fab/x

Shelf FabricCard/x; 2007-01-20 19:12:21.09
SET critical operator operationalCondition 00001000
ADMIN: locked OPER: enabled USAGE: idle
AVAIL: PROC: CNTRL:
ALARM: STBY: notSet UNKNW: false
Id: 0109 Rel:
Com: Fabric Card is locked
Int: 0/0/2/10383; bcsBus.cc; 719; ""

2>
--- Response 1 continued ...
Shelf FabricCard/x
ok 2007-01-20 19:12:21.09

2> set sh fab/x test duration 20
Shelf FabricCard/x Test
ok 2007-01-20 19:12:21.88

3> start sh fab/x test
Shelf FabricCard/x Test
Test started.

4>
Shelf FabricCard/x; 2007-01-20 19:12:28.25
SET major equipment equipmentFailure 70020002
ADMIN: locked OPER: disabled USAGE: idle
AVAIL: inTest PROC: CNTRL:
ALARM: STBY: notSet UNKNW: false
Id: 010B Rel:
Com: SCB Channel X: ADMIN: Unlocked OPER: Enabled USAGE: idle
Bustap Info: A:0ffff D:0fffe F:00000 T:00001 I:00000 O:00000
Int: 0/0/2/10381; scbChannelManager.cc; 1756; ""
000000000000000000000000000000000000000000000000

4>
--- Response 3 continued ...
Shelf FabricCard/x Test
Test stopped.
ok 2007-01-20 19:32:22.52


4> unlock sh fab/x

5>
Shelf FabricCard/x; 2007-01-20 19:32:29.27
SET major equipment equipmentFailure 70020002
ADMIN: locked OPER: disabled USAGE: idle
AVAIL: inTest PROC: CNTRL:
ALARM: STBY: notSet UNKNW: false
Id: 010D Rel:
Com: SCB Channel X: ADMIN: Unlocked OPER: Enabled USAGE: idle
Bustap Info: A:0ffff D:0fffe F:00000 T:00001 I:00000 O:00000
Int: 0/0/2/10381; scbChannelManager.cc; 1756; ""
000000000000000000000000000000000000000000000000


6> lock sh fab/y
Shelf FabricCard/y
Cannot lock the only fabric in service.
command failed 2007-01-20 19:32:30.10

7> set sh fab/y test duration 20
Shelf FabricCard/y Test
ok 2007-01-20 19:32:30.72

8> start sh fab/y test
Shelf FabricCard/y Test
Test in progress.
command failed 2007-01-20 19:32:31.28


9>
--- Response 4 continued ...
Shelf FabricCard/x
ok 2007-01-20 19:32:47.23
Reply With Quote
  #7  
Old 01-23-2007, 02:21 PM
tnygren's Avatar
tnygren tnygren is offline
Registered User
 
Join Date: May 2005
Posts: 1,408
Hi Srinath,

I think that I see what is happening.

It is not that 'waitforstring' is not waiting for the 'OK'. It that the OK appears right after the 'Test stopped' string and is found earlier then needed.

Let me explain.

When 'Test stopped.' appears on the screen, the script immediately sends the command required ("unlock sh fab/x"). When the next 'waitforstring' is issued ("ok"), SecureCRT will start looking from the point where 'Test stopped.' was found.

In this case, the 'ok' appears in the next line under 'Test stopped.' and the next command in the script is executed since the 'ok' string was found.

If the script is modified to add an extra 'waitforstring' for the 'ok' before the unlock command is issued, do you see better results?

For example:


Code:
$crt->Screen->Send("start sh fab/x test"."\015");
$crt->Screen->WaitforString("Test stopped.");

$crt->Screen->WaitforString("ok");

$crt->Screen->Send("unlock sh fab/x"."\015");
$crt->Screen->WaitforString("ok");
$crt->Screen->Send("lock sh fab/y"."\015");
__________________
Thanks,

Teresa

Teresa Nygren
Reply With Quote
  #8  
Old 01-24-2007, 12:02 PM
Srinath Srinath is offline
Registered User
 
Join Date: Aug 2006
Posts: 7
Smile You Rock..!!

Teresa - Excellent catch there! Yep..you solved the issue. I incuded another WaitforString "ok" and test started running like a breeze. Thankyou very very much. Couldn't have solved this without you.
Thanks
Reply With Quote
  #9  
Old 01-24-2007, 02:31 PM
tnygren's Avatar
tnygren tnygren is offline
Registered User
 
Join Date: May 2005
Posts: 1,408
Hi Srinath,

You are very welcome and I'm glad that the script is working!

If you have any other questions on the scripting objects or our products, please let us know.
__________________
Thanks,

Teresa

Teresa Nygren
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 01:38 PM.