aboutsummaryrefslogtreecommitdiffstats
path: root/sshexec.1
blob: 9f379626efa963d082d2576219ef006eb2f98512 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
.TH SSHEXEC 1 sshexec

.SH NAME
sshexec - run a command through ssh(1) with normal command syntax

.SH SYNOPSIS
.B sshexec
.RB [ {
.RI [\fBssh=\fP ssh-command ]
.RI [\fBdir=\fP directory ]
.RB [ cd= ( strict | lax )]
.RB [[\fIfd\fP]{ > , >> , >| , < , <> }[ & ] = \fIfile\fP]
.RB [ asis= \fIasis-marker\fP
.RB [ nasis= \fIasis-count\fP]]
.BR } ]
.RI [ ssh-option ]\ ...\,
.I destination
.I command
.RI [ argument ]\ ...\,

.SH DESCRIPTION
The
.B sshexec
utility is a wrapper for SSH that makes it easy to run commands
directly in the SSH command.
.PP
.B sshexec
passes any argument after
.B }
to
.I ssh-command
.RB ( ssh
if not specified), but it
rewrites
.I command
and the
.IR argument s
to one argument that can be passed into
.BR ssh (1)
to describe each argument as separate arguments.
It may also rewrite
.I destination
to remove information that's not supported by
.BR ssh (1)
and inserts extra arguments after it
(it may also add a
.B --
argument immediately before
.IR destination )
to cause the remote shell it change working directory to
.IR directory ,
if specified, and execute the provided
.I command
and
.IR argument s
as a regular command rather than as shell code joined
by together by spaces.

.SH OPTIONS
.B sshexec
options may be placed at the very beginning enclosed with
the arguments
.B {
and
.BR } .
.B sshexec
options, if any, shall be placed in the same
.B {
.BR } -group.
Any other option will be passed as is to the
.BR ssh (1)
utility or
.IR ssh-command .
The
.B sshexec
utility has a build it list of options recognised by the
.BR ssh (1)
utility and will not allow anything matching this list.
The
.B sshexec
utility does not allow mixing options and operands: no
option may be placed after
.IR destination ,
such options will be treated as the
.I command
or an
.IR argument .
.PP
The following
.B sshexec
options are supported:
.TP
.BI ssh= ssh-command
Instead of looking for
.B ssh
in
.IR PATH ,
the
.B sshexec
utility shall use
.IR ssh-command ,
which it will look for in
.I PATH
if it is only a file name (does not contain a slash
.RB ( / )).
.TP
.BI dir= directory
In the remote, change working directory to
.I directory
before executing
.IR command .
.TP
.B cd=strict
Fail without executing the
.I command
if it's not possible to set
.I directory
as the remote working directory.
.TP
.B cd=lax
Continue (but warn) executing the
.I command
even if it's not possible to set
.I directory
as the remote working directory.
.TP
.IB \fR[\fPfd\fP]\fP >= file
After changing working directory (assuming one is specified),
create or truncate the specified
.I file
and open it for writing, using file descriptor number
.IR fd .
(Default
.I fd
is 1 (standard output).)
.TP
.IB \fR[\fPfd\fP]\fP >>= file
After changing working directory (assuming one is specified),
create the specified
.I file
if it does not exist and open it for writing in
append-mode, using file descriptor number
.IR fd .
(Default
.I fd
is 1 (standard output).)
.TP
.IB \fR[\fPfd\fP]\fP >|= file
After changing working directory (assuming one is specified),
create the specified
.IR file ,
but fail if it already exists, and open it for writing,
using file descriptor number
.IR fd .
(Default
.I fd
is 1 (standard output).)
.TP
.IB \fR[\fPfd\fP]\fP <= file
After changing working directory (assuming one is specified),
open the specified
.IR file ,
for reading, using file descriptor number
.IR fd .
(Default
.I fd
is 0 (standard input).)
.TP
.IB \fR[\fPfd\fP]\fP <>= file
After changing working directory (assuming one is specified),
open the specified
.IR file ,
for reading and writing, creating it if it does not
already exist, using file descriptor number
.IR fd .
(Default
.I fd
is 0 (standard input).)
.TP
.IB \fR[\fPfd\fP]\fP \fR{\fP>\fP,\fP>>\fP,\fP>|\fP}\fP&= file
Duplicate the file descriptor
.I fd
giving the new file descriptor the number
.IR file .
(Default
.I fd
is 1 (standard output).)
.TP
.IB \fR[\fPfd\fP]\fP \fR{\fP>\fP,\fP>>\fP,\fP>|\fP}\fP&=-
Close the file descriptor
.IR fd .
(Default
.I fd
is 1 (standard output).)
.TP
.IB \fR[\fPfd\fP]\fP \fR{\fP<\fP,\fP<>\fP}\fP&= file
Duplicate the file descriptor
.I fd
giving the new file descriptor the number
.IR file .
(Default
.I fd
is 0 (standard input).)
.TP
.IB \fR[\fPfd\fP]\fP \fR{\fP<\fP,\fP<>\fP}\fP&=-
Close the file descriptor
.IR fd .
(Default
.I fd
is 0 (standard input).)
.TP
.BI asis= asis-marker
Any
.I argument
equal to
.I asis-marker
will be skipped over and instead the next argument
(regardless of whether it to is equal to
.IR asis-marker )
will be interpreted as raw shell code string that
shall be inserted without escaping.
.TP
.BI masis= asis-count
If specified,
.I asis-marker
shall only have it's specified affect up to
.I asis-count
times.

