From e264f62ca09a8f65c87a46d562a4d0f9ec5d457e Mon Sep 17 00:00:00 2001 From: Shih-wei Liao Date: Wed, 10 Feb 2010 11:10:31 -0800 Subject: Check in LLVM r95781. --- utils/bugpoint/RemoteRunSafely.sh | 105 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 utils/bugpoint/RemoteRunSafely.sh (limited to 'utils/bugpoint') diff --git a/utils/bugpoint/RemoteRunSafely.sh b/utils/bugpoint/RemoteRunSafely.sh new file mode 100644 index 0000000..f390e33 --- /dev/null +++ b/utils/bugpoint/RemoteRunSafely.sh @@ -0,0 +1,105 @@ +#!/bin/sh +# +# Program: RemoteRunSafely.sh +# +# Synopsis: This script simply runs another program remotely using ssh. +# It always returns the another program exit code or exit with +# code 255 which indicates that the program could not be executed. +# +# Syntax: +# +# RemoteRunSafely.sh [-l ] [-p ] +# +# +# where: +# is the remote host to execute the program, +# is the username on the remote host, +# is the port used by the remote client, +# is the path to the program to run, +# are the arguments to pass to the program. +# + +printUsageAndExit() +{ + echo "Usage:" + echo "./RemoteRunSafely.sh [-l ] [-p ] " \ + " " + exit 255 +} + +moreArgsExpected() +{ + # $1 - remaining number of arguments + # $2 - number of arguments to shift + if [ $1 -lt $2 ] + then + echo "Error: Wrong number of argumants." + printUsageAndExit + fi +} + +# Save a copy of the original arguments in a string before we +# clobber them with the shift command. +ORIG_ARGS="$*" +#DEBUG: echo 'GOT: '$ORIG_ARGS + +moreArgsExpected $# 1 +RHOST=$1 +shift 1 + +RUSER=`id -un` +RCLIENT=ssh +RPORT= +WORKING_DIR= + +moreArgsExpected $# 1 +if [ $1 = "-l" ]; then + moreArgsExpected $# 2 + RUSER=$2 + shift 2 +fi +moreArgsExpected $# 1 +if [ $1 = "-p" ]; then + moreArgsExpected $# 2 + RPORT="-p $2" + shift 2 +fi + +moreArgsExpected $# 1 +PROGRAM=$(basename $1) +WORKING_DIR=$(dirname $1) +shift 1 + +#DEBUG: echo 'DIR='${0%%`basename $0`} +#DEBUG: echo 'RHOST='$RHOST +#DEBUG: echo 'RUSER='$RUSER +#DEBUG: echo 'PROGRAM='$PROGRAM +#DEBUG: echo 'WORKING_DIR='$WORKING_DIR +#DEBUG: echo 'ARGS='$* + +# Sanity check +if [ "$RHOST" = "" -o "$PROGRAM" = "" ]; then + printUsageAndExit +fi + +# Local program file must exist and be execuatble +local_program=$WORKING_DIR"/"$PROGRAM +if [ ! -x "$local_program" ]; then + echo "File "$local_program" does not exist or is not an executable.." + exit 255 +fi + +connection=$RUSER'@'$RHOST +remote="./"$PROGRAM +( + cat $local_program | \ + $RCLIENT $connection $RPORT \ + 'rm -f '$remote' ; ' \ + 'cat > '$remote' ; chmod +x '$remote' ; '$remote' '$*' ; ' \ + 'err=$? ; rm -f '$remote' ; exit $err' +) +err=$? + +#DEBUG: echo script exit $err +exit $err + -- cgit v1.1