Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rate Thread Display Modes
  #16  
Old 10-11-2016, 11:33 AM
corp-mule corp-mule is offline
Registered User
 
Join Date: Mar 2006
Posts: 21

I have the same problem. And the solution within this thread did not resolve it.

I'm trying to capture the output of the "sh run" command on a Cisco router. The output is a little bit over 4400 lines. But the log file only has a little over 1850.

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

' **************************************
' **************************************
'     WARNING - WARNING - WARNING
' **************************************
' **************************************
'
' This script works ... BUT ...
'
' The log file does not contain *ALL* the output!!!
'
' I have not been able to find the cause or solution.
'
' This URL addresses the issue but, the solution
' within this thread, does not solve the problem for me.
'
' Logging long output issue - VanDyke Software Forums
' https://forums.vandyke.com/showthread.php?t=11908
'
' **************************************
' **************************************

' This script will ...
'
' - Stop the current (generic session)
'   logfile

' - Then starts a new logfile to capture
'   output from specific "show comamnds"

' - Then, stop the "specific logfile"

' - Then start a new generic session
'   logfile.
'

  ' Turn on synchronous mode while performing Send/Wait sequences
  ' so no input is missed.
  '
  crt.Screen.Synchronous = True
'

' Specify a log file name that is time-stamped (with legal
' filename characters). This way, the files can be sorted
' easily within Windows Explorer.
'
' crt.Session.LogFileName = _
'
' "C:\Temp\Logs\%Y-%M-%D--%h-%m-%s.%t-%S(%H).txt"


Sub Main

' If you are unsure whether or not logging has been enabled
' already, you can determine this programmatically with an
' If statement within your script code:

'If crt.Session.Logging <> True Then
'crt.Session.Log True
'End If

' If at any point within your script code, you desire to
' turn off logging, simply use the Session.Log method,
' providing an argument of False. For example:
'
' crt.Session.Log False
'
' If logging is already enabled, and you want to ensure that
' specific log settings are active (using a specific log
' file name, append vs. overwrite, etc.), then you may want
' to stop the logging process, configure log settings within
' your script, and then enable logging as per your
' requirements. For example:
'
' --- If crt.Session.Logging Then
' --- ' Turn off logging before setting up our script's
' --- ' logging...
' --- crt.Session.Log False
' --- End If
'
' If using a pre-configured session ...
'
If crt.Session.Logging Then
'
' Turn off logging before setting up our script's logging...
'
crt.Session.Log False
End If
'
' Set up the log file so that it resides in the path
' defined in the TEMP environment variable, and is
' named according to the remote IP address:
'
' crt.Session.LogFileName = "%TEMP%\" & _
' "LogFileForIP(" & crt.Session.RemoteAddress & ").txt"
' crt.Session.LogUsingSessionOptions
'
' I:\files\logs\securecrt\%H--%M-%D--%h-%m.log
crt.Session.LogFileName = "I:\files\logs\securecrt\" & _
"sh-run---%S--%M-%D--%h-%m.log"
crt.Session.LogUsingSessionOptions
'
' Send commands, etc.
' ...
'
' Get hostname from session
Set objTab = crt.GetScriptTab()
Set objConfig = objTab.Session.Config
strHostname = objConfig.GetOption("Hostname")
strPrompt = strHostname & "#"


