++ed by:

24 PAUSE users
21 non-PAUSE users.

Ferenc Erki
and 1 contributors


(R)?ex - (Remote)? Execution


Rex is a tool to ease the execution of commands on multiple remote servers. You can define small tasks, chain tasks to batches, link them with servers or server groups, and execute them easily in your terminal.

Command line options

-b Run batch
-e Run the give code fragment
-E Execute task on the given environment
-H Execute task on these hosts
-z Execute task on hosts from this command's output
-G|-g Execute task on these group
-u Username for the ssh connection
-p Password for the ssh connection
-P Private Keyfile for the ssh connection
-K Public Keyfile for the ssh connection
-T List all known tasks.
-Tm List all known tasks in "machine readable" format
-Ty List all known tasks in YAML format
-Tv List all known tasks with all information
-f Use this file instead of Rexfile
-h Display this help
-m Monochrome output. No colors
-M Load Module instead of Rexfile
-s Use sudo for every command
-S Password for sudo
-v Display (R)?ex Version
-F Force. Don't regard lock file
-d Debug
-dd More Debug (includes Profiling Output)
-o <module> Create a compatible output for the given module
-C Turn cache OFF
-c Turn cache ON
-q Quiet mode. No Logging output
-qw Quiet mode. Only output warnings and errors
-Q Really quiet. Output nothing.
-t Number of threads to use ('parallelism' parameter)


If you run rex it will read the file Rexfile in the current working directory. A Rexfile consists of 3 major parts.

Authentication and Configuration

In that part you define the user and password you want to use to log into your servers. You can even define timeouts or the paralellism of task execution.

Simple Authentication

Define the user

 user "<user>";

Define the password

 password "<password>";

Set password authentication


Key Authentication

Define Private Key

 private_key "/path/to/your/private/key.file";

Define Public Key

 public_key "/path/to/your/public/key.file";

Define Logging

Log to a file

 logging to_file => "rex.log";

Log to syslog

 logging to_syslog => "local0";

Other Configuration parameters

Define ssh timeout

 timeout 10;

Define parallelism

 parallelism 2;

Group your servers

Rex gives you the possibility to group your servers. One way is to do it in code within the Rexfile. Another is to use a server.ini file in the same directory as the Rexfile.

Code in the Rexfile

Rex gives you the possibility to group your servers. So you don't need to type every servername multiple times.

 group "frontends" => "frontend01", "frontend02", "frontend03", "frontend04";

You can even define ranges in the servernames:

 group "frontends" => "frontend[01..04]";

Using server.ini

The same group definition can be stored in a server.ini file:


Your tasks

Create a task description

 desc "This is a long description of a task";

Create the task

 task "shortname", group => "frontends", sub {
     run "uptime";

or, if you don't have groups

 task "shortname", "frontend01", "frontend02", "frontend03", "frontend04", sub {
     run "uptime";

and with serverranges

 task "shortname", "frontend[01..04]", sub {
     run "uptime";