#1
|
|||
|
|||
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) |
#2
|
|||
|
|||
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:
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 |
#3
|
|||
|
|||
![]() Quote:
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. |
#4
|
|||
|
|||
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 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 |
#5
|
|||
|
|||
Quote:
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? |
#6
|
|||
|
|||
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() |
![]() |
Tags |
vbs |
Thread Tools | |
Display Modes | |
|
|