''''''''''''''''''''''''''''''''''''''''
        CRT.Screen.SendSpecial "MENU_CLEAR_SCREEN_AND_SCROLLBACK"
        'CRT.Screen.SendSpecial "MENU_CLEAR_SCROLLBACK"
	crt.Screen.Send "!" & chr(13)
	
	crt.Screen.WaitForStrings strPrompt, "#"
	crt.Screen.Send "term len 0" & chr(13)
 	crt.Screen.WaitForStrings strPrompt, "#"
	crt.Screen.Send "!" & chr(13)

	crt.Screen.WaitForStrings strPrompt, "#"
	crt.Screen.Send "sh clock" & chr(13)

	crt.Screen.WaitForStrings strPrompt, "#"
	crt.Screen.Send "!" & chr(13)

	crt.Screen.WaitForStrings strPrompt, "#"
	crt.Screen.Send "!" & chr(13)

	crt.Screen.WaitForStrings strPrompt, "#"
	crt.Screen.Send "sh run" & chr(13)

	crt.Screen.WaitForStrings strPrompt, "#"
	crt.Screen.Send "!" & chr(13)

	crt.Screen.WaitForStrings strPrompt, "#"
	crt.Screen.Send "!" & chr(13)

	crt.Screen.WaitForStrings strPrompt, "#"
	crt.Screen.Send "!" & chr(13)

	crt.Screen.WaitForStrings strPrompt, "#"
	crt.Screen.Send "!" & chr(13)

	crt.Screen.WaitForStrings strPrompt, "#"
	crt.Screen.Send "sh clock" & chr(13)

	crt.Screen.WaitForStrings strPrompt, "#"
	crt.Screen.Send "!" & chr(13)

	crt.Screen.WaitForStrings strPrompt, "#"
	crt.Screen.Send "term len 24" & chr(13)

	crt.Screen.WaitForStrings strPrompt, "#"
	crt.Screen.Send "!" & chr(13)

	crt.Screen.WaitForStrings strPrompt, "#"
	crt.Screen.Send "!" & chr(13)

	crt.Screen.WaitForStrings strPrompt, "#"
	crt.Screen.Send "!" & chr(13)

	crt.Screen.WaitForStrings strPrompt, "#"
	' 900000 = 15 minutes
	' 1800000 = 30 minutes
	' 3600000 = 1 hour
        'crt.Sleep 900000



''''''''''''''''''''''''''''''''''''''''
'
' Turn off synchronous mode
crt.Screen.Synchronous = false
'
' Stop logging
'
'crt.Session.Log False
'
' Perform other script work, or setup on the remote for the
' next batch of logging...
' ...
' Start logging again (be sure to append or else we'll
' overwrite the data we've logged so far).
'
'crt.Session.Log True, True
'
'
' If using a pre-configured session ...
'
If crt.Session.Logging Then
'
' Turn off logging before setting up our script's logging...
'
crt.Session.Log False
End If
'
' Turn on logging;
'
	crt.Screen.Send "!" & chr(13)

	crt.Screen.WaitForStrings strPrompt, "#"
	crt.Screen.Send "!" & chr(13)

	crt.Screen.WaitForStrings strPrompt, "#"
	'crt.Sleep 5000
crt.Session.LogFileName = "I:\files\logs\securecrt\" & _
"%S--%M-%D--%h-%m.log"
crt.Session.LogUsingSessionOptions
'crt.Screen.WaitForStrings strPrompt, "#", 5
'crt.Sleep 5000
'
'
' Send more commands, etc.
' ...
' ...
End Sub
Reply With Quote
  #17  
Old 10-11-2016, 01:28 PM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,635
Hi corp-mule,

Quote:
I'm trying to capture the output of the "sh run" command on a Cisco router. The output is a little bit over 4400 lines. But the log file only has a little over 1850.
Is it the first 1850 lines? Or the last 1850 lines? (Or are parts of the output being missed?)

What is the session's logging configuration?

Please list the explicit steps you are taking to run the script.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #18  
Old 10-11-2016, 03:25 PM
corp-mule corp-mule is offline
Registered User
 
Join Date: Mar 2006
Posts: 21
It's the first 1850 lines.

You said ...

Quote:
What is the session's logging configuration?
The session is logging to a directory.
i:\files\logs\securecrt\<log-file-here>

I've run the script two different ways.

1. I used the menu to run it manually:
script > run > nav-to-the-file-location-and-choose-the-file

2. I mapped a "key" (ctrl-1).

I hope I answered your questions.

thanks.
Reply With Quote
  #19  
Old 10-11-2016, 03:36 PM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,635
Hi corp-mule,

What version of SecureCRT are you using?

On what OS?

You are using LogUsingSessionOptions.

Please provide info about the logging configuration in the session.

So does the script complete successfully?

Or is Cancel available in the Script menu? (If so and you choose Cancel, what line of the script does it indicate as the issue?)
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #20  
Old 10-11-2016, 03:58 PM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,635
Hi corp-mule,

I have some further insight from our scripting guru:
  • If out of sync, logging will stop at the point where Session.Log = False (which may very well be before all of the output arrives)

  • Considering that the script is using a WaitForStrings(strPrompt, "#"), that means that an errant "#" character anywhere in the output of a command (not part of the shell prompt) could result in getting out of sync

  • For troubleshooting purposes, use ReadString() instead of WaitForStrings(), and write the results of each ReadString(strPrompt, "#") to a separate log file so you can potentially determine where the script is getting out of sync
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #21  
Old 10-11-2016, 04:09 PM
corp-mule corp-mule is offline
Registered User
 
