3 # Program: RemoteRunSafely.sh
5 # Synopsis: This script simply runs another program remotely using rsh.
6 # It always returns the another program exit code.
8 # (?) only exit statuses that indicates that the program could not be executed
9 # normally is considered to indicate a test failure.
13 # RemoteRunSafely.sh <hostname> [-l <login_name>] [-p <port>]
17 # <hostname> is the remote host to execute the program,
18 # <login_name> is the username on the remote host,
19 # <port> is the port used by the remote client,
20 # <program> is the path to the program to run,
21 # <args...> are the arguments to pass to the program.
27 echo "./RemoteRunSafely.sh <hostname> [-l <login_name>] [-p <port>] " \
28 "[cd <working_dir>] <program> <args...>"
34 # $1 - remaining number of arguments
35 # $2 - number of arguments to shift
38 echo "Error: Wrong number of argumants."
43 # Save a copy of the original arguments in a string before we
44 # clobber them with the shift command.
46 #DEBUG: echo 'GOT: '$ORIG_ARGS
58 if [ $1 = "-l" ]; then
64 if [ $1 = "-p" ]; then
71 PROGRAM=$(basename $1)
72 WORKING_DIR=$(dirname $1)
75 #DEBUG: echo 'DIR='${0%%`basename $0`}
76 #DEBUG: echo 'RHOST='$RHOST
77 #DEBUG: echo 'RUSER='$RUSER
78 #DEBUG: echo 'PROGRAM='$PROGRAM
79 #DEBUG: echo 'WORKING_DIR='$WORKING_DIR
80 #DEBUG: echo 'ARGS='$*
83 if [ "$RHOST" = "" -o "$PROGRAM" = "" ]; then
87 # Local program file must exist and be execuatble
88 local_program=$WORKING_DIR"/"$PROGRAM
89 if [ ! -x "$local_program" ]; then
90 echo "File "$local_program" does not exist or is not an executable.."
94 connection=$RUSER'@'$RHOST
97 cat $local_program | \
98 $RCLIENT $connection $RPORT \
99 'rm -f '$remote' ; ' \
100 'cat > '$remote' ; chmod +x '$remote' ; '$remote' '$*' ; ' \
106 #DEBUG: echo script exit $err