Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Notices

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 08-30-2012, 04:05 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,305
Post Example: Read Data From Separate Hosts/Commands File And Log To Individual Files

Demonstrates how to connect to hosts read in from a "hosts" file and for each host, send a list of commands read in from a "commands" file. Results of each command run are (by default) logged to separate, uniquely-named files based on the host address and the command that is run. However, the script code is architected to allow you to change this behavior so that it's all logged to one file per host, or even just to a single file.

Download the example scripts:
Python Version (for use on Mac/Linux/Windows versions of SecureCRT):
RunCommandsOnMultipleHostsAndLogResults.py.txt
Last updated: 08 Jun, 2021

VBScript Version (for use on Windows versions of SecureCRT):
RunCommandsOnMultipleHostsAndLogResults.vbs.txt
Last updated: 21 May, 2018 (this script is no longer being updated/maintained)

Example ##hosts.txt and ##commands.txt files:
The following show you the format of what the ##hosts.txt and ##commands.txt files would look like.The ##hosts.txt file can contain host-specific command file directives, which is what the ##DeviceType1Commands.txt and ##DeviceType2Commands.txt files exemplify.



.
Attached Files
File Type: txt RunCommandsOnMultipleHostsAndLogResults.vbs.txt (45.7 KB, 22314 views)
File Type: txt RunCommandsOnMultipleHostsAndLogResults.py.txt (47.2 KB, 17484 views)
File Type: txt ##hosts.txt (1.1 KB, 15867 views)
File Type: txt ##commands.txt (575 Bytes, 15668 views)
File Type: txt ##DeviceType1Commands.txt (396 Bytes, 14851 views)
File Type: txt ##DeviceType2Commands.txt (399 Bytes, 13888 views)

Last edited by jdev; 02-02-2022 at 03:27 PM. Reason: Explain that VBScript version is no longer being updated/maintained.
Reply With Quote
  #2  
Old 09-06-2012, 03:21 PM
Levittown Levittown is offline
Registered User
 
Join Date: Aug 2012
Posts: 7
help!

Todd:

Also, is there is a way to stop the output from pausing? For instace, if the command output is too long, it will not complte the log file unless I manually press the enter key until the output is completed.

Thank you
Reply With Quote
  #3  
Old 09-06-2012, 04:14 PM
Levittown Levittown is offline
Registered User
 
Join Date: Aug 2012
Posts: 7
help!

Also,

The first host execute the command, but on the second host, I get the following error:

CRT Scripting Runtime error
Error: Sreen.CurrentRow: not connected
Line 186 which points to the following line of code:
nRow = crt.Screen.CurrentRow
Reply With Quote
  #4  
Old 09-06-2012, 06:26 PM
miked's Avatar
miked miked is offline
Registered User
 
Join Date: Feb 2004
Posts: 2,039
Quote:
The first host execute the command, but on the second host, I get the following error:

CRT Scripting Runtime error
Error: Sreen.CurrentRow: not connected
Line 186 which points to the following line of code:
nRow = crt.Screen.CurrentRow
SecureCRT is not connected at that point. You need to be connected to the server before using crt.Screen.CurrentRow. I think there's probably much more going on here than we know yet, and should see a log file.

Quote:
Also, is there is a way to stop the output from pausing?
Can you send a SecureCRT raw log file showing the output pausing?

To create a raw log:
  1. Before connecting with the session, select "Raw Log Session" from SecureCRT's "File" menu.
  2. In the "Select Log File" dialog, choose a folder and filename in which you would like the log text to be stored and press the "Save" button. At this point, if you open the "File" menu, you will notice that the "Raw Log Session" menu item now has a check-mark next to it; this indicates that raw logging is activated.
  3. Now connect to the remote machine and perform the actions which cause the reported problem to occur.
  4. Once the problem occurs, disconnect the session and select "Raw Log Session" from the "File" menu to turn off the raw logging feature.
  5. Browse to the location of the raw log file and add the file as an attachment to your e-mail reply.
