3 # Program: RemoteRunSafely.sh
5 # Synopsis: This script simply runs another program remotely using ssh.
6 # It always returns the another program exit code or exit with
7 # code 255 which indicates that the program could not be executed.
11 # RemoteRunSafely.sh <hostname> [-l <login_name>] [-p <port>]
15 # <hostname> is the remote host to execute the program,
16 # <login_name> is the username on the remote host,
17 # <port> is the port used by the remote client,
18 # <program> is the path to the program to run,
19 # <args...> are the arguments to pass to the program.
25 echo "./RemoteRunSafely.sh <hostname> [-l <login_name>] [-p <port>] " \
32 # $1 - remaining number of arguments
33 # $2 - number of arguments to shift
36 echo "Error: Wrong number of arguments."
41 # Save a copy of the original arguments in a string before we
42 # clobber them with the shift command.
44 #DEBUG: echo 'GOT: '$ORIG_ARGS
56 if [ $1 = "-l" ]; then
62 if [ $1 = "-p" ]; then
69 PROGRAM
=$
(basename $1)
70 WORKING_DIR
=$
(dirname $1)
73 #DEBUG: echo 'DIR='${0%%`basename $0`}
74 #DEBUG: echo 'RHOST='$RHOST
75 #DEBUG: echo 'RUSER='$RUSER
76 #DEBUG: echo 'PROGRAM='$PROGRAM
77 #DEBUG: echo 'WORKING_DIR='$WORKING_DIR
78 #DEBUG: echo 'ARGS='$*
81 if [ "$RHOST" = "" -o "$PROGRAM" = "" ]; then
85 # Local program file must exist and be execuatble
86 local_program
=$WORKING_DIR"/"$PROGRAM
87 if [ ! -x "$local_program" ]; then
88 echo "File "$local_program" does not exist or is not an executable.."
92 connection
=$RUSER'@'$RHOST
95 cat $local_program | \
96 $RCLIENT $connection $RPORT \
97 'rm -f '$remote' ; ' \
98 'cat > '$remote' ; chmod +x '$remote' ; '$remote' '$
*' ; ' \
99 'err=$? ; rm -f '$remote' ; exit $err'
103 #DEBUG: echo script exit $err