File: parallel-ssh.1

package info (click to toggle)
pssh 2.3.4-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 536 kB
  • sloc: python: 1,545; makefile: 15
file content (402 lines) | stat: -rw-r--r-- 9,023 bytes parent folder | download | duplicates (2)
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
.\" Man page for parallel-ssh.  See "man 7 man" and "man man-pages" for formatting info.
.TH parallel-ssh 1 "January 24, 2012"

.SH NAME
parallel-ssh \(em parallel ssh program


.SH SYNOPSIS
.B parallel-ssh
.RB [ \-vAiIP ]
.RB [ \-h
.IR hosts_file ]
.RB [ \-H
.RI [ user @] host [: port ]]
.RB [ \-g
.IR pattern ]
.RB [ \-l
.IR user ]
.RB [ \-p
.IR par ]
.RB [ \-o
.IR outdir ]
.RB [ \-e
.IR errdir ]
.RB [ \-t
.IR timeout ]
.RB [ \-O
.IR options ]
.RB [ \-x
.IR args ]
.RB [ \-X
.IR arg ]
.I command ...

.B parallel-ssh \-I
.RB [ \-vAiIP ]
.RB [ \-h
.IR hosts_file ]
.RB [ \-H
.RI [ user @] host [: port ]]
.RB [ \-g
.IR pattern ]
.RB [ \-l
.IR user ]
.RB [ \-p
.IR par ]
.RB [ \-o
.IR outdir ]
.RB [ \-e
.IR errdir ]
.RB [ \-t
.IR timeout ]
.RB [ \-O
.IR options ]
.RB [ \-x
.IR args ]
.RB [ \-X
.IR arg ]
.RI [ command
.IR ... ]


.SH DESCRIPTION
.PP
.B parallel-ssh
is a program for executing ssh in parallel on a number of hosts.  It provides
features such as sending input to all of the processes, passing a password
to ssh, saving output to files, and timing out.

The PSSH_NODENUM, PSSH_NUMNODES, PSSH_HOST environment variables are sent to
the remote host.  The PSSH_NODENUM variable is assigned a unique number for
each ssh connection, starting with 0 and counting up.  The PSSH_NUMNODES
variable is assigned the total number of node being used. The PSSH_HOST
variable is assigned the name of the host as specified in the hosts list.  Note
that sshd drops environment variables by default, so sshd_config on the remote
host must include the line:
.RS
AcceptEnv PSSH_NODENUM PSSH_NUMNODES PSSH_HOST
.RE

.SH OPTIONS

.TP
.BI \-h " host_file"
.PD 0
.TP
.BI \-\-hosts " host_file"
Read hosts from the given
.IR host_file .
Lines in the host file are of the form
.RI [ user @] host [: port ]
and can include blank lines and comments (lines beginning with "#").
If multiple host files are given (the
.B \-h
option is used more than once), then parallel-ssh behaves as though these files
were concatenated together.
If a host is specified multiple times, then parallel-ssh will connect the
given number of times.

.TP
.B \-H
.RI [ user @] host [: port ]
.PD 0
.TP
.B \-\-host
.RI [ user @] host [: port ]
.PD 0
.TP
.B \-H
.RI \(dq[ user @] host [: port ]
[
.RI [ user @] host [: port
] ... ]\(dq
.PD 0
.TP
.B \-\-host
.RI \(dq[ user @] host [: port ]
[
.RI [ user @] host [: port
] ... ]\(dq
.PD 0
.IP
Add the given host strings to the list of hosts.  This option may be given
multiple times, and may be used in conjunction with the
.B \-h
option.

.TP
.BI \-g " pattern"
.PD 0
.TP
.BI \-\-host\-glob " pattern"
Filter hosts with glob pattern
.IR pattern .
This uses the same syntax as shell globs. Make sure to quote the pattern to
prevent shell from expanding it. Examples are "*web*" and "company_*".

.TP
.BI \-l " user"
.PD 0
.TP
.BI \-\-user " user"
Use the given username as the default for any host entries that don't
specifically specify a user.

.TP
.BI \-p " parallelism"
.PD 0
.TP
.BI \-\-par " parallelism"
Use the given number as the maximum number of concurrent connections.

.TP
.BI \-t " timeout"
.PD 0
.TP
.BI \-\-timeout " timeout"
Make connections time out after the given number of seconds.  With a value
of 0, parallel-ssh will not timeout any connections.

.TP
.BI \-o " outdir"
.PD 0
.TP
.BI \-\-outdir " outdir"
Save standard output to files in the given directory.  Filenames are of the
form
.RI [ user @] host [: port ][. num ]
where the user and port are only included for hosts that explicitly
specify them.  The number is a counter that is incremented each time for hosts
that are specified more than once.

.TP
.BI \-e " errdir"
.PD 0
.TP
.BI \-\-errdir " errdir"
Save standard error to files in the given directory.  Filenames are of the
same form as with the
.B \-o
option.

.TP
.BI \-x " args"
.PD 0
.TP
.BI \-\-extra-args " args"
Passes extra SSH command-line arguments (see the
.BR ssh (1)
man page for more information about SSH arguments).
This option may be specified multiple times.
The arguments are processed to split on whitespace, protect text within
quotes, and escape with backslashes.
To pass arguments without such processing, use the
.B \-X
option instead.

.TP
.BI \-X " arg"
.PD 0
.TP
.BI \-\-extra-arg " arg"
Passes a single SSH command-line argument (see the
.BR ssh (1)
man page for more information about SSH arguments).  Unlike the
.B \-x
option, no processing is performed on the argument, including word splitting.
To pass multiple command-line arguments, use the option once for each
argument.

.TP
.BI \-O " options"
.PD 0
.TP
.BI \-\-options " options"
SSH options in the format used in the SSH configuration file (see the
.BR ssh_config (5)
man page for more information).  This option may be specified multiple
times.

.TP
.B \-A
.PD 0
.TP
.B \-\-askpass
Prompt for a password and pass it to ssh.  The password may be used for
either to unlock a key or for password authentication.
The password is transferred in a fairly secure manner (e.g., it will not show
up in argument lists).  However, be aware that a root user on your system
could potentially intercept the password.

.TP
.B \-i
.PD 0
.TP
.B \-\-inline
Display standard output and standard error as each host completes.

.TP
.B \-\-inline\-stdout
Display standard output (but not standard error) as each host completes.

.TP
.B \-v
.PD 0
.TP
.B \-\-verbose
Include error messages from ssh with the
.B \-i
and
.B \-e
options.

.TP
.B \-I
.PD 0
.TP
.B \-\-send-input
Read input and send to each ssh process.  Since ssh allows a command script to
be sent on standard input, the
.B \-I
option may be used in lieu of the command argument.

.TP
.B \-P
.PD 0
.TP
.B \-\-print
Display output as it arrives.  This option is of limited usefulness because
output from different hosts are interleaved.


.SH EXAMPLES

.PP
Connect to host1 and host2, and print "hello, world" from each:
.RS
parallel-ssh -i -H "host1 host2" echo "hello, world"
.RE

.PP
Print "hello, world" from each host specified in the file hosts.txt:
.RS
parallel-ssh -i -h hosts.txt echo "hello, world"
.RE

.PP
Run a command as root with a prompt for the root password:
.RS
parallel-ssh -i -h hosts.txt -A -l root echo hi
.RE

.PP
Run a long command without timing out:
.RS
parallel-ssh -i -h hosts.txt -t 0 sleep 10000
.RE

.PP
If the file hosts.txt has a large number of entries, say 100, then the
parallelism option may also be set to 100 to ensure that the commands are run
concurrently:
.RS
parallel-ssh -i -h hosts.txt -p 100 -t 0 sleep 10000
.RE

.PP
Run a command without checking or saving host keys:
.RS
parallel-ssh -i -H host1 -H host2 -x "-O StrictHostKeyChecking=no -O UserKnownHostsFile=/dev/null -O GlobalKnownHostsFile=/dev/null" echo hi
.RE

.PP
Print the node number for each connection (this will print 0, 1, and 2):
.RS
parallel-ssh -i -H host1 -H host1 -H host2 'echo $PSSH_NODENUM'
.RE

.SH TIPS

.PP
If you have a set of hosts that you connect to frequently with specific
options, it may be helpful to create an alias such as:
.RS
alias parallel-ssh_servers="parallel-ssh -h /path/to/server_list.txt -l root -A"
.RE

.PP
Note that when an ssh command is terminated, it does not kill remote processes
(OpenSSH bug #396 has been open since 2002).  One workaround is to instruct
ssh to allocate a pseudo-terminal, which makes it behave more like a normal
interactive ssh session.  To do this, use parallel-ssh's "-x" option to pass "-tt" to
ssh.  For example:
.RS
parallel-ssh -i -x "-tt" -h hosts.txt -t 10 sleep 1000
.RE
will ensure that all of the sleep commands will terminate (with SIGHUP) after
the 10 second timeout.

.PP
By default, ssh uses full buffering for non-interactive commands.  Line
buffering may be preferable to full buffering if you intend to look at the
files in an output directory as a command is running.  To switch ssh to use
line buffering, use its "-tt" option (which allocates a pseudo-terminal) using
the "-x" option in parallel-ssh.

.PP
The ssh_config file can include an arbitrary number of Host sections.  Each
host entry specifies ssh options which apply only to the given host.  Host
definitions can even behave like aliases if the HostName option is included.
This ssh feature, in combination with parallel-ssh host files, provides a tremendous
amount of flexibility.


.SH EXIT STATUS

.PP
The exit status codes from parallel-ssh are as follows:

.TP
.B 0
Success

.TP
.B 1
Miscellaneous error

.TP
.B 2
Syntax or usage error

.TP
.B 3
At least one process was killed by a signal or timed out.

.TP
.B 4
All processes completed, but at least one ssh process reported an error
(exit status 255).

.TP
.B 5
There were no ssh errors, but at least one remote command had a non-zero exit
status.


.SH AUTHORS
.PP
Written by
Brent N. Chun <bnc@theether.org> and
Andrew McNabb <amcnabb@mcnabbs.org>.

https://github.com/lilydjwg/parallel-ssh


.SH SEE ALSO
.BR ssh (1),
.BR ssh_config (5),
.BR parallel-scp (1),
.BR parallel-rsync (1),
.BR parallel-slurp (1),
.BR parallel-nuke (1),