ersh on hpux11 -- any script debuggers?
Will Partain <[email protected]> Wed, 13 Jun 2001 21:40:57 +0100
| Newsgroups | gmane.comp.sysutils.ark.devel |
|---|---|
| Message-ID | <[email protected]> |
Anyone out there got access to hpux11 boxen? The supposedly latest-and-greatest 'ersh' script (rsh, but get back the exit status of the command run on the far end) doesn't work correctly when the far host is an hpux11 box. Maarten Litmaath, the author, suggests as a test case: ersh $hpux_host 'set -x; date > /dev/null; exit 43' echo status=$? It's supposed to work whether the shell on the far end is sh-style or csh-style. When I run it, I always get back exit status 99. I am obviously missing something, but maybe there's someone out there who is particularly fiendish with shell scripts... Will === the one I've been playing with =================== #!/bin/sh # ARK version: $Revision: 1.4 $ # Based on the original from Maarten Litmaath: # @(#)?Id: ersh 4.0 2001/04/09 [email protected] (Maarten Litmaath) ? # This rsh front-end normally returns the exit status of the remote command; # it returns the exit status of rsh itself when it failed (e.g. when the host # is unknown or down, or when it got killed by a signal); it returns 99 when # the remote command wrapper got killed. # It works OK with sh/csh-compatible shells on the remote (!) side. # If there is no remote command present, rlogin is invoked, which # need not return a meaningful exit status. # Usage and bugs: see rsh(1). dirs=' /usr/bin /bin /usr/ucb /usr/bsd ' RSH= for i in $dirs do if test -x $i/remsh then RSH=$i/remsh break fi if test -x $i/rsh then RSH=$i/rsh break fi done # ToDo: should test that RSH's set test $RSH || RSH=remsh # System V usage() { echo "Usage: $0 [ -l username ] [ -n ] hostname [ command ]" >&2 echo " or: $0 hostname [ -l username ] [ -n ] [ command ]" >&2 exit 1 } host= lflag= nflag= user= while test $# != 0 do case $1 in -l) lflag=$1 shift test $# = 0 && usage user=$1 ;; -n) nflag=$1 ;; -*) echo "$0: illegal option: $1" >&2 usage ;; ?*) test "X$host" = X || break host=$1 ;; *) usage esac shift done test "X$host" = X && usage case $# in 0) for i in $dirs do test -x $i/rlogin && exec $i/rlogin $lflag $user "$host" done echo "$0: cannot find rlogin" >&2 exit 1 esac marker=ersh.$$.`date +%y%m%d_%T` hangup=99 set -x AWK=' /'$marker' [0-9]+$/ { len = length("'$marker'") for (i = 1; substr($0, i, len) != "'$marker'"; i++) { } if (i != 1) { printf "%s", substr($0, 1, i - 1) } i += len status = substr($0, i + 1, length - i) next } { print } END { if (status ~ /^[0-9]+0$/) { exit(status / 10) } exit('$hangup') } ' # partain: begin # Here's a simple example of the shell redirection games being # used herein; this example is from the Rice University "Document # UNIX 18", Advanced Unix -- Scripts. # # Here's an example of using the exec command to change the default # association of file descriptors to accomplish a task, and then to # put it back when that task is completed: # # prompt$ exec 3>&1; grep string file 2>&1 1>&3 | sed s/exp/new/ 1>&2 # # File descriptor three (which starts unused - there are ten file # descriptors total can be used [0-9]) is first associated with file # descriptor one, which initially points at our tty. Next, the # STDERR of the grep command goes to file descriptor one, which is # what pipes read from, while the output of file descriptor one is # associated with that of three, which we just pointed at our tty. # Thus STDERR from the grep is piped to sed, which puts the STDOUT # back on the STDERR, which points to the terminal. File descriptor # three is being used as a place marker in this example for the # default assignment of file descriptor one, so that after one has # been moved around it's still possible to point it back at the # right place. # # partain: end exec 3>&1 # If the remote shell is a Bourne shell variant, we avoid echoing "$status" # because it might contain a newline. shcmd='test $0 = 0 || set $0; echo '"$marker"' $1 >&2' cmd="( ${*-:} ); exec sh -c '$shcmd'"' $?0 "$status"0' ( $RSH "$host" $lflag $user $nflag "$cmd" 2>&1 >&3 3>&- || echo "$marker $?0" ) | awk "$AWK" >&2 3>&-