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-03-2021, 09:37 AM
CustomX CustomX is offline
Registered User
 
Join Date: Nov 2020
Posts: 2
Unhappy VBS to Python

Hi, I'm new on Mac platform, but I had been using SecureCRT for a couple of years.

I have a lot of scripts than I use in SecureCRT, thats scripts basically are plain text scripts, for database administration propuse but was called by VBS function.

I'm not programmer, and I am not familiar with python language.

Somebody can help me to translate this block of code to python in order to allow to use my personal scripts in securecrt in mac?

Thanks a lot in advance regarding this and sorry in advance if this not a proper request in this thread.

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

' Script to open a text file and read it line by
' line to a server.

' Constants used by OpenTextFile()
'
Const ForReading = 1
Const ForWriting = 2


Sub Main
  crt.Screen.Synchronous = True
  
  Dim fso, file
  
  Set fso = CreateObject("Scripting.FileSystemObject")

  ' Open a file for writing. The last True parameter causes the file
  ' to be created if it doesn't exist.
  ' strFile = crt.Arguments(0)
  strFile = "F:\SecureCRT\sqlScripts\DBA_Feature_usage.sql"
  Set file = fso.OpenTextFile(strFile, ForReading, False)
 
  Do While file.AtEndOfStream <> True

    str = file.Readline
    crt.Screen.Send str & Chr(13)
    
  Loop

  crt.Screen.Synchronous = False

End Sub
Reply With Quote
  #2  
Old 06-03-2021, 01:33 PM
cboyack cboyack is offline
VanDyke Technical Support
 
Join Date: Apr 2020
Location: Albuquerque, NM
Posts: 132
I've moved your post to a new thread since this is a new issue.

Regarding your request for script translation services, VanDyke Software does not offer script translation as part of our technical support offering. If any other members of the community want to chime in on this and provide translation on their own, they are welcome to do so.

We actually have an example script (SendFile.py) on our Example Python Scripts for SecureCRT® for Windows and Mac webpage that essentially performs the task that you're looking for via a python script.

You may want to trim that particular script a bit, since the cat command at the start of the script isn't needed, and neither is the EOF, since you won't be using cat command. Of course, you'll also want to modify the file to which the for option pointed, but aside from that, the script opens a file and reads it, line by line, to the remote system.
__________________
Thanks,
--Cameron

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #3  
Old 06-05-2021, 10:23 AM
gregg gregg is offline
Registered User
 
Join Date: Oct 2010
Posts: 66
This should be an adequate replacement for the mentioned script.

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

# Script to open a text file and read it line by
# line to a server.

DEFAULT_FILENAME = r"F:\SecureCRT\sqlScripts\DBA_Feature_usage.sql"

def main():
    # filename = crt.Dialog.Prompt("Filename to read:", "Filename", DEFAULT_FILENAME, False)
    filename = crt.Dialog.FileOpenDialog("Text file", "Open", DEFAULT_FILENAME, "SQL Files (*.sql)|*.sql|All Files (*.*)|*.*|")

    if not filename:
        # escape pressed or no filename entered
        return

    crt.Screen.Synchronous = True
    try:
        # Open a file for reading.
        with open(filename, "rt") as fh:
            for line in fh:
                crt.Screen.Send(line.rstrip() + "\r")
    except FileNotFoundError:
        crt.Dialog.MessageBox("Could not open file %s" % filename, "File not found")
    finally:
        crt.Screen.Synchronous = False
    
main()
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 11:53 AM.