#!/bin/sh # # rsh_status # # AUTHOR: # Dan Harkless # # COPYRIGHT: # This file is Copyright (C) 1998 by Dan Harkless, and is released under the # GNU General Public License . # # USAGE: # % rsh_status [-l ] [-n] # # DESCRIPTION: # rsh/remsh is not as useful as one would like in a script, since the status # returned is not the status from the remote command, but from the rsh itself, # so unless the machine name or login info was bad, the status is always 0. # rsh_status behaves like rsh but returns the exit status from the command on # the other end, allowing for the writing of much more fault-tolerant scripts. # # To make this magic happen, rsh_status needs to have an NFS-mounted directory # that's available on both systems, and is world-writable (unless you don't # use -l, in which case it just needs to be writable by you). If # $RSH_STATUS_DIR is set, that directory will be used. If not, $HOME/public # is assumed. # # DATE MODIFICATION # ========== ================================================================== # 1998-02-25 On AT&T UNIX, rsh is BSD's Rsh, so use remsh, which works on both. # 1996-12-06 Original. if [ $# -lt 2 ]; then echo "usage: rsh_status [-l ] [-n] " exit 1 fi rsh_host=$1 shift using_dash_l=0 while [ "`echo $1 | awk '{print substr($1, 1, 1)}'`" = "-" ]; do rsh_options="$rsh_options $1" if [ X$1 = X-l ]; then using_dash_l=1 shift rsh_options="$rsh_options $1" fi shift done rsh_status_dir=${RSH_STATUS_DIR-$HOME/public} rsh_status_file=.rsh_status.$HOST.$$ if [ ! -d $rsh_status_dir ]; then echo "rsh_status: $rsh_status_dir directory does not exist." echo 'rsh_status: Create it or set $RSH_STATUS_DIR to another directory'\ 'and re-run.' exit 1 fi if [ $using_dash_l = 1 ]; then if [ `ls -dl $rsh_status_dir | fgrep -c rwxrwxrwx` != 1 ]; then echo "rsh_status: $rsh_status_dir must be world-writable. Aborting." exit 1 fi else # using -l if [ ! -w $rsh_status_dir ]; then echo "rsh_status: $rsh_status_dir must be writable. Aborting." exit 1 fi fi trap "rm -f $rsh_status_dir/$rsh_status_file" 0 1 2 3 15 remsh $rsh_host $rsh_options "$*; echo "'$?'" >$rsh_status_dir/$rsh_status_file" rsh_status=`cat $rsh_status_dir/$rsh_status_file` exit $rsh_status