ssh-exec

Package: WA2L/edrc 1.5.57
Section: General Commands (1)
Updated: 23 January 2021
Index Return to Main Contents

 

NAME

ssh-exec - execute command provided thru stdin using ssh on remote host

 

SYNOPSIS

edrc/bin/ssh-exec [ -h ]

ssh-exec [ -b ] -u user@hostname < commands

ssh-exec [ -b ] -u user -t hostname < commands

ssh-exec -p [ -e | -l localuser ] -u user@hostname

ssh-exec -p [ -e | -l localuser ] -u user -t hostname

ssh-exec [ -s | -v ][ -n ][ -b ][ -e | -l localuser ] -u user@hostname < commands

ssh-exec [ -s | -v ][ -n ][ -b ][ -e | -l localuser ] -u user -t hostname < commands

 

AVAILABILITY

WA2L/edrc

 

DESCRIPTION

execute commands, a sequence of commands or a whole script provided thru stdin to ssh-exec on a remote system using the SSH protocol.

Prior to the remote command invocation it is checked if the remote target system with hostname is up and if it is possible to connect using the provided user to the remote target system.

In addition to the commands it is supported to submit answers to specific outputs (when it is not possible to do it using simple input redirection) or an except(3) script without the need to write extra "wrapper" scripts.

 

[COMMANDS] Execute commands:

Simple command invocation on a target system:

  ssh-exec -u user@target <<EOM
  ps -ef | grep oracle
  EOM

or

  ssh-exec -u user@target <<EOM
  [COMMANDS]
  ps -ef | grep oracle
  EOM

The [COMMANDS] section keyword is optional as long as it is the first section provided to ssh-exec.

Command invocation with input redirection of needed command inputs:

  ssh-exec -u user@target <<EOM

  restore-data <<EOI
  /dat/backup/acme-001/2020-01-10/etc/hosts
  /etc/hosts
  EOI

  EOM

 

[ANSWERS] Providing answers to a tty command:

Remote control an interactive command that reads the input from a tty and not from stdin:

  ssh-exec -u user@target <<EOM

  [COMMANDS]
  set-license-key

  [ANSWERS]
  ;Input new license key:;VcB542RSXtMZM\r;
  ;Repeat new license key:;VcB542RSXtMZM\r;

  EOM

Behind the scenes the provided answers in the [ANSWERS] section are translated automatically into an ad-hoc expect script, as:

  expect "Input new license key:"
  send -- "VcB542RSXtMZM\r"

  expect "Repeat new license key:"
  send -- "VcB542RSXtMZM\r"

  expect eof

that is used to remote control the command.

This helps to efficiently handle the most cases of remote command control where the needed expect definition would be a expect ... -> send -- ... sequence.

The [ANSWERS] section has the format:

:Input prompt:Answer:

where the first character is treated as separator between the Input prompt and the Answer fields.

Therefore, if the Input prompt or the Answer contains the field separator character (the colon : in this example) the specification

;Input prompt;Answer;

is identical to the specification above.

 

[EXPECT] Providing an expect script to a tty command:

Remote control an interactive command that reads the input from a tty and not from stdin.

The expect script has to be provided only if the automatically generated script using the [ANSWERS] section is not sufficient to the needs to control a command.

  ssh-exec -u user@target <<EOM

  [COMMANDS]
  set-license-key

  [EXPECT]
  expect "Input new license key:"
  send -- "VcB542RSXtMZM\r"

  expect "Repeat new license key:"
  send -- "VcB542RSXtMZM\r"

  expect eof

  EOM

 

OPTIONS

-h
usage message.

-p
only probe connection to target hostname with user without reading commands from stdin.
 
-e
use EDRC_USER as defined in etc/ssh-exec.cfg (default=edrc) as local user.

When -e is used or the EDRC_USER (default=edrc) is used in the -l localuser option, the private keys as defined in var/connection/security/edrc/OpenSSH/default/default/id_dsa and var/connection/security/edrc/OpenSSH/default/default/id_rsa are used to connect to the remote hostname.

Prerequisite to a working connection is that the contents of the files var/connection/security/edrc/OpenSSH/default/default/id_dsa.pub and var/connection/security/edrc/OpenSSH/default/default/id_rsa.pub are appended to the ~user/.ssh/authorized_keys file on the target hostname.

To efficiently add the public keys to authorized_keys files on hosts where the WA2L/edrc package is installed, use the ssh-keyadd(1m) command.

-s
output (to stderr) of commands and exit without executing any commands on hostname.

-v
verbose output (to stderr) of commands to be sent to target hostname.

-n
do not probe connection before executing the provided commands.

-b
eliminate the output of a banner of a remote system (when not providing a [ANSWERS] section).

-l localuser
use the local user localuser to initiate the connection. Default local user is root.

When using this option the private SSH keys of the specified localuser (as defined in ~localuser/.ssh/id_dsa and ~localuser/.ssh/id_rsa files) on the local system are used to connect to the target hostname.

See -e option description for additional information.

-u user
remote user to connect on the target system.

-t hostname
target system hostname to execute the commands.

-u user@hostname
remote user to connect on the target system hostname.

commands
commands to be executed on the target hostname.

Commands can be read from file using the input redirection:

  ssh-exec options < commands

providing the file contents thru the pipe:

  cat commands | ssh-exec options

or the 'in here' mechanism in scripts without the creation of an extra file:

  ssh-exec options <<EOM
  command_1
  command_2
  command_n
  EOM

 

ENVIRONMENT

-

 

EXIT STATUS

0
no error.

1
remote system is not up.

2
cannot conntect to hostname with user user.

4
usage printed.

5
the execution has been aborted using Ctrl+C.

6
the configuration file ssh-exec.cfg does not exist.

7
errors in [ANSWERS] section. If you receive this error, use the -v to see more details.

8
command was started with the -s option.

11
temporary directory could not be claimed or created in /tmp. Check the system temporary directory /tmp if you get this error, it is an indicator of system intrusion.

 

FILES

etc/ssh-exec.cfg
configuration file of ssh-exec, see ssh-exec.cfg(4) for more information.

var/log/ssh-exec.log
default logfile of ssh-exec.

 

EXAMPLES

-

 

SEE ALSO

edrcintro(1), edrcsetup(1m), filedist(1), hostlist(3), input(3), input_targets(3), rcmd(1), remote_shell(3), remote_copy(3), resolve_targetlist(3), ssh-exec.cfg(4), ssh-keygen(1), ssh-keyadd(1m), syspoll(1)

 

NOTES

If you need to invoke ad-hoc commands on all systems in your environment (needs WA2L/edrc installed) most efficiently use the rcmd(1) command.

To poll a list of systems for reporting data most efficiently, use the syspoll(1) command.

 

BUGS

-

 

AUTHOR

ssh-exec was developed by Christian Walther. Send suggestions and bug reports to wa2l@users.sourceforge.net .

 

COPYRIGHT

Copyright © 2020 by Christian Walther

This is free software; see edrc/doc/COPYING for copying conditions. There is ABSOLUTELY NO WARRANTY; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


 

Index

NAME
SYNOPSIS
AVAILABILITY
DESCRIPTION
[COMMANDS] Execute commands:
[ANSWERS] Providing answers to a tty command:
[EXPECT] Providing an expect script to a tty command:
OPTIONS
ENVIRONMENT
EXIT STATUS
FILES
EXAMPLES
SEE ALSO
NOTES
BUGS
AUTHOR
COPYRIGHT

This document was created by man2html using the manual pages.
Time: 16:54:29 GMT, August 28, 2024