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 06-04-2016, 03:09 PM
jasonrakers jasonrakers is offline
Registered User
 
Join Date: Jun 2016
Posts: 2
python sleep delay

I am having issues with my script not executing sleep as expected. It appears that my sleep function is being executed first and not within the loop. I am trying to get the command in the loop to run every X seconds.

Code:
count = 0
szCommand1 = "set cli pager off"
szCommand2 = "show interface all"
objTab.Screen.Send(szCommand1 + "\r\n")
while (count < 9):
    objTab.Screen.Send(szCommand2 + "\r\n")
    #Wait for X milliseconds
    crt.Sleep(1000), count
    count = count + 1
After selecting "run" script from SecureCRT the script waits for the approximate Sleep value before executing the While loop. I have verified if I change the Sleep value, the time to begin changes accordingly (4000 * 9 = 36 seconds before start, 1000 * 9 = 9 seconds before start, etc.). I am using SecureCRT 6.6.3.

Last edited by jdev; 06-06-2016 at 09:13 AM.
Reply With Quote
  #2  
Old 06-06-2016, 09:22 AM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 919
Before you call crt.Screen.Send(), is crt.Screen.Synchronous true, or false?

If crt.Screen.Synchronous is true, then nothing will appear on the screen until you call a crt.Screen.WaitFor*() or a crt.Screen.ReadString().

This means that it may *seem* like your sleep call isn't happening like you desire, only because text won't show up on the screen until the script actually completes. This is by design so that you can make a call to screen.WaitFor*() or screen.ReadString() and have a high degree of confidence that data will not have been received and displayed to the screen between lines of code as the script is executing.

In SecureCRT scripting, you should practice these general "good things":
  • Use crt.Screen.Synchronous set to true
  • For every crt.Screen.Send() call you make, put in a corresponding crt.Screen.WaitForString(), passing in a value of some text that lets you know that what you sent has completed, and the remote device is ready for another command to be sent. Typically, the text you WaitFor..() or ReadString() to would be the remote shell prompt.
  • Don't use crt.Sleep() as a way of synchronizing the script thread with what's happening in the terminal screen. This won't work because the script thread is asynchronous with the terminal screen.
  • Read through the SecureCRT Scripting Guide. Even though the primary language used there is VBScript, it contains best practices and information that can pertain to general situations.
  • Read through the samples in the Example Scripts "sticky" in the Scripting forum. You can learn a lot and avoid making mistakes that would otherwise lead you to believe there's a bug in the program.

--Jake
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
Reply With Quote
  #3  
Old 06-06-2016, 10:34 AM
jasonrakers jasonrakers is offline
Registered User
 
Join Date: Jun 2016
Posts: 2
excellent!

Quote:
Originally Posted by jdev View Post
Before you call crt.Screen.Send(), is crt.Screen.Synchronous true, or false?

If crt.Screen.Synchronous is true, then nothing will appear on the screen until you call a crt.Screen.WaitFor*() or a crt.Screen.ReadString().

This means that it may *seem* like your sleep call isn't happening like you desire, only because text won't show up on the screen until the script actually completes. This is by design so that you can make a call to screen.WaitFor*() or screen.ReadString() and have a high degree of confidence that data will not have been received and displayed to the screen between lines of code as the script is executing.

Thanks, it is set to Synchronous. I think I got it now. Thanks for the good info!
Reply With Quote
Reply

Tags
python , sleep


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 12:23 PM.