Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > General

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 07-16-2019, 08:25 AM
melarnell melarnell is offline
Registered User
 
Join Date: Jul 2019
Posts: 5
Automate Script Run Time

I have a script that run every 15 seconds. Is there a way to script it to run for an hour and then automatically open the log file or to export the data into a csv or excel file? All help is appreciated.


Do

crt.Screen.Send "tmsh show sys connection cs-server-addr x.x.x.x" & chr(13)

Loop Until crt.Screen.WaitForKey(15)
Reply With Quote
  #2  
Old 07-16-2019, 08:56 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,636
Hi melarnell,

I think the simplest way is to calculate how many 15 second intervals in an hour (4 per min * 60 = 240) and then just use a simple For/Next loop with a Sleep(). You might even use variables to make the construct more flexible.

Code:
nInterval = 15 * 1000
nIterations = 240
For i = 0 to nIterations
    ' Run command
    crt.Screen.Send "tmsh show sys connection cs-server-addr x.x.x.x" & chr(13)
    ' Sleep 15 seconds
    crt.Sleep nInterval
Next
Quote:
Is there a way to script it to run for an hour and then automatically open the log file or to export the data into a csv or excel file? All help is appreciated.
You reference *the* log file. Do you already have code in your script for logging? (Or is this the entire script at this time?)

If not, adding the logging or Excel interaction would be much more involved.

What version of SecureCRT are you using?

On what OS/platform?
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #3  
Old 07-16-2019, 09:15 AM
melarnell melarnell is offline
Registered User
 
Join Date: Jul 2019
Posts: 5
Thumbs up

Quote:
Originally Posted by bgagnon View Post
Hi melarnell,

I think the simplest way is to calculate how many 15 second intervals in an hour (4 per min * 60 = 240) and then just use a simple For/Next loop with a Sleep(). You might even use variables to make the construct more flexible.

Code:
nInterval = 15 * 1000
nIterations = 240
For i = 0 to nIterations
    ' Run command
    crt.Screen.Send "tmsh show sys connection cs-server-addr x.x.x.x" & chr(13)
    ' Sleep 15 seconds
    crt.Sleep nInterval
Next
You reference *the* log file. Do you already have code in your script for logging? (Or is this the entire script at this time?)

If not, adding the logging or Excel interaction would be much more involved.

What version of SecureCRT are you using?

On what OS/platform?

Every time I open a session the logging begins.
8.5.4x64 build 1942
Windows 10 Ent

I will try the added variable/integer and let you know the result. Appreciate the quick response.
Reply With Quote
  #4  
Old 07-16-2019, 10:16 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,636
Hi melarnell,

On Windows, you can use the shell object to open the file. You also probably want to stop/start logging within the script so you don't open the file while still logging to it as well as needing to define the file to be opened.

So somewhere at the beginning of the script:
Code:
Set shell = CreateObject("WScript.Shell")

crt.Session.LogUsingSessionOptions
Then, at the end:
Code:
crt.Session.Log False

strLogFile = crt.Session.LogFileName

' Open the file for viewing
shell.Run chr(34) & strLogFile & chr(34)
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #5  
Old 07-16-2019, 11:39 AM
melarnell melarnell is offline
Registered User
 
Join Date: Jul 2019
Posts: 5
Quote:
Originally Posted by bgagnon View Post
Hi melarnell,

On Windows, you can use the shell object to open the file. You also probably want to stop/start logging within the script so you don't open the file while still logging to it as well as needing to define the file to be opened.

So somewhere at the beginning of the script:
Code:
Set shell = CreateObject("WScript.Shell")

crt.Session.LogUsingSessionOptions
Then, at the end:
Code:
crt.Session.Log False

strLogFile = crt.Session.LogFileName

' Open the file for viewing
shell.Run chr(34) & strLogFile & chr(34)
I am a noob when it come to vbs but I do try to figure it out. I am trying to create the time for the previous dialogue, but having issue.

there are 4 increments of 15 in 60 seconds.
60 seconds = 1 min * 60 = 1 hour
so I saw how you got the nInterations = 240

Adding that into a vbs did not work.


nInterval = 15 * 1000
nIterations = 240
For i = 0 to nIterations
' Run command
crt.Screen.Send "tmsh show sys connection cs-server-addr x.x.x.x" & chr(13)
crt.Sleep nInterval(240)

The script above says error on line 7, but there is not line 7.


nInterval = 15 * 1000
nIterations = 240
For i = 0 to nIterations
' Run command
crt.Screen.Send "tmsh show sys connection cs-server-addr x.x.x.x" & chr(13)
Loop Until crt.Screen.WaitForKey(15)
crt.Sleep nInterval(240)

The script above erros on line 6 frr the Loop Until

Any ideas on how I can get it work/run for only an Hour?
Reply With Quote
  #6  
Old 07-16-2019, 11:59 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,636
Hi melarnell,

You dropped the Next from the For/Next and I'm not sure what you are doing with the Sleep(). (To clarify, SecureCRT's Sleep() method uses milliseconds, thus the 15 * 1000.)

Here's a snippet of code:
Code:
Set shell = CreateObject("WScript.Shell")
crt.Session.LogUsingSessionOptions

nInterval = 15 * 1000
nIterations = 240

For i = 0 to nIterations
    ' Run command
    crt.Screen.Send "tmsh show sys connection cs-server-addr x.x.x.x" & chr(13)
    ' Sleep 15 seconds
    crt.Sleep nInterval
Next

crt.Session.Log False

strLogFile = crt.Session.LogFileName

' Open the file for viewing
shell.Run chr(34) & strLogFile & chr(34)
__________________
Thanks,
--Brenda

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

Last edited by bgagnon; 07-16-2019 at 01:02 PM. Reason: clarification of sleep()
Reply With Quote
Reply

Tags
vbs

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 05:31 AM.