VanDyke Software Forums

VanDyke Software Forums (https://forums.vandyke.com/index.php)
-   Scripting (https://forums.vandyke.com/forumdisplay.php?f=14)
-   -   Example: Read Data From Separate Hosts/Commands File And Log To Individual Files (https://forums.vandyke.com/showthread.php?t=10651)

rtb 08-30-2012 04:05 PM

Example: Read Data From Separate Hosts/Commands File And Log To Individual Files
 
6 Attachment(s)
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 versions of SecureCRT):
RunCommandsOnMultipleHostsAndLogResults.py.txt
Last updated: 21 May, 2018 (initial revision)

VBScript Version (for use on Windows versions of SecureCRT):
RunCommandsOnMultipleHostsAndLogResults.vbs.txt
Last updated: 21 May, 2018

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.



.

Levittown 09-06-2012 03:21 PM

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

Levittown 09-06-2012 04:14 PM

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
:(

miked 09-06-2012 06:26 PM

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.

Levittown 09-08-2012 12:18 PM

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 (Post 37341)
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.


joeboy 03-05-2013 01:12 PM

Is there a python version of this example? Thanks!

rtb 03-05-2013 02:02 PM

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.

Elder 03-20-2013 09:50 AM

I second the req for a python version. Well done RTB!

bgagnon 03-20-2013 10:05 AM

Hi Elder,

Todd (RTB) is not available.

I will make sure he knows you "second the motion". :)

rtb 04-24-2013 02:18 PM

Hi All,

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

quinj 10-10-2013 12:53 PM

Is the Python program will work for Windows 7 too?

bgagnon 10-10-2013 12:58 PM

Hi quinj,

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

quinj 10-10-2013 01:58 PM

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

hvh2000 07-17-2014 03:07 PM

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.

rtb 07-17-2014 03:32 PM

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?


All times are GMT -6. The time now is 01:38 AM.