Previous Topic: run-SSHCommand Command--Run a Remote Command Through SSH (Funclet)Next Topic: run-winRemote Command--Execute a Command on Multiple Remote Windows Systems (Funclet)


run-SSHShell Command--Run an Interactive SSH Command Line (Funclet)

The run-SSHCommand command accepts input lines, sending them to a remote system through SSH and displays the output from the remote node. The command line can be run within an existing SSH session or a new SSH session. The session is destroyed when the input ends. Although AutoShell uses SSH as its primary remote communication conduit, the remote node for this command does not require a running client AutoShell. Commands can be executed on any system running an SSH server. The available commands, their options and the way to end the input loop depend on the configured shell on the remote node. Typically the input loop can be terminated by entering "quit" or "exit".

The command has the following syntax:

run-SSHShell [-host hostname] [-user username] [-pass password] [-key key phrase] 
[-prompt prompt] [-port portnumber] [-session ssh]
-host hostname

The name of the SSH server.

-user username

(Optional) Specifies the user name to log in to the remote node. A user name is required for password or public key authentication. If no user name is specified, the user name entered during AutoShell login is used. Unquoted argument tokens are automatically stringified. Prevent automatic quoting for expressions by placing expression code in parentheses.

Default: $$User

-pass password

(Optional) Specifies the password to use to log in to the remote node. If no password is specified, the password entered during AutoShell login is used. To enter a hidden password after issuing this command, specify PW_GET() with an optional prompt as argument. Unquoted argument tokens are automatically stringified. Prevent automatic quoting for expressions by placing expression code in parentheses.

Default: $$Pass

-key key

(Optional) Specifies an absolute or relative path to a file containing a private RSA key to use to log in to the remote node. If a private key and a password are specified, AutoShell attempts a public key logon first, and if that fails, a password logon. Unquoted argument tokens are automatically stringified. Prevent automatic quoting for expressions by placing expression code in parentheses. This parameter is only required when creating an SSH session on the fly using public key authentication.

Default: ""

phrase

Specifies the passphrase for a private key. If the key is not encrypted, the passphrase is not required. To enter a hidden password after issuing this command, specify PW_GET() with an optional prompt as argument. Unquoted argument tokens are automatically stringified. Prevent automatic quoting for expressions by placing expression code in parentheses.

Default: ""

-prompt prompt

(Optional) Specifies the fixed portion at the end of the prompt string displayed by the SSH server to indicate it is ready for input (for example: "::->" for AutoShell). This information is required to determine the completion of commands executed during the SSH session. Specify as many fixed characters as possible. Unquoted argument tokens are automatically stringified. Prevent automatic quoting for expressions by placing expression code in parentheses.

Default: "::->"

-port portnumber

(Optional) Port on which to connect to the target system.

Default: SSH standard port 22.

-session ssh

Specifies a CASSHELL object as returned by new-SSHSession. When passing an existing SSH session object run-SSHShell does not need to create an SSH session for execution of the commands from the command line. If this parameter is specified, values passed for host, user, pass, key, phrase, and port are ignored. This information is specified when creating the session.

Default: null

Examples

Run an interactive command line shell on a host using an SSH session with password authentication:

run-SSHShell -host svr14 -user bob -pass xyz42 -prompt :>

Explicitly allocate SSH session, run a command first and then drop into the command line input loop:

ssh=new-SSHSession -host client8 -user bob -pass xyz42 -prompt ::->
run-SSHCommand -session ssh -command "cd /"
run-SSHShell -session ssh
ssh.disconnect();

See also:

new-SSHSession Command--Create a new Secure SSH Session (Funclet)

run-SSHCommand Command--Run a Remote Command Through SSH (Funclet)