#!/bin/sh

# the following scriptlet causes poweroff to run on hosts
# 192.168.0.1 - 192.168.0.10
#
# this script assumes that ssh is used with public keys (so that it
# doesn't ask for passwords). also assumes that root login is permitted
# which it is not normally.

# start by blowing away known_hosts in case keys are mismatched
# note that this is relatively dangerous operation to do on a system
# that is used to ssh from !! (DANGER: read the notice before)
rm -f ~/.ssh/known_hosts

for a in `seq 10`; do
  # copy the executable on remote host
  # also tell ssh to ignore the fact that we might not have connected
  # to the system before and insert the host key blindly
  # again, very very insecure, but..
  scp -o StrictHostKeyChecking=no poweroff root@192.168.0.$a:.
  # execute poweroff over ssh and detach ssh so that it doesn't
  # wait for the program to terminate. since power will be cut off
  # without proper process termination, the SSH connection will
  # wait for 15 minutes otherwise.
  ssh -f root@192.168.0.$a ./poweroff
done

