Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!crdgw1!uunet!convex!usenet From: tchrist@convex.COM (Tom Christiansen) Newsgroups: comp.unix.questions Subject: Re: Return status of 'rsh' Message-ID: <1991Apr10.000843.5391@convex.com> Date: 10 Apr 91 00:08:43 GMT References: Sender: usenet@convex.com (news access account) Reply-To: tchrist@convex.COM (Tom Christiansen) Distribution: comp Organization: CONVEX Software Development, Richardson, TX Lines: 94 Nntp-Posting-Host: pixel.convex.com From the keyboard of pbrown@vtopus.cs.vt.edu (Patrick R. Brown): :I am trying to set up a shell script to check for mail on a remote :machine. The script is the following: : : #! /bin/sh : # : # Check mail on CSGrad since I can't get mail here!!!! : # : if [ `rsh csgrad mail -e` ] : then : echo You have mail on CSGrad. : else : echo You do not have mail on CSGrad. : fi : :This looks nice, but it doesn't work. (I never "have" mail, even when :I do) What can I do (if anything) to get 'rsh' to return the status of :the command being run remotely. The Ultrix man pages don't have :anything to say on this topic. If 'rsh' won't do this, are there any :other ideas? You can use Maarten Litmath's ersh script where you have rsh. Your script will behave as you expect it to. --tom #!/bin/sh # @(#)ersh 2.4 91/01/30 Maarten Litmaath # This rsh front-end returns the exit status of the remote command. # It works OK with sh/csh-compatible shells on the remote (!) side. # If there is no remote command present, /usr/ucb/rlogin is invoked. # Usage: see rsh(1). unset hostname lflag nflag user case $1 in -l) ;; *) hostname=$1 shift esac case $1 in -l) lflag=-l user=$2 shift 2 esac case $1 in -n) nflag=-n shift esac case $hostname in '') hostname=$1 shift esac case $# in 0) exec /usr/ucb/rlogin $lflag ${user+"$user"} "$hostname" esac AWK=' NR > 1 { print prev; prev = $0; prev1 = $1; prev2 = $2; } NR == 1 { prev = $0; prev1 = $1; prev2 = $2; } END { if (prev1 ~ /[0-9]*[0-9]0/) exit(prev1 / 10); if (prev1 == "0") exit(prev2); print prev; exit(1); } ' exec 3>&1 /usr/ucb/rsh "$hostname" $lflag ${user+"$user"} $nflag \ "(${*-:}); sh -c '"'echo "$0 $1" >&2'\'' $?0 "$status"' \ 2>&1 >&3 3>&- | awk "$AWK" >&2 3>&-