Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question

4 Answers 4

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

share|improve this answer
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 -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.

share|improve this answer

Install the Sun Grid Engine. Or Hudson.

share|improve this answer

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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