diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2016-09-10 00:09:05 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2016-09-10 00:09:05 +0300 |
commit | db178647b046335520f9cb73398c7b1a7c198238 (patch) | |
tree | bba036e656dcccb64c790e9e52bf1ea7dd860dc8 | |
parent | f473011bf4b280021cde81c944627e4df522251c (diff) | |
download | rex-db178647b046335520f9cb73398c7b1a7c198238.tar.gz rex-db178647b046335520f9cb73398c7b1a7c198238.tar.bz2 |
Implement rex copy --sudo
* rex.exp (runcp): Turn off log_user.
Handle permission denied errors.
(rex_copy_to): New option: --sudo
(main): Remove leftover debugging hook.
* rex.man8: Update.
-rwxr-xr-x | rex.exp | 29 | ||||
-rw-r--r-- | rex.man8 | 12 |
2 files changed, 39 insertions, 2 deletions
@@ -1366,6 +1366,8 @@ proc runcp {args} { debug 2 "copying: \"$cmd_stub\" to $hosts" + log_user [config_option log] + foreach host $hosts { set cmd $cmd_stub lappend cmd [hostuser $host]@$host:[lindex $args end] @@ -1380,6 +1382,14 @@ proc runcp {args} { expect { -i $sidlist + "ermission denied" { + set sid $expect_out(spawn_id) + set host $sidinfo($sid,host) + terror "[hostuser $host]@[hostname $host]: $expect_out(buffer)" + closeproc $sid + continue + } + denied { set sid $expect_out(spawn_id) set host $sidinfo($sid,host) @@ -2358,6 +2368,9 @@ proc rex_copy_to {} { user,u=NAME {log in as user NAME} { set config(user) $optarg } + sudo + {copy in privileged mode} + setsudo } if { $argc < 2 } { @@ -2375,6 +2388,21 @@ proc rex_copy_to {} { common_config_setup hostlist_setup + if {$config(sudo) != ""} { + lappend config(data) {*}[lrange $argv 0 end-1] + set config(argv) [list {cp} {*}$config(data) [lindex $argv end]] + + set config(progname) cp + set config(command) [join $config(argv)] + debug 2 "copying [llength $config(data)] files: [join $config(data)]" + debug 2 "sudo=$config(sudo), progname=$config(progname), command=$config(command) ([llength $config(command)] args)" + debug 2 "... on $config(hosts)" + mainloop runcmd "$config(sudo)$config(command)" + cleanup + return + } + + debug 1 "copying $config(argv) to $config(hosts)" mainloop runcp {*}$config(argv) cleanup @@ -2559,7 +2587,6 @@ Report bugs to <gray+rex@gnu.org.ua> set config(mode) [argcvshift] switch -- $config(mode) { - new rex_command_new run - command rex_command cp - @@ -13,7 +13,7 @@ .\" .\" 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 "September 9, 2016" "REX" "Rex User Reference" +.TH REX 8 "September 10, 2016" "REX" "Rex User Reference" .ds ET /etc .SH NAME rex \- remote execution utility @@ -641,6 +641,16 @@ Set default password (unsafe!) \fB\-P\fR, \fB\-\-prefix\fR Prefix each output line with the host name or IP. .TP +.B \-\-sudo +Switch to root privileges before copying to \fIDEST\fR. Technically, +speaking, the command + +\fBrex copy \-\-sudo \fIFILE DEST\fR + +is equivalent to + +\fBrex run \-D \fIFILE\fB cp {} \fIDEST\fR +.TP \fB\-u\fR, \fB\-\-user=\fINAME\fR Set default user name. .TP |