Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Secure Shell

Reply
 
Thread Tools Display Modes
  #1  
Old 03-04-2019, 02:30 PM
akd akd is offline
Registered User
 
Join Date: Mar 2019
Posts: 3
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.
Reply With Quote
  #2  
Old 03-04-2019, 03:57 PM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 654
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.
  1. Create and save a session to the remote server
  2. Right click on the saved session and choose Properties
  3. Select the Logon Actions category
  4. Enable the Remote command option
  5. Enter the command you would like to run on the remote system
  6. Save your changes



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?
Attached Images
File Type: png RemoteCommand.png (30.3 KB, 1422 views)
__________________
Thanks,
--Eric

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #3  
Old 04-30-2019, 11:09 AM
southca southca is offline
Registered User
 
Join Date: Apr 2019
Posts: 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.
Reply With Quote
  #4  
Old 04-30-2019, 01:05 PM
berdmann berdmann is offline
VanDyke Technical Support
 
Join Date: Aug 2017
Posts: 256
Hi southca,

The general command line syntax for SecureCRT is:

Code:
 SecureCRT.exe [standard options] [protocol-specific options]
More specifically, if you want an "ad-hoc" connection to your remote host using a public key file you would use the following syntax:

Code:
SecureCRT.exe /SSH2 /I "C:\Path\to\identity\file" ubuntutest@myhost.local
Please review SecureCRT's Help for more on SecureCRT's command-line options.

Is this information helpful?
__________________
Thanks,
--Brittney

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #5  
Old 04-30-2019, 02:24 PM
southca southca is offline
Registered User
 
Join Date: Apr 2019
Posts: 3
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
Now let's say I want to extend the above connection command to execute "runme" on the target system. Ideally I could just update my existing command with something like this:
Code:
& $ssh /T /SSH2 /AUTH password /L "$user" /PASSWORD "$pass" /COMMAND "runme" myhost
Unfortunately with SecureCRT there is no direct command line option to simply pass commands as arguments. I found the /SCRIPT option documented and managed to make it work by saving the following text as "myscript.vbs"
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
Please let me know if there's a better way to accomplish this task. I've seen a number of similar questions in the support forums and it seems users are looking for simple OpenSSH client behavior where commands can be passed directly to the target host. Please consider adding this feature to your command line client.

Thank you.
Reply With Quote
  #6  
Old 04-30-2019, 05:04 PM
berdmann berdmann is offline
VanDyke Technical Support
 
Join Date: Aug 2017
Posts: 256
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=10365
The 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
Reply With Quote
  #7  
Old 05-01-2019, 09:45 AM
southca southca is offline
Registered User
 
Join Date: Apr 2019
Posts: 3
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
Here's the PowerShell to pass an argument to the above script that will ultimately be executed on the target SSH host, making it easy to run any command:

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
While this works, it's much more complicated than it needs to be. If/when the command line option is implemented the extra VBScript won't be needed. Thanks for submitting the feature request.
Reply With Quote
Reply

Tags
securecrt 8.5.3


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 09:03 PM.