automate: finding non-used servers from a list of servers

2

0

i posted this on stack overflow but a user recommended i post here. sorry for cross posting:

0 vote down star

i have access to a few linux clusters at school. sometimes they are busy and sometimes they are not. i usually log into each machine manually, use the "top" command to see if the server is busy (to see if both cores are used). from there, i execute my program to use some servers that are free to run my computations.

what i'd like to do is to automate this process with a script. suppose i have a list of servers, say server1 ... server N. I'd like to log into each of these servers sequentially, run some command (top?), and output a list of servers that are unused (or output the top two processes, showing cpu %, for each server).

any suggestions would be greatly appreciated.

Vinh Nguyen

Posted 2009-12-15T23:35:45.290

Reputation: 265

Answers

1

Thanks for the suggestions. Here is my script for anyone that is interested:

#! /usr/bin/env bash

out=avail.txt
rm -f "$HOME/$out"
minLoad=1
for h in $(cat "$HOME/listofservers.txt"); do
    ##w | head -1 | cut -d : -f 5 - | cut -d "," -f 2 -
    load=`ssh username@$h uptime | cut -d : -f 5 - | cut -d "," -f 2 -`
    comparison=`expr $load \< $minLoad`
    if [ comparison ]; then
        echo "$h" >> "$HOME/$out"
        ##echo "$load" >> "$HOME/$out"
    fi
done

PS We do have SGE installed. However, what I'm doing doesn't play well with SGE yet. Thanks.

Vinh Nguyen

Posted 2009-12-15T23:35:45.290

Reputation: 265

1

Well, I'd look at using w rather than top (returns system load and who is logged in), but look around.

Ronald Pottol

Posted 2009-12-15T23:35:45.290

Reputation: 641

0

Install the Sun Grid Engine. Or Hudson.

bmargulies

Posted 2009-12-15T23:35:45.290

Reputation: 1 121

0

Using ssh keys, you can do something like this:

for i in server1 server2 server N
 do
       ssh user@$i "uptime" 
 done

Uptime command will show the load of the box too. You can use "top -b 1", "w"...

If you need help configuring ssh keys so ssh doesn't ask for password, read here How do I set up SSH so I don't have to type my password?

sntg

Posted 2009-12-15T23:35:45.290

Reputation: 121