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.

link|improve this question

43% accept rate
feedback

4 Answers

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

link|improve this answer
feedback
up vote 1 down vote accepted

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

#! /usr/bin/env bash


out=avail.txt
rm -rf ~/$out
minLoad=1
for h in $(cat ~/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" >> ~/$out
        ##echo "$load" >> ~/$out
    fi
done

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

link|improve this answer
feedback

Install the Sun Grid Engine. Or Hudson.

link|improve this answer
feedback

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 http://superuser.com/questions/8077/how-do-i-set-up-ssh-so-i-dont-have-to-type-my-password

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.