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-26-2019, 10:31 PM
slouw slouw is offline
Registered User
 
Join Date: Nov 2005
Posts: 143
Error handler for failure to turn logging on

Is there a way to handle an error that occurs when turning on logging with an illegal filename?
I am having an error in a script when it turns on logging.
I want to work out a way to handle the error.
I tried checking if crt.GetScriptTab().Session.Log(True) returns a value but it does not seem to.

Thanks as always for any reply

Script fragment is below

Code:
LogFileStrNew = dirname + "\%Y-%M-%D %hh%mm%ss %S " + CommandStr + ".log"
writeB("00520 LogFileStrNew           :" + LogFileStrNew)
crt.Session.Config.SetOption("Log Filename", LogFileStrNew)
LogReturn = 0
writeB("00525 LogReturn Initialised   :" + str(LogReturn))
LogReturn = crt.GetScriptTab().Session.Log(True)
writeB("00527 LogReturn Return        :" + str(LogReturn))
Reply With Quote
  #2  
Old 06-27-2019, 10:10 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 3,942
Hi slouw,

This is more of a Python question than SecureCRT. You can typically use try/except blocks for error handling in Python.

Or, you might use existing script code Jake has in several example scripts to "clean up filenames". This block is from the RunCommandsOnMultipleHostsAndLogResults example.

Code:
                                # Replace any illegal characters that might have been
                                # introduced by the command we're running (e.g. if the
                                # command had a path or a pipe in it)
                                strCleanCmd = strCommand.replace('/', "[SLASH]")
                                strCleanCmd = strCleanCmd.replace('\\', "[BKSLASH]")
                                strCleanCmd = strCleanCmd.replace(':', "[COLON]")
                                strCleanCmd = strCleanCmd.replace( '*', "[STAR]")
                                strCleanCmd = strCleanCmd.replace( '?', "[QUESTION]")
                                strCleanCmd = strCleanCmd.replace( '"', "[QUOTE]")
                                strCleanCmd = strCleanCmd.replace( '<', "[LT]")
                                strCleanCmd = strCleanCmd.replace( '>', "[GT]")
                                strCleanCmd = strCleanCmd.replace( '|', "[PIPE]")
                                strLogFile = strLogFile.replace("COMMAND", strCleanCmd)
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #3  
Old 06-28-2019, 01:58 AM
slouw slouw is offline
Registered User
 
Join Date: Nov 2005
Posts: 143
Appreciate reply thank you Brenda
Line 524 on this file
RunCommandsOnMultipleHostsAndLogResults.py.txt
Has this line (extra backslash added to try and make [QUOTE] part of code. Failed.... :
Quote:
strCleanCmd = strCleanCmd.replace( '"', "\[QUOTE\]")
This was a workaround of sorts for me....
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 08:16 PM.