Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

rm -f "$HOME/$out"
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"

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
       ssh user@$i "uptime" 

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

share|improve this answer

Your Answer


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.