0

I've server Master,SlaveA,SlaveB,SlaveC, and want to get eg. the space information from the server by executing one bash script on the master.

How can I do that?

--case--
192.168.1.1 - Master
192.168.1.10 - A
192.168.1.11 - B
192.168.1.12 - C

Get df on slaves.

--ex. output---
==Slave A==
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda1             7222500   3909896   2945720  58% /
==Slave B==
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda1             4222500   3909896   5744447  98% /
==Slave C==
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda1             1222500   509896   xxxxxxxx  50% /

Many Thanks! DeLol

Sven
  • 98,649
  • 14
  • 180
  • 226
DeLol
  • 1
  • 1
    You should consider using tools like Nagios and Munin for this sort of thing rather than running scripts manually. – ThatGraemeGuy Apr 10 '13 at 13:39
  • @ThatGraemeGuy: Nagios etc. is fine, but it doesn't tell you more than that everything is OK. Sometimes I just want to have a list of data from several servers, or do something on all of them. And no, Puppet etc. isn't always the answer. – Sven Apr 10 '13 at 13:42
  • I'm not sure what Puppet has to do with this, since that's used for configuration management. Nobody even mentioned it. – ThatGraemeGuy Apr 10 '13 at 13:48
  • @ThatGraemeGuy: It was just a proactive statement from my side, not necessarily aimed to you directly, but tools like puppet are usually the next thing mentioned in discussions like that. "You want to do things on many machines. Use puppet/chef/cfengine". – Sven Apr 10 '13 at 14:06
  • [dsh](http://www.netfort.gr.jp/~dancer/software/dsh.html.en) can handle this for any arbitrary command. – Mike Renfro Apr 11 '13 at 02:45

2 Answers2

1

Put the commands you need in a quick script on the master and run the script like this:

ssh 192.168.1.10 < script.sh

This executes the commands contained within script.sh on the remote host without copying script to the remote system.

Also see: Documenting server details

ewwhite
  • 197,159
  • 92
  • 443
  • 809
0

For a limited list of clients I have a bash function in my ~/.profile:

ch () {

   echo host1
   ssh root@host1 $@
   echo host2
   ssh root@host2 $@
}

I call this like this:

ch df

This can be easily expanded to a list of clients read from an array or a config file.

Another option is to use something like cssh or similar.

Sven
  • 98,649
  • 14
  • 180
  • 226