#!/bin/bash
#
# rrun 	:  	run a command niced to "10" in the background of any 
#		machine.  Standard output and error are redirected to
#		/dev/null since we use rcmd. 
# requirements: you must not have a .rhosts file.  If you have one, I'd
#		suggest moving it to a backup file, then writing script
#		commands to rename it ".rhosts" whenever it's needed.
# changes required: changing "berryj" to your username
#
# examples:	rrun fox sleep 60
#		rrun troi bk -a -P -f `pwd`/infile -t `pwd`/outfile
#		(bk is my program, not a unix utility)
#		rrun quark gcc `pwd`/float.c `pwd`/double.c -o `pwd`/fd
# warnings:	This uses "rcmd," which doesn't notify you if anything has
#		gone wrong.  Better check to make sure the job actually
#		got going (e.g. use "ps.sh machine")
#

if [ $# -lt 2 ]
then
	echo "usage: rrun <machine prefix> <command (not niced)> <arg1> .."
	exit 1
fi

remote_machine=$1
machine=$HOST
shift
if [ $1 = "nice" ]
then
	echo "rrun: error: command should not be nice'd (I will nice it)"
	exit 2
fi

if [ -f $HOME/.rhosts ]
then
	echo "error: .rhosts exists"
	exit 3
fi
trap 'rm $HOME/.rhosts; exit 1' 1 2 15
echo "$machine.rutgers.edu berryj" | cat > $HOME/.rhosts
rcmd $remote_machine.rutgers.edu nice -10 $* 
rm $HOME/.rhosts
