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 08-30-2012, 05:05 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
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 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.



.
Attached Files
File Type: txt ##hosts.txt (1.1 KB, 2305 views)
File Type: txt RunCommandsOnMultipleHostsAndLogResults.vbs.txt (44.4 KB, 5482 views)
File Type: txt ##commands.txt (575 Bytes, 2316 views)
File Type: txt ##DeviceType1Commands.txt (396 Bytes, 1828 views)
File Type: txt ##DeviceType2Commands.txt (399 Bytes, 1637 views)
File Type: txt RunCommandsOnMultipleHostsAndLogResults.py.txt (45.9 KB, 2424 views)

Last edited by jdev; 05-23-2018 at 02:50 PM. Reason: Update VBScript code and post newly-available Python version
Reply With Quote
  #2  
Old 09-06-2012, 04: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, 05: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, 07:26 PM
miked's Avatar
miked miked is offline
Registered User
 
Join Date: Feb 2004
Posts: 2,040
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, 01: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, 02: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 10-22-2014, 02:08 PM
iabudi iabudi is offline
Registered User
 
Join Date: Oct 2014
Posts: 4
Using Python Script

Quote:
Originally Posted by rtb View Post
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 logged to separate, uniquely-named files based on the host address and the command that is run.
who do I fix he login to into a cisco like the follwoing

telnet 1.1.1.1
password: ********
cisco> enable
password : *******
Cisco#

if we can't get a solution
how can I ignore the prompt change.

Thanks
Reply With Quote
  #8  
Old 10-22-2014, 06:04 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi iabudi,

Thanks for the post. What errors can you get if enable fails?

What error do you see if the password is invalid?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #9  
Old 11-19-2014, 02:15 PM
iabudi iabudi is offline
Registered User
 
Join Date: Oct 2014
Posts: 4
Python Script

Quote:
Originally Posted by rtb View Post
Hi iabudi,

Thanks for the post. What errors can you get if enable fails?

What error do you see if the password is invalid?
I resolved the login issue by adding all the commands under the username


but I am running into a new issue where it runs the first command then stops at the prompt and when I stop the script it tells me its stoped at line 399

# Wait for the command to be echo'd back to us.
g_objNewTab.Screen.WaitForString(strCommand + "\r\n")

The window shows: Router-name#

I not sure what is the script looking for?

Thanks
Reply With Quote
  #10  
Old 11-19-2014, 04:08 PM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,048
Hello iabudi,

Todd is not available.

What type of device are you connected to at the time the issue occurs?

What was the command that was sent?
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #11  
Old 11-19-2014, 09:30 PM
iabudi iabudi is offline
Registered User
 
Join Date: Oct 2014
Posts: 4
cisco Script

Quote:
Originally Posted by bgagnon View Post
Hello iabudi,

Todd is not available.

What type of device are you connected to at the time the issue occurs?

What was the command that was sent?
I am connecting to cisco router

I sent show ip route and the second command is show log

the script created the file then sent the show ip route (from the command file)
I get back the ip route table and at the end I get the router prompt.
Router#

then it just sits there. until I stop script. and I get the line 399 message.

How can I send you the script?
Reply With Quote
  #12  
Old 10-08-2015, 09:17 PM
djdumlao djdumlao is offline
Registered User
 
Join Date: Oct 2015
Posts: 2
Will this script work on Python version 3

RTB and Vandyke team Will this script work on Python version 3?

Last edited by rtb; 10-09-2015 at 09:03 AM. Reason: Removing cruft from post
Reply With Quote
  #13  
Old 10-09-2015, 09:03 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi djdumlao,

Since SecureCRT 7.3 for Windows includes Python 2.6 and SecureCRT on Mac OS X, RHEL and Ubuntu use Python 2.7 (which should already exist on the system), we haven't tested the script with Python 3.x.

The script is intended to be run from within SecureCRT.

Does this help to answer your question?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #14  
Old 03-23-2016, 10:02 AM
splicer72 splicer72 is offline
Registered User
 
Join Date: Oct 2011
Posts: 3
Use a hostname instead of IP to name file

Hi Todd
The script is working fine for me as it is but am trying to amend two things with little luck.
I would like to use a hostname to name the log file, i had a similar script that used a single file i.e hostname:ip:ssh but that does not work on the network i am currently working on
The other change is that I would like to be able to place all of the output into a single file as opposed to multiple files. I have tried looking at how to do this but am a bit stumped.
Any ideas would be greatly appreciated

Thanks in advance


Colin
Reply With Quote
  #15  
Old 03-23-2016, 10:25 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,048
Hi Colin,

We do have such an example script (log to one file).

Please send an email to support@vandyke.com and reference "Attn Brenda - Forum Thread #10651". I will provide further guidance on how to accomplish the naming convention you desire via email.
__________________
Thanks,
--Brenda

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

Tags
example script


Currently Active Users Viewing This Thread: 2 (0 members and 2 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:45 PM.