#1
|
|||
|
|||
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 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! |
#2
|
|||
|
|||
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".
__________________
Thanks, --Cameron VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
#3
|
|||
|
|||
Quote:
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! |
#4
|
|||
|
|||
Hi E.Young,
Without direct answers to each of these questions, it will be impossible for us to find any solutions to your issue.
__________________
Thanks, --Cameron VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
#5
|
|||
|
|||
Quote:
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() 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!') |
#6
|
|||
|
|||
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 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 |
#7
|
|||
|
|||
Quote:
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! |
#8
|
|||
|
|||
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 |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Display Modes | Rate This Thread |
|
|