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-22-2020, 09:30 PM
E.Young E.Young is offline
Registered User
 
Join Date: May 2020
Posts: 4
crt.Session.LogFileName problem at ubuntu 18.04

hello all,

here is my script:

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

logfilename = crt.Dialog.Prompt('INPUT THE LOG FILE NAME:', 'SAVE LOG', '', False)

# crt.Session.LogFileName = "./%M-%D-%Y-" + str(logfilename) + ".log" # FOR LINUX
crt.Session.LogFileName = ".\%M-%D-%Y-" + str(logfilename) + ".log"  # FOR WIN

crt.Session.Log(True)
crt.Screen.Synchronous = True

for command in cmdList:
    crt.Screen.Send(command + '\r')
    crt.Screen.WaitForString(wtf)

crt.Session.Log(False)
crt.Screen.Synchronous = False
at win10, the code FOR WIN runs perfect.
however at ubuntu 18.04, the code FOR LINUX doesnt work(I have deleted the '#' for sure).

what shuld i do to fix the script?
thanks!
Reply With Quote
  #2  
Old 06-23-2020, 09:47 AM
cboyack cboyack is offline
VanDyke Technical Support
 
Join Date: Apr 2020
Location: Albuquerque, NM
Posts: 25
Hi E.Young,

In order for me to get a better idea of what's going on with regards to the script, I'm going to need a little more information than "doesn't work".
  • Is there an error message that you're seeing when the script is run on the Linux machine?
    • If so, what is the exact text of the error message?
  • What specific behavior are you seeing, and how does this differ from what you expect the behavior of the script to be?
  • What specific steps are you taking/following from the time you start SecureCRT to the time where you observe the unexpected behavior you've described?
__________________
Thanks,
--Cameron

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #3  
Old 06-23-2020, 08:13 PM
E.Young E.Young is offline
Registered User
 
Join Date: May 2020
Posts: 4
Quote:
Originally Posted by cboyack View Post
Hi E.Young,

In order for me to get a better idea of what's going on with regards to the script, I'm going to need a little more information than "doesn't work".
  • Is there an error message that you're seeing when the script is run on the Linux machine?
    • If so, what is the exact text of the error message?
  • What specific behavior are you seeing, and how does this differ from what you expect the behavior of the script to be?
  • What specific steps are you taking/following from the time you start SecureCRT to the time where you observe the unexpected behavior you've described?

sorry I didnt describ it clearly.

at win10, the script runs well, the output log is logged at the same file folder.

while run the script at linux SecureCRT, the output cannot be logged at anywhere.

what should I do to fix the script? and if I wanna run the script at MAC OS, what should I do?

thanks!
Reply With Quote
  #4  
Old 06-24-2020, 08:11 AM
cboyack cboyack is offline
VanDyke Technical Support
 
Join Date: Apr 2020
Location: Albuquerque, NM
Posts: 25
Hi E.Young,

Without direct answers to each of these questions, it will be impossible for us to find any solutions to your issue.
  • Is there an error message that you're seeing when the script is run on the Linux machine?
    • If so, what is the exact text of the error message?
  • What exact behavior are you seeing when running the edited script on your Linux machine, and how does this differ from what you expect the behavior of the script to be?
  • What specific steps are you taking/following from the time you start SecureCRT to the time where you observe the unexpected behavior you've described?
__________________
Thanks,
--Cameron

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #5  
Old 06-27-2020, 08:33 PM
E.Young E.Young is offline
Registered User
 
Join Date: May 2020
Posts: 4
Quote:
Originally Posted by cboyack View Post
Hi E.Young,

Without direct answers to each of these questions, it will be impossible for us to find any solutions to your issue.
  • Is there an error message that you're seeing when the script is run on the Linux machine?
    • If so, what is the exact text of the error message?
  • What exact behavior are you seeing when running the edited script on your Linux machine, and how does this differ from what you expect the behavior of the script to be?
  • What specific steps are you taking/following from the time you start SecureCRT to the time where you observe the unexpected behavior you've described?
[*]Is there an error message that you're seeing when the script is run on the Linux machine?

no, there is no message was shown when the script running on linux.
[*]What exact behavior are you seeing when running the edited script on your Linux machine, and how does this differ from what you expect the behavior of the script to be?

the script on win and linux is almost the same, the only difference is that on win the script will log file correctly and on linux the script will not.
[*]What specific steps are you taking/following from the time you start SecureCRT to the time where you observe the unexpected behavior you've described?

after running the script there is no output log.



and I have a new question:
Code:
crt.Dialog.FileOpenDialog()
load a file from local machine, how can I get the name of the selected file? I wanna use the name of the selected file as log file name. what should I do?

here is my full code:

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


def loadCmdTxt():
    cmdFile = crt.Dialog.FileOpenDialog("SELECT THE COMMAND FILE", "OPEN", "", "TXT Files (*.txt)|*.txt")
    with open(cmdFile) as f:
        commands = f.readlines()
        commandList = []
        for command in commands:
            commandList.append(command.strip())
    return commandList


