pec2 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,368 @@
1
+ .\" Man page for pssh. See "man 7 man" and "man man-pages" for formatting info.
2
+ .TH pssh 1 "January 24, 2012"
3
+
4
+ .SH NAME
5
+ pssh \(em parallel ssh program
6
+
7
+
8
+ .SH SYNOPSIS
9
+ .B pssh
10
+ .RB [ \-vAiIP ]
11
+ .RB [ \-h
12
+ .IR hosts_file ]
13
+ .RB [ \-H
14
+ .RI [ user @] host [: port ]]
15
+ .RB [ \-l
16
+ .IR user ]
17
+ .RB [ \-p
18
+ .IR par ]
19
+ .RB [ \-o
20
+ .IR outdir ]
21
+ .RB [ \-e
22
+ .IR errdir ]
23
+ .RB [ \-t
24
+ .IR timeout ]
25
+ .RB [ \-O
26
+ .IR options ]
27
+ .RB [ \-x
28
+ .IR args ]
29
+ .RB [ \-X
30
+ .IR arg ]
31
+ .I command ...
32
+
33
+ .B pssh \-I
34
+ .RB [ \-vAiIP ]
35
+ .RB [ \-h
36
+ .IR hosts_file ]
37
+ .RB [ \-H
38
+ .RI [ user @] host [: port ]]
39
+ .RB [ \-l
40
+ .IR user ]
41
+ .RB [ \-p
42
+ .IR par ]
43
+ .RB [ \-o
44
+ .IR outdir ]
45
+ .RB [ \-e
46
+ .IR errdir ]
47
+ .RB [ \-t
48
+ .IR timeout ]
49
+ .RB [ \-O
50
+ .IR options ]
51
+ .RB [ \-x
52
+ .IR args ]
53
+ .RB [ \-X
54
+ .IR arg ]
55
+ .RI [ command
56
+ .IR ... ]
57
+
58
+
59
+ .SH DESCRIPTION
60
+ .PP
61
+ .B pssh
62
+ is a program for executing ssh in parallel on a number of hosts. It provides
63
+ features such as sending input to all of the processes, passing a password
64
+ to ssh, saving output to files, and timing out.
65
+
66
+ The PSSH_NODENUM and PSSH_HOST environment variables are sent to the remote
67
+ host. The PSSH_NODENUM variable is assigned a unique number for each ssh
68
+ connection, starting with 0 and counting up. The PSSH_HOST variable is
69
+ assigned the name of the host as specified in the hosts list. Note that sshd
70
+ drops environment variables by default, so sshd_config on the remote host must
71
+ include the line:
72
+ .RS
73
+ AcceptEnv PSSH_NODENUM PSSH_HOST
74
+ .RE
75
+
76
+ .SH OPTIONS
77
+
78
+ .TP
79
+ .BI \-h " host_file"
80
+ .PD 0
81
+ .TP
82
+ .BI \-\-hosts " host_file"
83
+ Read hosts from the given
84
+ .IR host_file .
85
+ Lines in the host file are of the form
86
+ .RI [ user @] host [: port ]
87
+ and can include blank lines and comments (lines beginning with "#").
88
+ If multiple host files are given (the
89
+ .B \-h
90
+ option is used more than once), then pssh behaves as though these files
91
+ were concatenated together.
92
+ If a host is specified multiple times, then pssh will connect the
93
+ given number of times.
94
+
95
+ .TP
96
+ .B \-H
97
+ .RI [ user @] host [: port ]
98
+ .PD 0
99
+ .TP
100
+ .B \-\-host
101
+ .RI [ user @] host [: port ]
102
+ .PD 0
103
+ .TP
104
+ .B \-H
105
+ .RI \(dq[ user @] host [: port ]
106
+ [
107
+ .RI [ user @] host [: port
108
+ ] ... ]\(dq
109
+ .PD 0
110
+ .TP
111
+ .B \-\-host
112
+ .RI \(dq[ user @] host [: port ]
113
+ [
114
+ .RI [ user @] host [: port
115
+ ] ... ]\(dq
116
+ .PD 0
117
+ .IP
118
+ Add the given host strings to the list of hosts. This option may be given
119
+ multiple times, and may be used in conjunction with the
120
+ .B \-h
121
+ option.
122
+
123
+ .TP
124
+ .BI \-l " user"
125
+ .PD 0
126
+ .TP
127
+ .BI \-\-user " user"
128
+ Use the given username as the default for any host entries that don't
129
+ specifically specify a user.
130
+
131
+ .TP
132
+ .BI \-p " parallelism"
133
+ .PD 0
134
+ .TP
135
+ .BI \-\-par " parallelism"
136
+ Use the given number as the maximum number of concurrent connections.
137
+
138
+ .TP
139
+ .BI \-t " timeout"
140
+ .PD 0
141
+ .TP
142
+ .BI \-\-timeout " timeout"
143
+ Make connections time out after the given number of seconds. With a value
144
+ of 0, pssh will not timeout any connections.
145
+
146
+ .TP
147
+ .BI \-o " outdir"
148
+ .PD 0
149
+ .TP
150
+ .BI \-\-outdir " outdir"
151
+ Save standard output to files in the given directory. Filenames are of the
152
+ form
153
+ .RI [ user @] host [: port ][. num ]
154
+ where the user and port are only included for hosts that explicitly
155
+ specify them. The number is a counter that is incremented each time for hosts
156
+ that are specified more than once.
157
+
158
+ .TP
159
+ .BI \-e " errdir"
160
+ .PD 0
161
+ .TP
162
+ .BI \-\-errdir " errdir"
163
+ Save standard error to files in the given directory. Filenames are of the
164
+ same form as with the
165
+ .B \-o
166
+ option.
167
+
168
+ .TP
169
+ .BI \-x " args"
170
+ .PD 0
171
+ .TP
172
+ .BI \-\-extra-args " args"
173
+ Passes extra SSH command-line arguments (see the
174
+ .BR ssh (1)
175
+ man page for more information about SSH arguments).
176
+ This option may be specified multiple times.
177
+ The arguments are processed to split on whitespace, protect text within
178
+ quotes, and escape with backslashes.
179
+ To pass arguments without such processing, use the
180
+ .B \-X
181
+ option instead.
182
+
183
+ .TP
184
+ .BI \-X " arg"
185
+ .PD 0
186
+ .TP
187
+ .BI \-\-extra-arg " arg"
188
+ Passes a single SSH command-line argument (see the
189
+ .BR ssh (1)
190
+ man page for more information about SSH arguments). Unlike the
191
+ .B \-x
192
+ option, no processing is performed on the argument, including word splitting.
193
+ To pass multiple command-line arguments, use the option once for each
194
+ argument.
195
+
196
+ .TP
197
+ .BI \-O " options"
198
+ .PD 0
199
+ .TP
200
+ .BI \-\-options " options"
201
+ SSH options in the format used in the SSH configuration file (see the
202
+ .BR ssh_config (5)
203
+ man page for more information). This option may be specified multiple
204
+ times.
205
+
206
+ .TP
207
+ .B \-A
208
+ .PD 0
209
+ .TP
210
+ .B \-\-askpass
211
+ Prompt for a password and pass it to ssh. The password may be used for
212
+ either to unlock a key or for password authentication.
213
+ The password is transferred in a fairly secure manner (e.g., it will not show
214
+ up in argument lists). However, be aware that a root user on your system
215
+ could potentially intercept the password.
216
+
217
+ .TP
218
+ .B \-i
219
+ .PD 0
220
+ .TP
221
+ .B \-\-inline
222
+ Display standard output and standard error as each host completes.
223
+
224
+ .TP
225
+ .B \-\-inline\-stdout
226
+ Display standard output (but not standard error) as each host completes.
227
+
228
+ .TP
229
+ .B \-v
230
+ .PD 0
231
+ .TP
232
+ .B \-\-verbose
233
+ Include error messages from ssh with the
234
+ .B \-i
235
+ and
236
+ .B \e
237
+ options.
238
+
239
+ .TP
240
+ .B \-I
241
+ .PD 0
242
+ .TP
243
+ .B \-\-send-input
244
+ Read input and send to each ssh process. Since ssh allows a command script to
245
+ be sent on standard input, the
246
+ .B \-I
247
+ option may be used in lieu of the command argument.
248
+
249
+ .TP
250
+ .B \-P
251
+ .PD 0
252
+ .TP
253
+ .B \-\-print
254
+ Display output as it arrives. This option is of limited usefulness because
255
+ output from different hosts are interleaved.
256
+
257
+
258
+ .SH EXAMPLES
259
+
260
+ .PP
261
+ Connect to host1 and host2, and print "hello, world" from each:
262
+ .RS
263
+ pssh -i -H "host1 host2" echo "hello, world"
264
+ .RE
265
+
266
+ .PP
267
+ Print "hello, world" from each host specified in the file hosts.txt:
268
+ .RS
269
+ pssh -i -h hosts.txt echo "hello, world"
270
+ .RE
271
+
272
+ .PP
273
+ Run a command as root with a prompt for the root password:
274
+ .RS
275
+ pssh -i -h hosts.txt -A -l root echo hi
276
+ .RE
277
+
278
+ .PP
279
+ Run a long command without timing out:
280
+ .RS
281
+ pssh -i -h hosts.txt -t 0 sleep 10000
282
+ .RE
283
+
284
+ .PP
285
+ If the file hosts.txt has a large number of entries, say 100, then the
286
+ parallelism option may also be set to 100 to ensure that the commands are run
287
+ concurrently:
288
+ .RS
289
+ pssh -i -h hosts.txt -p 100 -t 0 sleep 10000
290
+ .RE
291
+
292
+ .PP
293
+ Run a command without checking or saving host keys:
294
+ .RS
295
+ pssh -i -H host1 -H host2 -x "-O StrictHostKeyChecking=no -O UserKnownHostsFile=/dev/null -O GlobalKnownHostsFile=/dev/null" echo hi
296
+ .RE
297
+
298
+ .PP
299
+ Print the node number for each connection (this will print 0, 1, and 2):
300
+ .RS
301
+ pssh -i -H host1 -H host1 -H host2 'echo $PSSH_NODENUM'
302
+ .RE
303
+
304
+ .SH TIPS
305
+
306
+ .PP
307
+ If you have a set of hosts that you connect to frequently with specific
308
+ options, it may be helpful to create an alias such as:
309
+ .RS
310
+ alias pssh_servers="pssh -h /path/to/server_list.txt -l root -A"
311
+ .RE
312
+
313
+ .PP
314
+ The ssh_config file can include an arbitrary number of Host sections. Each
315
+ host entry specifies ssh options which apply only to the given host. Host
316
+ definitions can even behave like aliases if the HostName option is included.
317
+ This ssh feature, in combination with pssh host files, provides a tremendous
318
+ amount of flexibility.
319
+
320
+
321
+ .SH EXIT STATUS
322
+
323
+ .PP
324
+ The exit status codes from pssh are as follows:
325
+
326
+ .TP
327
+ .B 0
328
+ Success
329
+
330
+ .TP
331
+ .B 1
332
+ Miscellaneous error
333
+
334
+ .TP
335
+ .B 2
336
+ Syntax or usage error
337
+
338
+ .TP
339
+ .B 3
340
+ At least one process was killed by a signal or timed out.
341
+
342
+ .TP
343
+ .B 4
344
+ All processes completed, but at least one ssh process reported an error
345
+ (exit status 255).
346
+
347
+ .TP
348
+ .B 5
349
+ There were no ssh errors, but at least one remote command had a non-zero exit
350
+ status.
351
+
352
+
353
+ .SH AUTHORS
354
+ .PP
355
+ Written by
356
+ Brent N. Chun <bnc@theether.org> and
357
+ Andrew McNabb <amcnabb@mcnabbs.org>.
358
+
359
+ http://code.google.com/p/parallel-ssh/
360
+
361
+
362
+ .SH SEE ALSO
363
+ .BR ssh (1),
364
+ .BR ssh_config(5),
365
+ .BR pscp (1),
366
+ .BR prsync (1),
367
+ .BR pslurp (1),
368
+ .BR pnuke (1),
File without changes
@@ -0,0 +1,102 @@
1
+ #!/usr/bin/env python
2
+ # -*- Mode: python -*-
3
+
4
+ # Copyright (c) 2009-2012, Andrew McNabb
5
+
6
+ """Implementation of SSH_ASKPASS to get a password to ssh from pssh.
7
+
8
+ The password is read from the socket specified by the environment variable
9
+ PSSH_ASKPASS_SOCKET. The other end of this socket is pssh.
10
+
11
+ The ssh man page discusses SSH_ASKPASS as follows:
12
+ If ssh needs a passphrase, it will read the passphrase from the current
13
+ terminal if it was run from a terminal. If ssh does not have a terminal
14
+ associated with it but DISPLAY and SSH_ASKPASS are set, it will execute
15
+ the program specified by SSH_ASKPASS and open an X11 window to read the
16
+ passphrase. This is particularly useful when calling ssh from a .xsession
17
+ or related script. (Note that on some machines it may be necessary to
18
+ redirect the input from /dev/null to make this work.)
19
+ """
20
+
21
+ import os
22
+ import socket
23
+ import sys
24
+ import textwrap
25
+
26
+ bin_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
27
+ askpass_bin_path = os.path.join(bin_dir, 'pssh-askpass')
28
+ ASKPASS_PATHS = (askpass_bin_path,
29
+ '/usr/libexec/pssh/pssh-askpass',
30
+ '/usr/local/libexec/pssh/pssh-askpass',
31
+ '/usr/lib/pssh/pssh-askpass',
32
+ '/usr/local/lib/pssh/pssh-askpass')
33
+
34
+ _executable_path = None
35
+
36
+ def executable_path():
37
+ """Determines the value to use for SSH_ASKPASS.
38
+
39
+ The value is cached since this may be called many times.
40
+ """
41
+ global _executable_path
42
+ if _executable_path is None:
43
+ for path in ASKPASS_PATHS:
44
+ if os.access(path, os.X_OK):
45
+ _executable_path = path
46
+ break
47
+ else:
48
+ _executable_path = ''
49
+ sys.stderr.write(textwrap.fill("Warning: could not find an"
50
+ " executable path for askpass because PSSH was not"
51
+ " installed correctly. Password prompts will not work."))
52
+ sys.stderr.write('\n')
53
+ return _executable_path
54
+
55
+ def askpass_main():
56
+ """Connects to pssh over the socket specified at PSSH_ASKPASS_SOCKET."""
57
+
58
+ verbose = os.getenv('PSSH_ASKPASS_VERBOSE')
59
+
60
+ # It's not documented anywhere, as far as I can tell, but ssh may prompt
61
+ # for a password or ask a yes/no question. The command-line argument
62
+ # specifies what is needed.
63
+ if len(sys.argv) > 1:
64
+ prompt = sys.argv[1]
65
+ if verbose:
66
+ sys.stderr.write('pssh-askpass received prompt: "%s"\n' % prompt)
67
+ if not prompt.strip().lower().endswith('password:'):
68
+ sys.stderr.write(prompt)
69
+ sys.stderr.write('\n')
70
+ sys.exit(1)
71
+ else:
72
+ sys.stderr.write('Error: pssh-askpass called without a prompt.\n')
73
+ sys.exit(1)
74
+
75
+ address = os.getenv('PSSH_ASKPASS_SOCKET')
76
+ if not address:
77
+ sys.stderr.write(textwrap.fill("pssh error: SSH requested a password."
78
+ " Please create SSH keys or use the -A option to provide a"
79
+ " password."))
80
+ sys.stderr.write('\n')
81
+ sys.exit(1)
82
+
83
+ sock = socket.socket(socket.AF_UNIX)
84
+ try:
85
+ sock.connect(address)
86
+ except socket.error:
87
+ _, e, _ = sys.exc_info()
88
+ message = e.args[1]
89
+ sys.stderr.write("Couldn't bind to %s: %s.\n" % (address, message))
90
+ sys.exit(2)
91
+
92
+ try:
93
+ password = sock.makefile().read()
94
+ except socket.error:
95
+ sys.stderr.write("Socket error.\n")
96
+ sys.exit(3)
97
+
98
+ print(password)
99
+
100
+
101
+ if __name__ == '__main__':
102
+ askpass_main()