aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2016-08-31 13:48:09 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2016-08-31 13:48:09 +0300
commit03b27c897f90ce71c6d315d788d47e15eb2b247f (patch)
treef638318ce93c953db49cad4eb3593982b9b39a5d
parentb94c2ec951d3d7ada55ddae3530b882799035cd7 (diff)
downloadrex-03b27c897f90ce71c6d315d788d47e15eb2b247f.tar.gz
rex-03b27c897f90ce71c6d315d788d47e15eb2b247f.tar.bz2
Improve -D functionality
* rex.exp: Expand {} in the argument list to the list of arguments to -D options. Expand {N} to the Nth option argument. * rex.man8: Document changes.
-rwxr-xr-xrex.exp45
-rw-r--r--rex.man839
2 files changed, 70 insertions, 14 deletions
diff --git a/rex.exp b/rex.exp
index 8b6d0d0..f9f9f0e 100755
--- a/rex.exp
+++ b/rex.exp
@@ -1101,7 +1101,7 @@ proc runcmd {hosts command} {
spawn -noecho ssh [hostuser $host]@$host
lappend sidlist $spawn_id
set sidinfo($spawn_id,host) $host
- debug 1 "$host on $spawn_id"
+ debug 2 "$host on $spawn_id"
set sidinfo($spawn_id,state) INIT
set sidinfo($spawn_id,zsh-quirk) [config_option zsh-quirk]
set sidinfo($spawn_id,earlycmd) [hostearlycmd $host]
@@ -1273,7 +1273,11 @@ proc runcmd {hosts command} {
wait -i $sid
} elseif {$sidinfo($sid,state) == "COPY"} {
debug 2 "$sidinfo($sid,cmd) finished"
- set cmd "$config(sudo)sh $command"
+ if [config_option script] {
+ set cmd "$config(sudo)sh $command"
+ } else {
+ set cmd "$config(sudo)$command"
+ }
debug 2 "sending $cmd to $sidinfo($sid,master)"
send -i $sidinfo($sid,master) "$cmd\r"
set sidinfo($sidinfo($sid,master),state) COMMAND
@@ -1616,12 +1620,41 @@ if {![config_option copy]} {
if [regexp {[|\n]} "$config(command)"] {
set config(option,script) 2
} else {
+ set newcom [list]
foreach c $config(command) {
- if [regexp {[ \t\n;]} "$c"] {
- set config(option,script) 2
- break
- }
+ switch -regexp -matchvar match -- $c {
+ {[ \t\n;]} {
+ set config(option,script) 2
+ lappend newcom $c
+ }
+ "{([0-9]+)}" {
+ if [info exists config(data)] {
+ set i [expr [lindex $match 1] - 1]
+ if {$i < [llength $config(data)]} {
+ lappend newcom [lindex $config(data) $i]
+ } else {
+ terror "{$i} out of range"
+ exit 1
+ }
+ } else {
+ terror "{N} used in the absence of -D"
+ }
+ }
+ "{}" {
+ if [info exists config(data)] {
+ foreach d $config(data) {
+ lappend newcom $d
+ }
+ } else {
+ terror "{} used in the absence of -D"
+ }
+ }
+ default {
+ lappend newcom $c
+ }
+ }
}
+ set config(command) $newcom
}
if { [config_option script] == 2 } {
diff --git a/rex.man8 b/rex.man8
index 217bff0..d8b53b8 100644
--- a/rex.man8
+++ b/rex.man8
@@ -13,38 +13,40 @@
.\"
.\" You should have received a copy of the GNU General Public License
.\" along with Rex. If not, see <http://www.gnu.org/licenses/>.
-.TH REX 8 "August 30, 2016" "REX" "Rex User Reference"
+.TH REX 8 "August 31, 2016" "REX" "Rex User Reference"
.ds ET /etc
.SH NAME
rex \- remote execution utility
.SH SYNOPSIS
\fBrex\fR\
[\fB\-CEINPSVZbcdefhilnqsw\fR]\
- [\fB\-C\fR \fIFILE\fR]\
- [\fB\-H\fR \fINAME\fR[\fB,\fINAME\fR...]]\
- [\fB\-g\fR \fIGROUP\fR]\
+ [\fB\-D\fR \fIFILE\fR]\
+ [\fB\-c\fR \fIFILE\fR]\
[\fB\-e\fR [\fIWORD\fR]]\
+ [\fB\-g\fR \fIGROUP\fR]\
+ [\fB\-H\fR \fINAME\fR[\fB,\fINAME\fR...]]\
[\fB\-j\fR \fIN\fR]\
[\fB\-s\fR \fINAME\fR]\
[\fB\-u\fR \fINAME\fR]\
[\fB\-X\fR \fIHOST[\fB,\fINAME\fR...]]\
[\fB\-x\fR \fISCRIPT\fR]\
[\fB\-\-buffer\-output\fR]\
- [\fB\-\-ignore\-hosts\fR]\
[\fB\-\-config=\fIFILE\fR]\
[\fB\-\-confirm\fR]\
+ [\fB\-\-data\-file=\fIFILE\fR]\
[\fB\-\-debug\fR]\
[\fB\-\-exclude\-host=\fIHOST\fR]\
[\fB\-\-group=\fIGROUP\fR]\
[\fB\-\-host=\fINAME\fR]\
+ [\fB\-\-ignore\-hosts\fR]\
[\fB\-\-interactive\fR]\
[\fB\-\-jobs=\fIN\fR]\
[\fB\-\-list\-groups\fR]\
[\fB\-\-log\fR]\
- [\fB\-\-noop\fR]\
- [\fB\-\-no\-resolve\fR]\
- [\fB\-\-no\-init\-file\fR]\
[\fB\-\-no\-host\-header\fR]\
+ [\fB\-\-no\-init\-file\fR]\
+ [\fB\-\-no\-resolve\fR]\
+ [\fB\-\-noop\fR]\
[\fB\-\-prefix\fR]\
[\fB\-\-program=\fISCRIPT\fR]\
[\fB\-\-script\fR]\
@@ -326,6 +328,23 @@ Copy arguments (\fISRC\fR...) to \fIDST\fR on each host.
\fB\-C\fR, \fB\-\-config=\fIFILE\fR
Read config from \fIFILE\fR.
.TP
+\fB\-D\fR, \fB\-\-data\-file=\fIFILE\fR
+Declares \fIFILE\fR as a data file which will be used by
+\fICOMMAND\fR. The file will be copied to each host prior to running
+the command on it.
+
+Multiple files can be specified by repeating the \fB\-D\fR option as
+many times as needed.
+
+If \fB\-D \fIFILE\fR option is given, the string \fB{}\fR passed as one of the
+\fIARGS\fR is replaced by \fIFILE\fR on the target machine. If
+several \fB\-D\fR options are given, \fB{}\fR is replaced by their
+arguments. For example, the command
+.B rex -D a -d D proc '{}'
+copies files \fBa\fR and \fBb\fR to the target machine and then runs
+the command \fBproc a b\fR. Notice the use of quotes to prevent curly
+braces from being misinterpreted by the shell.
+.TP
.BR \-d ", " \-\-debug
Increase debugging level.
.TP
@@ -431,6 +450,10 @@ The \fBconfig\fR variable is an associative array keeping the
configuration of \fBrex\fR. The \fBrc\fR scripts are free to modify
it as they see fit. The valid keys in \fBconfig\fR are:
.TP
+.B data
+(list) A list of file names to copy to each host prior to running
+the command. See the description of the \fB\-\-data\-file\fR option.
+.TP
.B debug
(integer) Debug verbosity level. Defaults to 0, it is increased by
one with each \fB\-d\fR (\fB\-\-debug\fR) option. Biggest possible

Return to:

Send suggestions and report system problems to the System administrator.