def runCmd(cmdList):
    wtf = crt.Dialog.Prompt('INPUT THE WAITFORSTRING WORD :', 'INPUT THE WAITFORSTRING WORD :', '', False)

    logfilename = crt.Dialog.Prompt('INPUT THE LOG FILE NAME:', 'SAVE LOG', '', False)
    # crt.Session.LogFileName = "./%M-%D-%Y-" + str(logfilename) + ".log" # FOR LINUX
    crt.Session.LogFileName = ".\%M-%D-%Y-" + str(logfilename) + ".log"  # FOR WIN

    crt.Session.Log(True)
    crt.Screen.Synchronous = True
    
    for command in cmdList:
        crt.Screen.Send(command + '\r')
        crt.Screen.WaitForString(wtf)

    crt.Session.Log(False)
    crt.Screen.Synchronous = False


runCmd(loadCmdTxt())

crt.Dialog.MessageBox('DONE!')
Reply With Quote
  #6  
Old 06-29-2020, 03:38 PM
cboyack cboyack is offline
VanDyke Technical Support
 
Join Date: Apr 2020
Location: Albuquerque, NM
Posts: 25
Hi E.Young,

Thanks for sharing that information!

My guess is that "." doesn't mean the same thing for you on your Linux as it does for you on your Windows machine. I would suspect that since the script runs to completion on your Linux machine, that the log files do exist, they just don't exist where you're currently expecting them to reside.

If, instead of using ".", you dynamically determine a valid path which you can use to build a corresponding absolute path for your log files, does the script then work for you regardless of the platform?

For example, instead of:

Code:
    logfilename = crt.Dialog.Prompt('INPUT THE LOG FILE NAME:', 'SAVE LOG', '', False)
    # crt.Session.LogFileName = "./%M-%D-%Y-" + str(logfilename) + ".log" # FOR LINUX
    crt.Session.LogFileName = ".\%M-%D-%Y-" + str(logfilename) + ".log"  # FOR WIN
you would do this:

Code:
    logfilename = crt.Dialog.Prompt('INPUT THE LOG FILE NAME:', 'SAVE LOG', '', False)
    import os
    strFolder = os.path.expanduser("~") + "/Desktop"
    crt.Session.LogFileName = strFolder + "/%M-%D-%Y-" + str(logfilename) + ".log" # FOR ALL
    # Display the filename and directory separately
    #crt.Dialog.MessageBox("filename: {}\r\ndirectory: {}".format(
    #    os.path.basename(crt.Session.LogFileName),
    #    os.path.dirname((crt.Session.LogFileName).replace("\\","/"))))

I'm not sure I understand your "new" question.

What problem are you trying to solve? Do you want to use the name of the file but not the full name + path?

If so, note the commented code in the block above. If not, please clarify further.
__________________
Thanks,
--Cameron

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #7  
Old 07-05-2020, 01:01 AM
E.Young E.Young is offline
Registered User
 
Join Date: May 2020
Posts: 4
Quote:
Originally Posted by cboyack View Post
Hi E.Young,

Thanks for sharing that information!

My guess is that "." doesn't mean the same thing for you on your Linux as it does for you on your Windows machine. I would suspect that since the script runs to completion on your Linux machine, that the log files do exist, they just don't exist where you're currently expecting them to reside.

If, instead of using ".", you dynamically determine a valid path which you can use to build a corresponding absolute path for your log files, does the script then work for you regardless of the platform?

For example, instead of:

Code:
    logfilename = crt.Dialog.Prompt('INPUT THE LOG FILE NAME:', 'SAVE LOG', '', False)
    # crt.Session.LogFileName = "./%M-%D-%Y-" + str(logfilename) + ".log" # FOR LINUX
    crt.Session.LogFileName = ".\%M-%D-%Y-" + str(logfilename) + ".log"  # FOR WIN
you would do this:

Code:
    logfilename = crt.Dialog.Prompt('INPUT THE LOG FILE NAME:', 'SAVE LOG', '', False)
    import os
    strFolder = os.path.expanduser("~") + "/Desktop"
    crt.Session.LogFileName = strFolder + "/%M-%D-%Y-" + str(logfilename) + ".log" # FOR ALL
    # Display the filename and directory separately
    #crt.Dialog.MessageBox("filename: {}\r\ndirectory: {}".format(
    #    os.path.basename(crt.Session.LogFileName),
    #    os.path.dirname((crt.Session.LogFileName).replace("\\","/"))))

I'm not sure I understand your "new" question.

What problem are you trying to solve? Do you want to use the name of the file but not the full name + path?

If so, note the commented code in the block above. If not, please clarify further.

Thanks a lot cboyack!
the code: os.path.expanduser"~" works perfect on my linux.

and the new question, yes I wanna get the name string of the file, using as the log file name. the code: os.path.basename(crt.Session.LogFileName) is exactly what I want.

Thank you very much!
Reply With Quote
  #8  
Old 07-05-2020, 06:42 PM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,359
Hi E.Young,

Cameron is not available, but it sounds like your issues are resolved. I am glad to hear it.
__________________
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 04:46 AM.