Tentakel to execute commands on multiple Linux or UNIX Servers

This is Part II in a series on Execute Commands on Multiple Linux or UNIX Servers Simultaneously. The full series is Part I, Part II, and Part III. Many times, you want to execute a command not only on one server, but also on several servers. For example, find out

ADVERTISEMENTS

  • Version of kernel
  • Version of Apache web server
  • Update static html or images files on all web servers via rsync
  • Find out user information, server information, memory usage etc
  • Security/patch checking

tentakel

I have already covered how to execute commands on multiple Linux or UNIX servers via shell script. The disadvantage of script is commands do not run in parallel on all servers. However, several tools exist to automate this procedure in parallel. With the help of tool called tentakel, you run distributed command execution. It is a program for executing the same command on many hosts in parallel using ssh (it supports other methods too). Main advantage is you can create several sets of servers according requirements. For example webserver group, mail server group, home servers group etc. The command is executed in parallel on all servers in this group (time saving). By default, every result is printed to stdout (screen). The output format can be defined for each group.

How it works?

Consider the following sample setup:

admin workstation   Group                  Hosts
|----------------> www-servers        host1, host2,host3
|----------------> homeservers        192.168.1.12,192.168.1.15
IP: 192.168.1.1

You need to install tentakel on admin workstation (192.168.1.1). We have two group servers, first is group of web server with three host and another is homeservers with two hosts.

The requirements on the remote hosts (groups) need a running sshd server on the remote side. You need to setup ssh-key based login between admin workstation and all group servers/hosts to take full advantage of this tentakel distributed command execution method.

System requirement

Tentakel requires a working Python installation. It is known to work with Python 2.3. Python 2.2 and Python 2.1 are not supported. If you are using old version of python then please upgrade it.

Configuration

Let us see howto install and configure tentakel.

Step # 1 : Download tentakel

Visit sourceforge home page to download tentakel or download RPM files from tentakel home page.

Step # 2: Install tentakel

Untar source code, enter:

# tar -zxvf tentakel-2.2.tgz

You should be root user for the install step. To install it type

# make
# make install

Step # 3 Configure groups

For demonstration purpose we will use following setup:

   admin pc                    Group           hosts
Running Debian Linux       homeservers     192.168.1.12 192.168.1.15
User: jadmin

Copy sample tentakel configuration file tentakel.conf.example to /etc directory

# cp tentakel.conf.example /etc/ tentakel.conf

Modify /etc/tentakel.conf according to above setup, at the end your file should look like as follows:

# first section: global parameters
set ssh_path="/usr/bin/ssh"
set method="ssh"  # ssh method
set user="jadmin"   # ssh username for remote servers
#set format="%d %o\n" # output format see man page
#set maxparallel="3"  # run at most 3 commands in parallel

# our home servers with two hosts
group homeservers ()
+192.168.1.12 +192.168.1.15

# localhost
group local ()
+127.0.0.1

Save the file and exit to shell prompt. Where,
group homeservers () : Group name
+192.168.1.12 +192.168.1.15 : Host inclusion. name is included and can be an ip address or a hostname.

Step # 4 Configure SSH password less login

Configure ssh-key based login to avoid password prompt between admin workstation and group servers for jadmin user.

Step # 5 Test tentakel

Login as jadmin and type the following command:

$ tentakel -g homeservers

interactive mode
tentakel(homeservers)>

Where,
-g groupname: Select the group groupname The group must be defined in the configuration file (here it is homeservers). If not specified tentakel implicitly assumes the default group.

At tentakel(homeservers)> prompt type command uname and uptime command as follows:

exec "uname -mrs"
exec "uptime"

Few more examples
Find who is logged on all homeservers and what they are doing (type at shell prompt)

$ tentakel -g homeservers "w"

Executes the uptime command on all hosts defined in group homeservers:

$ tentakel -g homeservers uptime

As you can see, tentakel is very powerful and easy to use tool. It also supports the concept of plugins. A plugin is a single Python module and must appear in the $HOME/.tentakel/plugins/ directory. Main advantage of plugin is customization according to your need. For example, entire web server or mysql server farm can be controlled according our requirements.
However, tentakel is not the only utility for this kind of work. There are programs that do similar things or have to do with tentakel in some way. The complete list can be found online here. tentakel should work on almost all variant of UNIX/BSD or Linux distributions.

Time is a precious commodity, especially if you’re a system administrator. No other job pulls people in so many directions at once. Users interrupt you constantly with requests, preventing you from getting anything done and putting lots of pressure on you. What do you do? The answer is time management. Read our book review of Time Management for System Administrators. Continue reading Execute commands on multiple hosts using expect tool Part III of this series.

Reference:

  • Read tentakel man page for tentakel configuration options
  • tentakel home page

