- Solution: you can get the info from Spiceworks or you can use putty (plink).path to putty plink.exe -ssh user@x.x.x.x -pw psss Hi All, I am looking for SSH script to be able to login automatically to all switches from the list, send command ie: show vlan 1 and return results to a file The reason I need.
- Please note that I created a thread on SecureCRT's forum regarding this issue as well - SecureCRT not processing script correctly (maybe) - VanDyke Software Forums.
Create an automatic login script for multiple devices using SecureCRT - Part 4. SSH on iPad and iPhone - Duration: 3:12. Simon Hope 10,467 views. Create an automatic login script for. When comparing PuTTY vs SecureCRT. Scripts can be bound to buttons, menu items, and keyboard shortcuts. You can use 'PuTTYgen' to generate a key pair, then use 'Pageant' to do a password-less SSH remote login. It is JUST an SSH client. There are many other options with built in X-servers, Multitabbing, etc.
This is quite a common task for Linux system administrators, when it is needed to execute some command or a local Bash script from a one Linux workstation or a server on another remote Linux machine over SSH.
In this article you will find the examples of how to execute a remote command, multiple commands or a Bash script over SSH between remote Linux hosts and get back the output (result).
This information will be especially useful for ones, who want to create a Bash script that will be hosted locally on a one Linux machine but would be executed remotely on the other hosts over SSH.
Cool Tip: Connect to a remote SSH server without typing a password! Configure a passwordless authentication! Only 3 easy steps! Read more →
SSH: Execute Remote Command
Execute a remote command on a host over SSH:
Examples
Get the uptime of the remote server:
Reboot the remote server:
SSH: Run Multiple Remote Commands
In the most cases it is not enough to send only one remote command over SSH.Much more often it is required to send multiple commands on a remote server, for example, to collect some data for inventory and get back the result.
There are a lot of different ways of how it can be done, but i will show the most popular of them.
Run multiple command on a remote host over SSH:
– or –
– or –
Cool Tip: SSH login is too slow? This can be fixed easily! Get rid of delay during authentication! Read more →
Examples
Get the uptime and the disk usage:
Get the memory usage and the load average:
Show the kernel version, number of CPUs and the total RAM:
SSH: Run Bash Script on Remote Server
The equally common situation, when there is some Bash script on a Linux machine and it needs to connect from it over SSH to another Linux machine and run this script there.The idea is to connect to a remote Linux server over SSH, let the script do the required operations and return back to local, without need not to upload this script to a remote server.
Certainly this can be done and moreover quite easily.
Ssh Execute Script
Cool Tip: Want to ROCK? Start a GUI (graphical) application on a remote Linux workstation over SSH! Read more →
Example
Execute the local script.sh
on the remote server:
This module contains classes for representing the execution of a script in SecureCRT. The attributes and methodsdefined with these classes are more 'global' in nature, meaning that they focus on either the interaction with theapplication, or anything that is common to the entire script regardless of how many sessions (in tabs) are open toremote devices.
The Script Base Class¶
securecrt_tools.scripts.
Script
(script_path)¶This is a base class for the script object. This class cannot be used directly, but is instead a blueprint thatenforces what any sub-classes must implement. The reason for using this design (base class with sub-classes) isto allow the script to be run in different contexts without needing to change the code, as long as the correctsub-class is being used.
For example, the most important sub-class is the CRTScript subclass which is used when the script is executed fromSecureCRT. This class is written to interact with SecureCRT's Python API to be able to control the applications.If the script author wants to display something to the user, they can use the message_box() method to useSecureCRT's pop-up message box (crt.Dialog.MessageBox() call). The other sub-class (currently) is the DebugScriptsub-class, which was created to allow easier debugging of a script's logic by letting you execute the script usinga local python installation – ideally in your IDE of choice. This would allow you to use the fully debuggingfeatures of the IDE which are otherwise not available when executing a script inside SecureCRT. When themessage_box() is called on the DebugScript sub-class, the message will be printed to the console.
This sub-class design can also allow for additional classes to be created in the future – perhaps one that usesNetmiko to connect to the remote devices. In this way, if a Netmiko sub-class was created, then all of the samescripts can be executed without needing to change them, because the Netmiko class would be required to implementall of the same methods that are defined in the base class (just like CRTScript and DebugScript)
DebugScript class is to allow the programmer to debug their code in their favorite IDE or debugger, which cannotbe done when executing the script from SecureCRT (in which case you are forced to either use debug messages or writeoutputs to a messagebox. DebugScript allows the same code to run locally without SecureCRT and the class willprompt for the information it needs to continue running the main script.
Any methods that are not prepended with the @abstractmethod tag preceding the method definition will be inheritedand available to the sub-classes without needing to define them specifically in each sub-class. Methods designedthis way would use the exact same code in all sub-classes, and so there is no reason to re-create them in eachsubclass.
Methods defined with the @abstractmethod tag should be left empty in this class. They are required to beimplemented in each sub-class. Methods are defined this way when they are required to exist in all sub-classesfor consistency, but the code would be written completely different depending on which class is being used. Oneexample is the message_box method below. Under the CRTScript class, this method uses the SecureCRT API to printmessages and format the text box that should pop up to the user, but in the DebugScript class this method onlyprints the message to the console. In this way, a call to this method will work either way the script is calledas long as the correct Script sub-class is being used (and the template are already written to do this).
get_main_session
()¶Returns a CRTSession object that interacts with the SecureCRT tab that the script was lauched within. This isthe primary tab that will be used to interact with remote devices. While new tabs can be created to connect toother devices, SecureCRT does not support multi-threading so multiple devices cannot be interacted withsimultaneously via a script.
Returns: | A session object that represents the tab where the script was launched |
---|---|
Return type: | sessions.Session |
get_template
(name)¶Retrieve the full path to a TextFSM template file.
Parameters: | name (str) – Filename of the template |
---|---|
Returns: | Full path to the template location |
Return type: | str |
import_device_list
()¶This function will prompt for a device list CSV file to import, returns a list containing all of thedevices that were in the CSV file and their associated credentials. The CSV file must be of the format, andinclude a header row of [‘Hostname', ‘Protocol', ‘Username', ‘Password', ‘Enable', ‘Proxy Session']. An exampledevice list CSV file is at ‘template/sample_device_list.csv'
The ‘Proxy Session' options is looking for a SecureCRT session name that can be used to proxy this connectionthrough. This sets the ‘Firewall' option under a SecureCRT session to perform this connection proxy.
Some additional information about missing items from a line in the CSV:- If the hostname field is missing, the line will be skipped.- If the protocol field is empty, the script will try SSH2, then SSH1, then Telnet.- If the username is missing, this method will prompt the user for a default usernaem to use- If the password is missing, will prompt the user for a password for each username missing a password- If the enable password is missing, the method will ask the user if they want to set a default enable to use- If the IP is included then the device will be reached through the jumpbox, otherwise connect directly.
Returns: | A list where each entry is a dictionary representing a device and the associated login information. |
---|---|
Return type: | list of dict |
validate_dir
(path, prompt_to_create=True)¶Verifies that the path to the supplied directory exists. If not, prompt the user to create it.
Parameters: | path (str) – A directory path (not including filename) to be validated |
---|
CRTScript Class¶
securecrt_tools.scripts.
CRTScript
(crt)¶Bases: securecrt_tools.scripts.Script
This class is a sub-class of the Script base class, and is meant to be used in any scripts that are being executedfrom inside of SecureCRT. This sub-class is designed to interact with the SecureCRT application itself (not withtabs that have connections to remote devices) and represent a script being executed from within SecureCRT. Thisclass inherits the methods from the Script class that are documented above, and is required to implement all of theabstract classes defined in the Script class.
connect
(host, username, password, protocol=None, proxy=None, prompt_endings=('#', '>'))¶Attempts to connect to a device by any available protocol, starting with SSH2, then SSH1, then telnet
Parameters: |
|
---|
connect_ssh
(host, username, password, version=None, proxy=None, prompt_endings=('#', '>'))¶Connects to a device via the SSH protocol. By default, SSH2 will be tried first, but if it fails it will attemptto fall back to SSH1.
Parameters: |
|
---|
connect_telnet
(host, username, password, proxy=None, prompt_endings=('#', '>'))¶Connects to a device via the Telnet protocol.
Parameters: |
|
---|
create_new_saved_session
(session_name, ip, protocol='SSH2', folder='_imports')¶Creates a session object that can be opened from the Connect menu in SecureCRT.
Parameters: |
|
---|
disconnect
(command='exit')¶Disconnects the main session used by the script by calling the disconnect method on the session object.
Parameters: | command (str) – The command to be issued to the remote device to disconnect. The default is ‘exit' |
---|
file_open_dialog
(title, button_label='Open', default_filename=', file_filter=')¶Prompts the user to select a file that will be processed by the script. In SecureCRT this will give a pop-upfile selection dialog window, and will return the full path to the file chosen.
Parameters: |
|
---|---|
Returns: | The absolute path to the file that was selected |
Return type: | str |
message_box
(message, title=', options=0)¶Premiere pro 2017 crack. Prints a message for the user. In SecureCRT, the message is displayed in a pop-up message box with a varietyof buttons, depending on which options are chosen. The default is just an 'OK' button.
This window can be customized by setting the 'options' value, using the constants listed at the top of thesessions.py file. One constant from each of the 3 categories can be OR'd (|) together to make a single optionvalue that will format the message box.
Parameters: |
|
---|---|
Returns: | The return code that identifies which button the user pressed. (See Message Box constants) |
Return type: | int |
prompt_window
(message, title=', hide_input=False)¶Prompts the user for an input value. In SecureCRT this will open a pop-up window where the user can input therequested information.
The 'hide_input' input will mask the input, so that passwords or other senstive information can be requested.
Parameters: |
|
---|---|
Returns: | The value entered by the user |
Return type: | str |
DebugScript Class¶
securecrt_tools.scripts.
DebugScript
(full_script_path)¶Bases: securecrt_tools.scripts.Script
This class is a sub-class of the Script base class, and is meant to be used in any scripts that are being executeddirectly from a local python installation. This sub-class is designed to simulate the interaction with SecureCRTwhile the script is being run from a local python installation. For example, when a script attempts to create apop-up message box in SecureCRT, this class will simply print the information to the console (or request informationfrom the user via the console).
This class inherits the methods from the Script class that are documented above, and is required to implement allof the abstract classes defined in the Script class. This way, it is a complete replacement for the CRTScript classif a script is run directly.
connect
(host, username, password, protocol=None, proxy=None, prompt_endings=('#', '>'))¶Pretends to connect to a device. Simply marks the state of the session as connected. Never fails.
Parameters: |
|
---|
connect_ssh
(host, username, password, version=None, proxy=None, prompt_endings=('#', '>'))¶Pretends to connect to a device via SSH. Simply tracks that we are now connected to something within thissession (this method never fails).
Parameters: |
|
---|
connect_telnet
(host, username, password, proxy=None, prompt_endings=('#', '>'))¶Pretends to connect to a device via the Telnet protocol, just like connect_ssh above. Never fails.
Parameters: |
|
---|
create_new_saved_session
(session_name, ip, protocol='SSH2', folder='_imports')¶Pretends to create a new SecureCRT session. Since we aren't running in SecureCRT, it does nothing exceptprint a message that a device was created.
Parameters: |
|
---|
disconnect
(command='exit')¶Disconnects the main session used by the script by calling the disconnect method on the session object.
Parameters: | command (str) – The command to be issued to the remote device to disconnect. The default is ‘exit' |
---|
file_open_dialog
(title, button_label='Open', default_filename=', file_filter=')¶Prompts the user to select a file that will be processed by the script. In a direct session, the user will beprompted for the full path to a file.
Returns: | A session object that represents the tab where the script was launched |
---|---|
Return type: | sessions.Session |
get_template
(name)¶Retrieve the full path to a TextFSM template file.
Parameters: | name (str) – Filename of the template |
---|---|
Returns: | Full path to the template location |
Return type: | str |
import_device_list
()¶This function will prompt for a device list CSV file to import, returns a list containing all of thedevices that were in the CSV file and their associated credentials. The CSV file must be of the format, andinclude a header row of [‘Hostname', ‘Protocol', ‘Username', ‘Password', ‘Enable', ‘Proxy Session']. An exampledevice list CSV file is at ‘template/sample_device_list.csv'
The ‘Proxy Session' options is looking for a SecureCRT session name that can be used to proxy this connectionthrough. This sets the ‘Firewall' option under a SecureCRT session to perform this connection proxy.
Some additional information about missing items from a line in the CSV:- If the hostname field is missing, the line will be skipped.- If the protocol field is empty, the script will try SSH2, then SSH1, then Telnet.- If the username is missing, this method will prompt the user for a default usernaem to use- If the password is missing, will prompt the user for a password for each username missing a password- If the enable password is missing, the method will ask the user if they want to set a default enable to use- If the IP is included then the device will be reached through the jumpbox, otherwise connect directly.
Returns: | A list where each entry is a dictionary representing a device and the associated login information. |
---|---|
Return type: | list of dict |
validate_dir
(path, prompt_to_create=True)¶Verifies that the path to the supplied directory exists. If not, prompt the user to create it.
Parameters: | path (str) – A directory path (not including filename) to be validated |
---|
CRTScript Class¶
securecrt_tools.scripts.
CRTScript
(crt)¶Bases: securecrt_tools.scripts.Script
This class is a sub-class of the Script base class, and is meant to be used in any scripts that are being executedfrom inside of SecureCRT. This sub-class is designed to interact with the SecureCRT application itself (not withtabs that have connections to remote devices) and represent a script being executed from within SecureCRT. Thisclass inherits the methods from the Script class that are documented above, and is required to implement all of theabstract classes defined in the Script class.
connect
(host, username, password, protocol=None, proxy=None, prompt_endings=('#', '>'))¶Attempts to connect to a device by any available protocol, starting with SSH2, then SSH1, then telnet
Parameters: |
|
---|
connect_ssh
(host, username, password, version=None, proxy=None, prompt_endings=('#', '>'))¶Connects to a device via the SSH protocol. By default, SSH2 will be tried first, but if it fails it will attemptto fall back to SSH1.
Parameters: |
|
---|
connect_telnet
(host, username, password, proxy=None, prompt_endings=('#', '>'))¶Connects to a device via the Telnet protocol.
Parameters: |
|
---|
create_new_saved_session
(session_name, ip, protocol='SSH2', folder='_imports')¶Creates a session object that can be opened from the Connect menu in SecureCRT.
Parameters: |
|
---|
disconnect
(command='exit')¶Disconnects the main session used by the script by calling the disconnect method on the session object.
Parameters: | command (str) – The command to be issued to the remote device to disconnect. The default is ‘exit' |
---|
file_open_dialog
(title, button_label='Open', default_filename=', file_filter=')¶Prompts the user to select a file that will be processed by the script. In SecureCRT this will give a pop-upfile selection dialog window, and will return the full path to the file chosen.
Parameters: |
|
---|---|
Returns: | The absolute path to the file that was selected |
Return type: | str |
message_box
(message, title=', options=0)¶Premiere pro 2017 crack. Prints a message for the user. In SecureCRT, the message is displayed in a pop-up message box with a varietyof buttons, depending on which options are chosen. The default is just an 'OK' button.
This window can be customized by setting the 'options' value, using the constants listed at the top of thesessions.py file. One constant from each of the 3 categories can be OR'd (|) together to make a single optionvalue that will format the message box.
Parameters: |
|
---|---|
Returns: | The return code that identifies which button the user pressed. (See Message Box constants) |
Return type: | int |
prompt_window
(message, title=', hide_input=False)¶Prompts the user for an input value. In SecureCRT this will open a pop-up window where the user can input therequested information.
The 'hide_input' input will mask the input, so that passwords or other senstive information can be requested.
Parameters: |
|
---|---|
Returns: | The value entered by the user |
Return type: | str |
DebugScript Class¶
securecrt_tools.scripts.
DebugScript
(full_script_path)¶Bases: securecrt_tools.scripts.Script
This class is a sub-class of the Script base class, and is meant to be used in any scripts that are being executeddirectly from a local python installation. This sub-class is designed to simulate the interaction with SecureCRTwhile the script is being run from a local python installation. For example, when a script attempts to create apop-up message box in SecureCRT, this class will simply print the information to the console (or request informationfrom the user via the console).
This class inherits the methods from the Script class that are documented above, and is required to implement allof the abstract classes defined in the Script class. This way, it is a complete replacement for the CRTScript classif a script is run directly.
connect
(host, username, password, protocol=None, proxy=None, prompt_endings=('#', '>'))¶Pretends to connect to a device. Simply marks the state of the session as connected. Never fails.
Parameters: |
|
---|
connect_ssh
(host, username, password, version=None, proxy=None, prompt_endings=('#', '>'))¶Pretends to connect to a device via SSH. Simply tracks that we are now connected to something within thissession (this method never fails).
Parameters: |
|
---|
connect_telnet
(host, username, password, proxy=None, prompt_endings=('#', '>'))¶Pretends to connect to a device via the Telnet protocol, just like connect_ssh above. Never fails.
Parameters: |
|
---|
create_new_saved_session
(session_name, ip, protocol='SSH2', folder='_imports')¶Pretends to create a new SecureCRT session. Since we aren't running in SecureCRT, it does nothing exceptprint a message that a device was created.
Parameters: |
|
---|
disconnect
(command='exit')¶Disconnects the main session used by the script by calling the disconnect method on the session object.
Parameters: | command (str) – The command to be issued to the remote device to disconnect. The default is ‘exit' |
---|
file_open_dialog
(title, button_label='Open', default_filename=', file_filter=')¶Prompts the user to select a file that will be processed by the script. In a direct session, the user will beprompted for the full path to a file.
Parameters: |
|
---|---|
Returns: | The absolute path to the file that was selected |
Return type: | str |
message_box
(message, title=', options=0)¶Prints a message for the user. When used in a DirectSession, the message is printed to the console and theuser is prompted to type the button that would be selected.
Linux Ssh Script
This window can be customized by setting the 'options' value, using the constants listed at the top of thesessions.py file. One constant from each of the 3 categories can be OR'd (|) together to make a single optionvalue that will format the message box.
Parameters: |
|
---|---|
Returns: | The return code that identifies which button the user pressed. (See Message Box constants) |
Return type: | int |
prompt_window
(message, title=', hide_input=False)¶Prompts the user for an input value. In a direct session, the user will be prompted at the console for input.
The 'hide_input' input will mask the input, so that passwords or other senstive information can be requested.
Parameters: |
|
---|---|
Returns: | The value entered by the user |
Return type: | str |
ssh_in_new_tab
(host, username, password, prompt_endings=('#', '>'))¶Pretends to open a new tab. Since this is being run directly and no tabs exist, the function really doesnothing but return a new Session object.
Parameters: |
|
---|
Script Class Exceptions:¶
securecrt_tools.scripts.
ScriptError
¶An exception type that is raised when there is a problem with the main scripts, such as missing settings files.
securecrt_tools.scripts.
ConnectError
¶Ssh In Script
An exception type that is raised when there are problems connecting to a device. Max payne 3 free download for pc highly compressed.