-2

I have 100 servers running on AWS. I need to easily get how much data each user on the remote systems are using and output it to a text file. How could I best accomplish this?

ram
  • 9
  • 2
    collect how much is the data used by each user what do you mean by that ? – Rahul Jun 23 '16 at 19:49
  • Do they all share a common username/password or do you possibly have access to a file with all the credentials? If so in what format. Also are you just looking for disk usage under the home/ directory or are you looking for a breakdown of per user per server? – Zachary Brady Jun 23 '16 at 19:52
  • Have a look at http://unix.stackexchange.com/questions/269617/linux-equivalent-to-powershells-one-to-many-remoting/269626#269626 – Rui F Ribeiro Jun 23 '16 at 20:46
  • thanks for your reply Zachary Brady, user name of every user is "ec2-user", and i was lunched all instances by using single key pair "example.pem", hear my script should login to each and every instance and it has to check disk usage by each user and place in text file – ram Jun 24 '16 at 18:04

1 Answers1

3

You can use a parallel shell such as clustershell or pdsh.

This way, assuming you already set up a passwordless SSH authentication from a central machine, you can run a command on each of the 100 servers at the same time. You can also go further and do various groups in order to organize them logically.

Lets assume your machines are named aws0, aws1, aws2, ... aws99.

With clustershell, you can run a command (uptime in this example) on all of them them this way:

# clush -w aws[0-100] uptime
aws0: 21:49:12 up  5:46,  1 user,  load average: 0.07, 0.02, 0.00
aws1: 21:49:12 up  5:46,  1 user,  load average: 0.07, 0.02, 0.00
aws2: 21:49:12 up  5:46,  1 user,  load average: 0.07, 0.02, 0.00
[...]
aws99: 21:49:12 up  5:46,  1 user,  load average: 0.07, 0.02, 0.00

You can run the command on a subset of them this way

clush -w aws[22-55,73-82,90,99] uptime
aws22: 21:49:12 up  5:46,  1 user,  load average: 0.07, 0.02, 0.00
aws23: 21:49:12 up  5:46,  1 user,  load average: 0.07, 0.02, 0.00
[...]
aws55: 21:49:12 up  5:46,  1 user,  load average: 0.07, 0.02, 0.00
aws73: 21:49:12 up  5:46,  1 user,  load average: 0.07, 0.02, 0.00
[...]
aws82: 21:49:12 up  5:46,  1 user,  load average: 0.07, 0.02, 0.00
aws90: 21:49:12 up  5:46,  1 user,  load average: 0.07, 0.02, 0.00
aws99: 21:49:12 up  5:46,  1 user,  load average: 0.07, 0.02, 0.00

Then, if you want to group the results that are identical, you can use the -b option of clush or pipe to dshbak -c with pdsh

# clush -bw aws[0-99] uptime
---------------
aws[0-99] (100)
---------------
21:49:12 up  5:46,  1 user,  load average: 0.07, 0.02, 0.00
Dieter G
  • 114