#1
|
|||
|
|||
SecureCRT – Command Line Options - Non-interactive command on the server
After a non-interactive SSH log in to a remote server without any interactive prompting, can I execute a script on the remote server?
Using Plink (Putty), I can execute a remote script. For example, to execute a script backup.sh on a remote server(myhost.local), I can issue a command: plink ubuntutest@myhost.local -i PuttyPrivate.ppk ./backup.sh I am wondering if this is possible using SecureCRT SSH. |
#2
|
|||
|
|||
Hi akd,
SecureCRT can absolutely run commands on the remote system. Because Plink is a command line only utility and SecureCRT is a GUI application there will some variance in how this is done. One option would be to use SecureCRT's Remote command functionality.
When connecting to this session, SecureCRT will automatically run the remote command. After the remote command completes SecureCRT will automatically disconnect the session. Based on your needs, there are additional configuration options available to automatically close the tab/application upon disconnect as well. Does this help get you the behavior you're looking for?
__________________
Thanks, --Eric VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
#3
|
|||
|
|||
How to script a remote command
Going back to the plink example:
plink ubuntutest@myhost.local -i PuttyPrivate.ppk ./backup.sh How do I accomplish this in a script using SecureCRT.exe instead of plink? I have a list of hosts and do not want to create/save a separate session for each one. |
#4
|
|||
|
|||
Hi southca,
The general command line syntax for SecureCRT is: Code:
SecureCRT.exe [standard options] [protocol-specific options] Code:
SecureCRT.exe /SSH2 /I "C:\Path\to\identity\file" ubuntutest@myhost.local Is this information helpful?
__________________
Thanks, --Brittney VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
#5
|
|||
|
|||
What about the command to execute?
Your examples make a scripted connection to a host, but I also want to pass a command to execute. I see this is possible using a saved session with the "Remote command" option, and I'm looking for the command line equivalent without saving a session for every host.
I can make a scripted connection to a host using PowerShell as follows: Code:
$ssh = "$env:ProgramFiles\VanDyke Software\Clients\SecureCRT.exe" $cred = Get-Credential -Message "SSH credentials" $user = $cred.GetNetworkCredential().UserName $pass = $cred.GetNetworkCredential().Password & $ssh /T /SSH2 /AUTH password /L "$user" /PASSWORD "$pass" myhost Code:
& $ssh /T /SSH2 /AUTH password /L "$user" /PASSWORD "$pass" /COMMAND "runme" myhost Code:
#$language = "VBScript" #$interface = "1.0" crt.Screen.Synchronous = True Sub Main crt.Screen.Send "runme" & chr(13) crt.Screen.Send "exit" & chr(13) End Sub With the above text block saved as a script file I can use it with my PowerShell command like this: Code:
$script = "$env:USERPROFILE\Desktop\myscript.vbs" & $ssh /SCRIPT $script /SSH2 /AUTH password /L "$user" /PASSWORD "$pass" myhost Thank you. |
#6
|
|||
|
|||
Hi southca,
There is not currently a command line option that will allow you to send a command to the remote host. I have submitted a feature request on your behalf to implement such a command line option. Should a future release of SecureCRT include this functionality, notification will be posted here. If you prefer direct email notification, send an email to support@vandyke.com and include *"Feature Request - Forum Thread #13431"* in the subject line. If you are running the same command(s) on the remote hosts that you are connecting to, you might be interested in our "Run Commands On Multiple Hosts And Log Results" script example: https://forums.vandyke.com/showthread.php?t=10365The script 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.
__________________
Thanks, --Brittney VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
#7
|
|||
|
|||
Executing commands on a remote host from CLI
I found it's possible to modify the VBS script to accept arguments, which adds some flexibility to the solution. Here's the modified version of "myscript.vbs":
Code:
#$language = "VBScript" #$interface = "1.0" ' SecureCRT script executes a single command on a connected session and exits crt.Screen.Synchronous = True Sub Main crt.Screen.Send crt.Arguments(0) & chr(13) crt.Screen.Send "exit" & chr(13) End Sub Code:
$ssh = "$env:ProgramFiles\VanDyke Software\Clients\SecureCRT.exe" $cred = Get-Credential -Message "SSH credentials" $user = $cred.GetNetworkCredential().UserName $pass = $cred.GetNetworkCredential().Password $script = "$env:USERPROFILE\Desktop\myscript.vbs" $command = "runme" & $ssh /SCRIPT $script /ARG $command /SSH2 /AUTH password /L "$user" /PASSWORD "$pass" myhost |
![]() |
Tags |
securecrt 8.5.3 |
Thread Tools | |
Display Modes | |
|
|