Jan Gehring > Rex-0.44.6.1 > bin/rex

Download:
Rex-0.44.6.1.tar.gz

Annotate this POD

CPAN RT

New  5
Open  1
View/Report Bugs
Source   Latest Release: Rex-0.51.2

(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
-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.
-f Use this file instead of Rexfile
-h Display this help
-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

Rexfile

If you run rex it will read the file Rexfile in the current working directory. A Rexfile consists 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 exexecution.

Simple Authentication

Define the user

 user "<user>";

Define the password

 password "<password>";

Set password authentication

 pass_auth;

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. 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]";

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";
 };
syntax highlighting: