pec2 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/exe/bin/pssh ADDED
@@ -0,0 +1,118 @@
1
+ #!/usr/bin/env python
2
+ # -*- Mode: python -*-
3
+
4
+ # Copyright (c) 2009-2012, Andrew McNabb
5
+ # Copyright (c) 2003-2008, Brent N. Chun
6
+
7
+ """Parallel ssh to the set of nodes in hosts.txt.
8
+
9
+ For each node, this essentially does an "ssh host -l user prog [arg0] [arg1]
10
+ ...". The -o option can be used to store stdout from each remote node in a
11
+ directory. Each output file in that directory will be named by the
12
+ corresponding remote node's hostname or IP address.
13
+ """
14
+
15
+ import fcntl
16
+ import os
17
+ import sys
18
+
19
+ parent, bindir = os.path.split(os.path.dirname(os.path.abspath(sys.argv[0])))
20
+ if os.path.exists(os.path.join(parent, 'psshlib')):
21
+ sys.path.insert(0, parent)
22
+
23
+ from psshlib import psshutil
24
+ from psshlib.manager import Manager, FatalError
25
+ from psshlib.task import Task
26
+ from psshlib.cli import common_parser, common_defaults
27
+
28
+ _DEFAULT_TIMEOUT = 60
29
+
30
+ def option_parser():
31
+ parser = common_parser()
32
+ parser.usage = "%prog [OPTIONS] command [...]"
33
+ parser.epilog = "Example: pssh -h hosts.txt -l irb2 -o /tmp/foo uptime"
34
+
35
+ parser.add_option('-i', '--inline', dest='inline', action='store_true',
36
+ help='inline aggregated output and error for each server')
37
+ parser.add_option('--inline-stdout', dest='inline_stdout',
38
+ action='store_true',
39
+ help='inline standard output for each server')
40
+ parser.add_option('-I', '--send-input', dest='send_input',
41
+ action='store_true',
42
+ help='read from standard input and send as input to ssh')
43
+ parser.add_option('-P', '--print', dest='print_out', action='store_true',
44
+ help='print output as we get it')
45
+
46
+ return parser
47
+
48
+ def parse_args():
49
+ parser = option_parser()
50
+ defaults = common_defaults(timeout=_DEFAULT_TIMEOUT)
51
+ parser.set_defaults(**defaults)
52
+ opts, args = parser.parse_args()
53
+
54
+ if len(args) == 0 and not opts.send_input:
55
+ parser.error('Command not specified.')
56
+
57
+ if not opts.host_files and not opts.host_strings:
58
+ parser.error('Hosts not specified.')
59
+
60
+ return opts, args
61
+
62
+ def do_pssh(hosts, cmdline, opts):
63
+ if opts.outdir and not os.path.exists(opts.outdir):
64
+ os.makedirs(opts.outdir)
65
+ if opts.errdir and not os.path.exists(opts.errdir):
66
+ os.makedirs(opts.errdir)
67
+ if opts.send_input:
68
+ stdin = sys.stdin.read()
69
+ else:
70
+ stdin = None
71
+ manager = Manager(opts)
72
+ for host, port, user in hosts:
73
+ cmd = ['ssh', host, '-o', 'NumberOfPasswordPrompts=1',
74
+ '-o', 'SendEnv=PSSH_NODENUM PSSH_HOST']
75
+ if opts.options:
76
+ for opt in opts.options:
77
+ cmd += ['-o', opt]
78
+ if user:
79
+ cmd += ['-l', user]
80
+ if port:
81
+ cmd += ['-p', port]
82
+ if opts.extra:
83
+ cmd.extend(opts.extra)
84
+ if cmdline:
85
+ cmd.append(cmdline)
86
+ t = Task(host, port, user, cmd, opts, stdin)
87
+ manager.add_task(t)
88
+ try:
89
+ statuses = manager.run()
90
+ except FatalError:
91
+ sys.exit(1)
92
+
93
+ if min(statuses) < 0:
94
+ # At least one process was killed.
95
+ sys.exit(3)
96
+ # The any builtin was introduced in Python 2.5 (so we can't use it yet):
97
+ #elif any(x==255 for x in statuses):
98
+ for status in statuses:
99
+ if status == 255:
100
+ sys.exit(4)
101
+ for status in statuses:
102
+ if status != 0:
103
+ sys.exit(5)
104
+
105
+ if __name__ == "__main__":
106
+ opts, args = parse_args()
107
+ cmdline = " ".join(args)
108
+ try:
109
+ hosts = psshutil.read_host_files(opts.host_files,
110
+ default_user=opts.user)
111
+ except IOError:
112
+ _, e, _ = sys.exc_info()
113
+ sys.stderr.write('Could not open hosts file: %s\n' % e.strerror)
114
+ sys.exit(1)
115
+ if opts.host_strings:
116
+ for s in opts.host_strings:
117
+ hosts.extend(psshutil.parse_host_string(s, default_user=opts.user))
118
+ do_pssh(hosts, cmdline, opts)
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env python
2
+
3
+ import os
4
+ import sys
5
+
6
+ parent, bindir = os.path.split(os.path.dirname(os.path.abspath(sys.argv[0])))
7
+ if os.path.exists(os.path.join(parent, 'psshlib')):
8
+ sys.path.insert(0, parent)
9
+
10
+ from psshlib.askpass_client import askpass_main
11
+ askpass_main()
@@ -0,0 +1,268 @@
1
+ .\" Man page for pssh. See "man 7 man" and "man man-pages" for formatting info.
2
+ .TH pnuke 1 "January 24, 2012"
3
+
4
+ .SH NAME
5
+ pnuke \(em parallel process kill program
6
+
7
+
8
+ .SH SYNOPSIS
9
+ .B pnuke
10
+ .RB [ \-vA ]
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 pattern
32
+
33
+
34
+ .SH DESCRIPTION
35
+ .PP
36
+ .B pnuke
37
+ is a program for killing processes in parallel on a number of hosts. It
38
+ provides features such as passing a password to ssh, saving output to files,
39
+ and timing out.
40
+
41
+
42
+ .SH OPTIONS
43
+
44
+ .TP
45
+ .BI \-h " host_file"
46
+ .PD 0
47
+ .TP
48
+ .BI \-\-hosts " host_file"
49
+ Read hosts from the given
50
+ .IR host_file .
51
+ Lines in the host file are of the form
52
+ .RI [ user @] host [: port ]
53
+ and can include blank lines and comments (lines beginning with "#").
54
+ If multiple host files are given (the
55
+ .B \-h
56
+ option is used more than once), then pnuke behaves as though these files
57
+ were concatenated together.
58
+ If a host is specified multiple times, then pnuke will connect the
59
+ given number of times.
60
+
61
+ .TP
62
+ .B \-H
63
+ .RI [ user @] host [: port ]
64
+ .PD 0
65
+ .TP
66
+ .B \-\-host
67
+ .RI [ user @] host [: port ]
68
+ .PD 0
69
+ .TP
70
+ .B \-H
71
+ .RI \(dq[ user @] host [: port ]
72
+ [
73
+ .RI [ user @] host [: port
74
+ ] ... ]\(dq
75
+ .PD 0
76
+ .TP
77
+ .B \-\-host
78
+ .RI \(dq[ user @] host [: port ]
79
+ [
80
+ .RI [ user @] host [: port
81
+ ] ... ]\(dq
82
+ .PD 0
83
+ .IP
84
+ Add the given host strings to the list of hosts. This option may be given
85
+ multiple times, and may be used in conjunction with the
86
+ .B \-h
87
+ option.
88
+
89
+ .TP
90
+ .BI \-l " user"
91
+ .PD 0
92
+ .TP
93
+ .BI \-\-user " user"
94
+ Use the given username as the default for any host entries that don't
95
+ specifically specify a user.
96
+
97
+ .TP
98
+ .BI \-p " parallelism"
99
+ .PD 0
100
+ .TP
101
+ .BI \-\-par " parallelism"
102
+ Use the given number as the maximum number of concurrent connections.
103
+
104
+ .TP
105
+ .BI \-t " timeout"
106
+ .PD 0
107
+ .TP
108
+ .BI \-\-timeout " timeout"
109
+ Make connections time out after the given number of seconds. With a value
110
+ of 0, pnuke will not timeout any connections.
111
+
112
+ .TP
113
+ .BI \-o " outdir"
114
+ .PD 0
115
+ .TP
116
+ .BI \-\-outdir " outdir"
117
+ Save standard output to files in the given directory. Filenames are of the
118
+ form
119
+ .RI [ user @] host [: port ][. num ]
120
+ where the user and port are only included for hosts that explicitly
121
+ specify them. The number is a counter that is incremented each time for hosts
122
+ that are specified more than once.
123
+
124
+ .TP
125
+ .BI \-e " errdir"
126
+ .PD 0
127
+ .TP
128
+ .BI \-\-errdir " errdir"
129
+ Save standard error to files in the given directory. Filenames are of the
130
+ same form as with the
131
+ .B \-o
132
+ option.
133
+
134
+ .TP
135
+ .BI \-x " args"
136
+ .PD 0
137
+ .TP
138
+ .BI \-\-extra-args " args"
139
+ Passes extra SSH command-line arguments (see the
140
+ .BR ssh (1)
141
+ man page for more information about SSH arguments).
142
+ This option may be specified multiple times.
143
+ The arguments are processed to split on whitespace, protect text within
144
+ quotes, and escape with backslashes.
145
+ To pass arguments without such processing, use the
146
+ .B \-X
147
+ option instead.
148
+
149
+ .TP
150
+ .BI \-X " arg"
151
+ .PD 0
152
+ .TP
153
+ .BI \-\-extra-arg " arg"
154
+ Passes a single SSH command-line argument (see the
155
+ .BR ssh (1)
156
+ man page for more information about SSH arguments). Unlike the
157
+ .B \-x
158
+ option, no processing is performed on the argument, including word splitting.
159
+ To pass multiple command-line arguments, use the option once for each
160
+ argument.
161
+
162
+ .TP
163
+ .BI \-O " options"
164
+ .PD 0
165
+ .TP
166
+ .BI \-\-options " options"
167
+ SSH options in the format used in the SSH configuration file (see the
168
+ .BR ssh_config (5)
169
+ man page for more information). This option may be specified multiple
170
+ times.
171
+
172
+ .TP
173
+ .B \-A
174
+ .PD 0
175
+ .TP
176
+ .B \-\-askpass
177
+ Prompt for a password and pass it to ssh. The password may be used for
178
+ either to unlock a key or for password authentication.
179
+ The password is transferred in a fairly secure manner (e.g., it will not show
180
+ up in argument lists). However, be aware that a root user on your system
181
+ could potentially intercept the password.
182
+
183
+ .TP
184
+ .B \-v
185
+ .PD 0
186
+ .TP
187
+ .B \-\-verbose
188
+ Include error messages from ssh with the
189
+ .B \-i
190
+ and
191
+ .B \e
192
+ options.
193
+
194
+
195
+ .\" .SH EXAMPLES
196
+
197
+ .\" .PP
198
+ .\" Connect to host1 and host2, and print "hello, world" from each:
199
+ .\" .RS
200
+ .\" pssh -i -H "host1 host2" echo "hello, world"
201
+ .\" .RE
202
+
203
+
204
+ .SH TIPS
205
+
206
+ .\" .PP
207
+ .\" If you have a set of hosts that you connect to frequently with specific
208
+ .\" options, it may be helpful to create an alias such as:
209
+ .\" .RS
210
+ .\" alias pssh_servers="pssh -h /path/to/server_list.txt -l root -A"
211
+ .\" .RE
212
+
213
+ .PP
214
+ The ssh_config file can include an arbitrary number of Host sections. Each
215
+ host entry specifies ssh options which apply only to the given host. Host
216
+ definitions can even behave like aliases if the HostName option is included.
217
+ This ssh feature, in combination with pssh host files, provides a tremendous
218
+ amount of flexibility.
219
+
220
+
221
+ .SH EXIT STATUS
222
+
223
+ .PP
224
+ The exit status codes from pnuke are as follows:
225
+
226
+ .TP
227
+ .B 0
228
+ Success
229
+
230
+ .TP
231
+ .B 1
232
+ Miscellaneous error
233
+
234
+ .TP
235
+ .B 2
236
+ Syntax or usage error
237
+
238
+ .TP
239
+ .B 3
240
+ At least one process was killed by a signal or timed out.
241
+
242
+ .TP
243
+ .B 4
244
+ All processes completed, but at least one ssh process reported an error
245
+ (exit status 255).
246
+
247
+ .TP
248
+ .B 5
249
+ There were no ssh errors, but at least one remote command had a non-zero exit
250
+ status.
251
+
252
+
253
+ .SH AUTHORS
254
+ .PP
255
+ Written by
256
+ Brent N. Chun <bnc@theether.org> and
257
+ Andrew McNabb <amcnabb@mcnabbs.org>.
258
+
259
+ http://code.google.com/p/parallel-ssh/
260
+
261
+
262
+ .SH SEE ALSO
263
+ .BR ssh (1),
264
+ .BR ssh_config(5),
265
+ .BR pssh (1),
266
+ .BR pscp (1),
267
+ .BR prsync (1),
268
+ .BR pslurp (1),
@@ -0,0 +1,299 @@
1
+ .\" Man page for prsync. See "man 7 man" and "man man-pages" for formatting info.
2
+ .TH prsync 1 "January 24, 2012"
3
+
4
+ .SH NAME
5
+ prsync \(em parallel process kill program
6
+
7
+
8
+ .SH SYNOPSIS
9
+ .B prsync
10
+ .RB [ \-vAraz ]
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
+ .RB [ \-S
32
+ .IR args ]
33
+ .I local
34
+ .I remote
35
+
36
+
37
+ .SH DESCRIPTION
38
+ .PP
39
+ .B prsync
40
+ is a program for copying files in parallel to a number of hosts. It provides
41
+ features such as passing a password to ssh, saving output to files, and timing
42
+ out.
43
+
44
+
45
+ .SH OPTIONS
46
+
47
+ .TP
48
+ .BI \-h " host_file"
49
+ .PD 0
50
+ .TP
51
+ .BI \-\-hosts " host_file"
52
+ Read hosts from the given
53
+ .IR host_file .
54
+ Lines in the host file are of the form
55
+ .RI [ user @] host [: port ]
56
+ and can include blank lines and comments (lines beginning with "#").
57
+ If multiple host files are given (the
58
+ .B \-h
59
+ option is used more than once), then prsync behaves as though these files
60
+ were concatenated together.
61
+ If a host is specified multiple times, then prsync will connect the
62
+ given number of times.
63
+
64
+ .TP
65
+ .B \-H
66
+ .RI [ user @] host [: port ]
67
+ .PD 0
68
+ .TP
69
+ .B \-\-host
70
+ .RI [ user @] host [: port ]
71
+ .PD 0
72
+ .TP
73
+ .B \-H
74
+ .RI \(dq[ user @] host [: port ]
75
+ [
76
+ .RI [ user @] host [: port
77
+ ] ... ]\(dq
78
+ .PD 0
79
+ .TP
80
+ .B \-\-host
81
+ .RI \(dq[ user @] host [: port ]
82
+ [
83
+ .RI [ user @] host [: port
84
+ ] ... ]\(dq
85
+ .PD 0
86
+ .IP
87
+ Add the given host strings to the list of hosts. This option may be given
88
+ multiple times, and may be used in conjunction with the
89
+ .B \-h
90
+ option.
91
+
92
+ .TP
93
+ .BI \-l " user"
94
+ .PD 0
95
+ .TP
96
+ .BI \-\-user " user"
97
+ Use the given username as the default for any host entries that don't
98
+ specifically specify a user.
99
+
100
+ .TP
101
+ .BI \-p " parallelism"
102
+ .PD 0
103
+ .TP
104
+ .BI \-\-par " parallelism"
105
+ Use the given number as the maximum number of concurrent connections.
106
+
107
+ .TP
108
+ .BI \-t " timeout"
109
+ .PD 0
110
+ .TP
111
+ .BI \-\-timeout " timeout"
112
+ Make connections time out after the given number of seconds. With a value
113
+ of 0, prsync will not timeout any connections.
114
+
115
+ .TP
116
+ .BI \-o " outdir"
117
+ .PD 0
118
+ .TP
119
+ .BI \-\-outdir " outdir"
120
+ Save standard output to files in the given directory. Filenames are of the
121
+ form
122
+ .RI [ user @] host [: port ][. num ]
123
+ where the user and port are only included for hosts that explicitly
124
+ specify them. The number is a counter that is incremented each time for hosts
125
+ that are specified more than once.
126
+
127
+ .TP
128
+ .BI \-e " errdir"
129
+ .PD 0
130
+ .TP
131
+ .BI \-\-errdir " errdir"
132
+ Save standard error to files in the given directory. Filenames are of the
133
+ same form as with the
134
+ .B \-o
135
+ option.
136
+
137
+ .TP
138
+ .BI \-x " args"
139
+ .PD 0
140
+ .TP
141
+ .BI \-\-extra-args " args"
142
+ Passes extra rsync command-line arguments (see the
143
+ .BR rsync (1)
144
+ man page for more information about rsync arguments).
145
+ This option may be specified multiple times.
146
+ The arguments are processed to split on whitespace, protect text within
147
+ quotes, and escape with backslashes.
148
+ To pass arguments without such processing, use the
149
+ .B \-X
150
+ option instead.
151
+
152
+ .TP
153
+ .BI \-X " arg"
154
+ .PD 0
155
+ .TP
156
+ .BI \-\-extra-arg " arg"
157
+ Passes a single rsync command-line argument (see the
158
+ .BR rsync (1)
159
+ man page for more information about rsync arguments). Unlike the
160
+ .B \-x
161
+ option, no processing is performed on the argument, including word splitting.
162
+ To pass multiple command-line arguments, use the option once for each
163
+ argument.
164
+
165
+ .TP
166
+ .BI \-O " options"
167
+ .PD 0
168
+ .TP
169
+ .BI \-\-options " options"
170
+ SSH options in the format used in the SSH configuration file (see the
171
+ .BR ssh_config (5)
172
+ man page for more information). This option may be specified multiple
173
+ times.
174
+
175
+ .TP
176
+ .B \-A
177
+ .PD 0
178
+ .TP
179
+ .B \-\-askpass
180
+ Prompt for a password and pass it to ssh. The password may be used for
181
+ either to unlock a key or for password authentication.
182
+ The password is transferred in a fairly secure manner (e.g., it will not show
183
+ up in argument lists). However, be aware that a root user on your system
184
+ could potentially intercept the password.
185
+
186
+ .TP
187
+ .B \-v
188
+ .PD 0
189
+ .TP
190
+ .B \-\-verbose
191
+ Include error messages from rsync with the
192
+ .B \-i
193
+ and
194
+ .B \e
195
+ options.
196
+
197
+ .TP
198
+ .B \-r
199
+ .PD 0
200
+ .TP
201
+ .B \-\-recursive
202
+ Recursively copy directories.
203
+
204
+ .TP
205
+ .B \-a
206
+ .PD 0
207
+ .TP
208
+ .B \-\-archive
209
+ Use rsync archive mode (rsync's \-a option).
210
+
211
+ .TP
212
+ .B \-z
213
+ .PD 0
214
+ .TP
215
+ .B \-\-compress
216
+ Use rsync compression.
217
+
218
+ .TP
219
+ .BI \-S " args"
220
+ .PD 0
221
+ .TP
222
+ .BI \-\-ssh-args " args"
223
+ Passes extra SSH command-line arguments (see the
224
+ .BR ssh (1)
225
+ man page for more information about SSH arguments).
226
+ The given value is appended to the ssh command (rsync's \-e option) without
227
+ any processing.
228
+
229
+
230
+ .\" .SH EXAMPLES
231
+
232
+ .\" .PP
233
+ .\" Connect to host1 and host2, and print "hello, world" from each:
234
+ .\" .RS
235
+ .\" pssh -i -H "host1 host2" echo "hello, world"
236
+ .\" .RE
237
+
238
+
239
+ .SH TIPS
240
+
241
+ .\" .PP
242
+ .\" If you have a set of hosts that you connect to frequently with specific
243
+ .\" options, it may be helpful to create an alias such as:
244
+ .\" .RS
245
+ .\" alias pssh_servers="pssh -h /path/to/server_list.txt -l root -A"
246
+ .\" .RE
247
+
248
+ .PP
249
+ The ssh_config file can include an arbitrary number of Host sections. Each
250
+ host entry specifies ssh options which apply only to the given host. Host
251
+ definitions can even behave like aliases if the HostName option is included.
252
+ This ssh feature, in combination with pssh host files, provides a tremendous
253
+ amount of flexibility.
254
+
255
+
256
+ .SH EXIT STATUS
257
+
258
+ .PP
259
+ The exit status codes from prsync are as follows:
260
+
261
+ .TP
262
+ .B 0
263
+ Success
264
+
265
+ .TP
266
+ .B 1
267
+ Miscellaneous error
268
+
269
+ .TP
270
+ .B 2
271
+ Syntax or usage error
272
+
273
+ .TP
274
+ .B 3
275
+ At least one process was killed by a signal or timed out.
276
+
277
+ .TP
278
+ .B 4
279
+ All processes completed, but at least one rsync process reported an error
280
+ (exit status other than 0).
281
+
282
+
283
+ .SH AUTHORS
284
+ .PP
285
+ Written by
286
+ Brent N. Chun <bnc@theether.org> and
287
+ Andrew McNabb <amcnabb@mcnabbs.org>.
288
+
289
+ http://code.google.com/p/parallel-ssh/
290
+
291
+
292
+ .SH SEE ALSO
293
+ .BR rsync (1),
294
+ .BR ssh (1),
295
+ .BR ssh_config(5),
296
+ .BR pssh (1),
297
+ .BR prsync (1),
298
+ .BR pslurp (1),
299
+ .BR pnuke (1),