__________________
Mike
VanDyke Software
Technical Support
[http://www.vandyke.com/support]
Reply With Quote
  #5  
Old 09-08-2012, 12:18 PM
Levittown Levittown is offline
Registered User
 
Join Date: Aug 2012
Posts: 7
I follow your instructions, but the log is empty. I can clearly see that secrteCRT connects to the second host, but it doesnt issue a command, and then I get the error...

Quote:
Originally Posted by miked View Post
SecureCRT is not connected at that point. You need to be connected to the server before using crt.Screen.CurrentRow. I think there's probably much more going on here than we know yet, and should see a log file.

Can you send a SecureCRT raw log file showing the output pausing?

To create a raw log:
  1. Before connecting with the session, select "Raw Log Session" from SecureCRT's "File" menu.
  2. In the "Select Log File" dialog, choose a folder and filename in which you would like the log text to be stored and press the "Save" button. At this point, if you open the "File" menu, you will notice that the "Raw Log Session" menu item now has a check-mark next to it; this indicates that raw logging is activated.
  3. Now connect to the remote machine and perform the actions which cause the reported problem to occur.
  4. Once the problem occurs, disconnect the session and select "Raw Log Session" from the "File" menu to turn off the raw logging feature.
  5. Browse to the location of the raw log file and add the file as an attachment to your e-mail reply.
Reply With Quote
  #6  
Old 03-05-2013, 01:12 PM
joeboy joeboy is offline
Registered User
 
Join Date: Mar 2013
Posts: 1
Is there a python version of this example? Thanks!
Reply With Quote
  #7  
Old 03-05-2013, 02:02 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,305
Hi joeboy,

Thanks for the question. I have one in the works, but it is not yet complete. I will post here when it is.
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #8  
Old 03-20-2013, 09:50 AM
Elder's Avatar
Elder Elder is offline
Registered User
 
Join Date: May 2004
Posts: 2
I second the req for a python version. Well done RTB!
Reply With Quote
  #9  
Old 03-20-2013, 10:05 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,636
Hi Elder,

Todd (RTB) is not available.

I will make sure he knows you "second the motion".
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #10  
Old 04-24-2013, 02:18 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,305
Hi All,

I have finally finished my Python port of the VBScript version of this script. Have at it.
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730

Last edited by rtb; 06-05-2013 at 03:00 PM.
Reply With Quote
  #11  
Old 10-10-2013, 12:53 PM
quinj quinj is offline
Registered User
 
Join Date: Oct 2013
Posts: 4
Is the Python program will work for Windows 7 too?
Reply With Quote
  #12  
Old 10-10-2013, 12:58 PM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,636
Hi quinj,

Yes, SecureCRT is capable of hosting "ActiveX Script" engines. Python scripts can be run in SecureCRT/Windows.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #13  
Old 10-10-2013, 01:58 PM
quinj quinj is offline
Registered User
 
Join Date: Oct 2013
Posts: 4
I apologize, the python program on this thread can be used in Windows 7. Looking at it inside, it all shows Windows XP.

Thanks
quinj
Reply With Quote
  #14  
Old 07-17-2014, 03:07 PM
hvh2000 hvh2000 is offline
Registered User
 
Join Date: Jul 2014
Posts: 4
Hi, I'm using this excellent script. I have a noob question - as it is the script saves the configuration files using the IP address in the filename, I am using fqdn's to connect to the devices, so am curious how one would modify it so that the file name reflects what was passed to the script in the hosts.txt file instead of the IP. There may be cases where I use an IP, but if I use an fqdn, I'd prefer the output file to use it as well.
Reply With Quote
  #15  
Old 07-17-2014, 03:32 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,305
Hi hvh2000,

Thanks for the post. It seems like you are using the VBScript version. If I am wrong, please correct me because the log file code is different between the VBScript and Python versions.

In the VBScript code starting on line 257, the IPADDRESS portion of the template name gets replaced with the IP address (g_objNewTab.Session.RemoteAddress). Line 260 could be modified to use g_strhost which is obtained on line 136 from the host file.

Does this help you accomplish your goal?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
Reply

Tags
example script

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:31 PM.