.SH OPERANDS
The following operands are supported:
.TP
.I destination
The destination to connect and log into. It shall be either in
the form
.RI [ user\fP\fB@ ] hostname [\fB:\fP directory ]
or in the form
.BR ssh [ exec ] :// [\fIuser @ ]\fIhostname\fP[ : \fIport\fP][ / \fIdirectory\fP].

.I user
shall be the name of the remote user. If not specified,
the name of the local user running the utility will be used.

.I hostname
shall be the address to the remote machine.

.I port
shall be the port or service name for the port to
connect to on the remote machine.

.I directory
shall be directory to change the remote working directory.
This is an alternative to (with the exact same behaviour)
to the
.B dir
option and cannot be combined with it.
.TP
.IR command \ [ argument ]\ ...\,
Whereas the
.BR ssh (1)
utility would simply join the
.I command
and
.I argument
arguments with a space between each of them as pass it
to the remote shell for execution, the
.B sshexec
utility forces the remote shell to treat each of the
as separate arguments and cause the shell to executing
them as a non-builtin command.

.I command
must not contain an equals sign
.RB ( = )
or be just a dash
.RB (\(dq - \(dq).

.SH STDIN
The
.B sshexec
utility itself does not use the standard input.

.SH INPUT FILES
None.

.SH ENVIRONMENT VARIABLES
The following environment variables affects the execution of
.BR sshexec :
.TP
.I PATH
Default. See to the Base Definitions volume of POSIX.1-2017, Section 8.3, Other Environment Variables.
This environment variable affects where the
.B sshexec
utility can find the
.BR ssh (1)
utility or
.IR ssh-command .
.TP
.I SSHEXEC_OPTS_NO_ARG
List of options that
.B sshexec
shall interpret as
.BR ssh (1)
options that do not have any argument.
(Default is
.BR 46AaCfGgKkMNnqsTtVvXxYy ,
meaning the options
.BR -4 ,
.BR -6 ,
.BR -A ,
.BR -a ,
.BR -C ,
.BR -f ,
.BR -G ,
.BR -g ,
.BR -K ,
.BR -k ,
.BR -M ,
.BR -N ,
.BR -n ,
.BR -q ,
.BR -s ,
.BR -T ,
.BR -t ,
.BR -V ,
.BR -v ,
.BR -X ,
.BR -x ,
.BR -Y ,
and
.BR -y .)
.TP
.I SSHEXEC_OPTS_ARG
List of options that
.B sshexec
shall interpret as
.BR ssh (1)
options that have an argument.
(Default is
.BR BbcDEeFIiJLlmOoPpQRSWw ,
meaning the options
.BR -B ,
.BR -b ,
.BR -c ,
.BR -D ,
.BR -E ,
.BR -e ,
.BR -F ,
.BR -I ,
.BR -i ,
.BR -J ,
.BR -L ,
.BR -l ,
.BR -m ,
.BR -O ,
.BR -o ,
.BR -P ,
.BR -p ,
.BR -Q ,
.BR -R ,
.BR -S ,
.BR -W ,
and
.BR -w .)
.TP
.I SSHEXEC_OPTS_OPT_ATTACHED_ARG
List of options that
.B sshexec
shall interpret as
.BR ssh (1)
options that have an argument only if
there are additional characters after
the option character in the same
command line argument. (Default is
the empty string, meaning no options.)
.TP
.I SSHEXEC_OPTS_OPT_ARG
List of options that
.B sshexec
shall interpret as
.BR ssh (1)
options that have an argument if there
are additional characters after
the option character in the same
command line argument or if argument is
followed directly by another argument
which does not start with a dash
.RB ( - ).
(Default is
the empty string, meaning no options.)
.TP
.I SSHEXEC_LONG_OPTS_NO_ARG
Space-separated list of long options that
.B sshexec
shall interpret as
.BR ssh (1)
options that do not have any argument
unless it is followed directly by an
equals sign
.RB ( = )
in the same command line argument.
Options that do not start with two dashes
.RB ( -- )
are silently ignored. (Default is the
empty string, meaning no options.)
.TP
.I SSHEXEC_LONG_OPTS_ARG
Space-separated list of long options that
.B sshexec
shall interpret as
.BR ssh (1)
options that have an argument that must
either be specified in the next command
line argument or after an
equals sign
.RB ( = )
the shall directly follow the option
string in the same command line argument.
Options that do not start with two dashes
.RB ( -- )
are silently ignored. (Default is the
empty string, meaning no options.)
.TP
.I SSHEXEC_LONG_OPTS_OPT_ARG
Space-separated list of long options that
.B sshexec
shall interpret as
.BR ssh (1)
options that have an argument if it is
the option string is is directly followed
by equals sign
.RB ( = )
in the same command line argument or if
argument is followed directly by another
argument which does not start with a dash
.RB ( - ).
Options that do not start with two dashes
.RB ( -- )
are silently ignored. (Default is the
empty string, meaning no options.)
.PP
Other environment variables may affect the execution of the
.BR ssh (1)
utility.

.SH ASYNCHRONOUS EVENTS
Default.

.SH STDOUT
The
.B sshexec
utility itself does not use the standard output.

.SH STDERR
The standard error is used for diagnostic messages in the
.B sshexec
utility itself.

.SH OUTPUT FILES
None.

.SH EXTENDED DESCRIPTION
None.

.SH EXIT STATUS
The
.B sshexec
utility exits with the exit status of the
.BR ssh (1)
utility or with 255 if an error occurred.

.SH CONSEQUENCES OF ERRORS
Default.

.SH APPLICATION USAGE
None.

.SH EXAMPLES
None.

.SH RATIONALE
The restrictions on
.I command
is in place to avoid unspecified behaviour.

.SH NOTES
None.

.SH BUGS
The remote shell must be sufficiently similar to
.BR sh (1posix).
Namely, it must support the
.B cd
builtin command and the commands
.B exec
and
.B printf
is expected by POSIX. Additionally, it must support
.BR \(dq$(\ )\(dq ,
.BR \(aq\ \(aq ,
and
.BR && ,
and argument separation with the SP character.
The remote shell must also not treat any alphanumeric
character, underscore
.RB ( _ )
or slash
.RB ( / )
as special characters.

.SH FUTURE DIRECTIONS
None.

.SH SEE ALSO
.BR ssh (1),
.BR sshcd (1)

.SH AUTHORS
Mattias Andrée
.RI < m@maandree.se >