Update: Damon confirmed that it works on Windows too with little modification.

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source & DevOps topics via:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
20 comments… add one
  • Stoyan Dec 27, 2005 @ 14:10

    Or if you like ruby, use SwitchTower. Have native ruby ssh client = will work on windows too.

  • 🐧 nixcraft Dec 27, 2005 @ 16:55

    Stoyan, SwitchTower seems good choice for windows 🙂 as I may soon start work on windows too, I appreciate you post.

  • Anonymous Dec 27, 2005 @ 22:18

    I think python should also work on windows. Btw nice article 🙂

  • Anonymous Dec 28, 2005 @ 10:28

    Fermilab has a much more feature rich tool named rgang.

    More info: rgang abstract and download

  • 🐧 nixcraft Dec 28, 2005 @ 11:26

    RGANG looks good too. It incorporates an algorithm to build a tree-like structure (or “worm” structure) to allow the distribution processing time to scale very well to 1000 or more nodes. Looks rock solid.

    Thanks for pointing out I appreciate you post 🙂

  • Damon Dec 28, 2005 @ 12:31

    I can confirm that it is possible to run Tentakel on Windows, albeit with a bit of modification to the source (about 7 lines total).

    I posted the details over my blog: Running Tentakel on Windows

  • 🐧 nixcraft Dec 28, 2005 @ 13:03

    Nice 😀 I have updated post.

  • Anonymous Dec 28, 2005 @ 21:25

    It seems a nice tool and using ssh it will be secure (as long as no-one knows the privat key ofcourse).

    For a more simple variant I use a sh-script to execute on all machines in my (linux-)network:

    ping -c 2 -w 10 -b 192.168.13.255 2>/dev/null | sed -n -e ‘s#^.*bytes from ([^:][^:]*).*#1#p’ | while read ip
    do
    name=`host ${ip} | sed -e ‘s#.* ([^ ][^ ]*).$#1#’`
    echo “— ${name} : ${*}”
    rsh ${name} ${EXTRA} “${*}”
    done

  • Anonymous Dec 28, 2005 @ 22:42

    If your somewhat traditional, just use Expect. Does most of the same, has tons of examples around, a cool book (Exploring Expect).
    And you can handle stuff that NEEDS a terminal like ssh password prompts or the password program to change passwords.And it works on windows.

  • 🐧 nixcraft Dec 28, 2005 @ 23:17

    Expect. Is very nice back in Solaris day I had complete monitoring system written in rsh and expect tool. Open advantage of ssh is that it provides API for C/C++ programs. So I get performance

    Anonymous user thanks for sharing your script with us. ,appreciate your post.

  • Sebastian Dec 29, 2005 @ 0:52

    Thanks for mentioning tentakel in your blog. You also mentioned rgang, which looks nice indeed. However, there are two reasons why I don’t like rgang: 1) the license is not as free as tentakels (at least it does not look like as far as I can tell without being a lawyer) 2) it looks much more unmaintained thatn tentakel 🙂

    -Sebastian

  • alutii Dec 29, 2005 @ 1:25

    Another possibility is fanout. I quite like fanterm where the output is collected in xterm like windows. Helps keep things organized for me.

    Groups in tentakel looks handy. Thanks for the article nixcraft.

  • Anonymous Dec 31, 2005 @ 15:40

    if the number of machines are

  • Anonymous Dec 31, 2005 @ 20:20

    I use Shocto –
    written in Ruby.
    Link here

  • mariuz Jan 17, 2008 @ 16:08

    if you have python2.5 like on my ubuntu system
    you must install from svn

    http://sourceforge.net/tracker/index.php?func=detail&aid=1581326&group_id=76769&atid=548189
    “I checked in a fix. You can try it out by checking out the development
    version of tentakel using the following command:”

    svn co http://svn.tuebingen.mpg.de/tentakel/trunk/
    cd trunk/tentakel
    make ; make install

  • Moise Ndala Jul 20, 2009 @ 14:26

    I would like just to mention that for new version of python 2.5 and latest versions, tentakel works fine with the patch specified at:
    http://bugs.gentoo.org/attachment.cgi?id=177786&action=view

    Thanks for your help!

    Regards

  • Eduardo Feb 29, 2012 @ 12:56

    Hi, I managed to install tentakel but can’t make it work since our servers don’t run on the 22 default port. Is there any way to change the port tentakel connects to??

  • Harry Mangalam Sep 19, 2012 @ 23:05

    or clusterfork
    which is very simple (a single perl script) & does execute in parallel, and does a bunch of other stuff like the rest of the ones mentioned above, and is also scriptable if you want use its abilities in other scripts. I do admire tentakel’s code compactness tho.

  • jaffer Mar 27, 2013 @ 9:53

    How do i execute 2 groups with each group associated to different command parallely.

    tentakel -c -g group1 -c -g group2

  • Rémy Jun 26, 2013 @ 9:46

    For python, take a look at “Fabric”.

    There si also parallel-ssh

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.