Join Date: Mar 2006
Posts: 21


Quote:
What version of SecureCRT are you using?
Version 7.2.3 (x64 build 500)

Quote:
On what OS?
Window Server 2008 R2
Version 6.1 (Build 7601: Service Pack 1)

Quote:
You are using LogUsingSessionOptions.
I'm not sure what you're asking of me here.

I have the logging configured in the "default session."

Does that answer your question?

Quote:
Please provide info about the logging configuration in the session.
I:\files\logs\securecrt\%S--%M-%D--%h-%m.log

Quote:
So does the script complete successfully?
Yes. The entire script runs and, all the output is veiwable and available in the application window.

Quote:
Or is Cancel available in the Script menu? (If so and you choose Cancel, what line of the script does it indicate as the issue?)
Cancel is available if I nav to it fast enough.

When I cancel the script, I see a dialog box that tells me it was cancelled and, which line it was on when I cancelled it.

But no errors.

Reply With Quote
  #22  
Old 10-12-2016, 07:42 AM
corp-mule corp-mule is offline
Registered User
 
Join Date: Mar 2006
Posts: 21
Quote:
Originally Posted by bgagnon View Post
Hi corp-mule,

I have some further insight from our scripting guru:
  • If out of sync, logging will stop at the point where Session.Log = False (which may very well be before all of the output arrives)

  • Considering that the script is using a WaitForStrings(strPrompt, "#"), that means that an errant "#" character anywhere in the output of a command (not part of the shell prompt) could result in getting out of sync

  • For troubleshooting purposes, use ReadString() instead of WaitForStrings(), and write the results of each ReadString(strPrompt, "#") to a separate log file so you can potentially determine where the script is getting out of sync



Isn't that what this code is supposed to compensate for?

' Get hostname from session
Set objTab = crt.GetScriptTab()
Set objConfig = objTab.Session.Config
strHostname = objConfig.GetOption("Hostname")
strPrompt = strHostname & "#"


Reply With Quote
  #23  
Old 10-12-2016, 10:01 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,635
Hi corp-mule,

No, that is simply setting the prompt variable to be hostname# (meaning the hostname or IP address supplied for the connection).

You are also "waiting for" just #, so if the output of any command you run includes a lone #, the WaitForStrings() call will be triggered when not expected.

I think the troubleshooting tip in the third bullet point is going to be the best resource to find out where your script is out of sync.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #24  
Old 10-12-2016, 02:56 PM
corp-mule corp-mule is offline
Registered User
 
Join Date: Mar 2006
Posts: 21


I see. I misunderstood the solution provided in this thread (above).

I know my output *does* include the "#" symbol within it. That's why I *thought* the solution mentioned above would help.

Now I just need to figure out how to work around that. Do you have any ideas?

Did I use this thread's solution improperly? If so, how, or where in the script, should I use it?

Reply With Quote
  #25  
Old 10-12-2016, 03:07 PM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,635
Hi corp-mule,

Why don't you check out the example scripts here?

I think you might find this one useful for the task you are trying to accomplish.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #26  
Old 10-13-2016, 09:08 AM
corp-mule corp-mule is offline
Registered User
 
Join Date: Mar 2006
Posts: 21


I gave it a quick glance. The titles of the files indicate that it might do what I want. But, as I looked at the files ... I'll *_never_* be able to troubleshoot them if something goes wrong. laffs ... I can't even figure out this simple script.

So ... on this script ... why was the solution suggested if it doesn't compensate for the output containing the "wait for string?" I thought it was supposed to make the script "wait for" the host's prompt, which contains the host's (or sessions) name?

' Get hostname from session
Set objTab = crt.GetScriptTab()
Set objConfig = objTab.Session.Config
strHostname = objConfig.GetOption("Hostname")
strPrompt = strHostname & "#"


Should I change the "wait for string" to match the code in the solution?

So ... change ...

crt.Screen.WaitForStrings strPrompt, "#"

to ...

crt.Screen.WaitForStrings strHostname & "#"




Reply With Quote
  #27  
Old 10-13-2016, 09:58 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,635
Hi corp-mule,

Sansone was looking for a way to make his script useful when connecting to any number of hosts. In other words, he wanted a dynamic way of determining the host's shell prompt. I believe the suggestion was given to solve that problem but more than one issue has been discussed in this thread.

What problem are you trying to solve?
__________________
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 02:31 AM.