#! /bin/sh
# determine the cores currently available
# last modified 5 Feb 09 th

# usage:  setupcores [-h ruptimehost]


while [ $# -gt 0 ] ; do
  case $1 in
  -h) ruptimehost=$2 ;;
  *)  ;;
  esac
  shift 2
done

readhost()
{
  while read host updown ignore ; do
    [ "$updown" = up ] && hosts="$hosts $host"
  done

  for host in $hosts ; do
    set -- `ssh -o "PasswordAuthentication no" -o "StrictHostKeyChecking yes" $host grep MHz /proc/cpuinfo 2>/dev/null | cut -d: -f2`
    [ $# -gt 0 ] && hl="$hl
$1 $host $#"
  done

  echo "$hl" | sort -n -r | cut -f2- -d' '
}


( [ -n "$ruptimehost" ] && ssh $ruptimehost ruptime || ruptime ) | readhost

