The response was great, I had my problem solved several hours before
I received my question !!.
FIRSTLY THANKS TO ALL THE FOLLOWING FOR REPLYING
================================================
David Wiseman <magi@csd.uwo.ca>
Alan Stebbens <aks@hub.ucsb.edu>
Mitch Wright <mitch@hq.af.mil>
Russell Brand <brand%wuthel@lll-winken.llnl.gov>
dmorse@sun-valley.Stanford.edu (Dennis Morse)
era@niwot.scd.ucar.edu (Ed Arnold)
daryl@dash.mitre.org (Daryl Crandall)
Joe Garbarino <jgarb@csd4330a.erim.org>
libes@cme.nist.gov (Don Libes)
Tom Conroy <trc@ESD.3Com.com>
probert <(Dave Probert) probert%cs@hub.ucsb.edu>
Jeff Nieusma <nieusma@cs.Colorado.edu>
Petri Ojala <ojala@cs.hut.fi>
birger@sdata.no (Birger Wathne)
mike@inti.lbl.gov (Michael Helm)
djm%green%millidc@uunet.UU.net (Drew Montag)
Claude.P.Cantin@NRC.CA
capaldi%librainc@uunet.UU.net (Carey Capaldi)
drl@vuse.vanderbilt.edu
Richard Evans <rde@topexp.co.uk>
"Dwight A. Ernest" <dwight@independent.uucp>
Who sent me the trendy script at near
the end of this document.
MY ORIGNAL QUESTION
===================
Is it possable to get the return value from an rsh command,
let me explain
I do
rsh mbsunf fsck /dev/smo0a
^^^^^^^^^^^^^^^
How do I find out if fsck completed sucessfully ??
If I have a script
#! /bin/sh
rsh mbsunf fsck /dev/smo0a
echo $?
All I get is wether the rsh worked not the fsck
Any ideas ??
I have tried writeing the output value to a file and re-reading it.
I don't realy want to execute a script on mbsunf as this will mean
leaving a set uid to root script hanging around. (or access to a
function I don't want to tell users how to do in any case).
Thanks for your help
THE ANSWERS
===========
Several people asked for summerirs having tried the same
themsellves. One person rang SUN who said it was impossable.
Well lots of peole know know thats not true.
Except for one very interesting answer The basic way to do it
is to return the valuse by echoing it after the command has
completed. I had tried this but what got me was that rsh
executes the remote shell using the default login shell.
I have not tested all the answers, I took ideas from them all
to come up with what I wanted, I have included some code
in C at the end just in case you want to use the system(3)
library call via rsh to return thr error code of the
eventual command (WHAT I WANTED TO DO)
NB. Have fun if your script is in /bin/sh and you login
with /bin/csh
NB2. watch the various quoteing of special charcters
DEFAULT LOGIN SHELL = /bin/sh
=============================
----------------------------------------------------------------------
If push comes to shove, you could try something like this:
rsh mbsunf fsck /dev/smo0a ';' echo $?
At least then you'll get the return code back. You'll have to free it
from the fsck output somehow but...
----------------------------------------------------------------------
rsh mbsunf 'fsck /dev/smo0a >& fsck.log ; echo $?'
and then read the output, the last line of which should be the status
code. If the status is bad, you can then retrieve the "fsck.log"
output. A Perl script could easily do this through a pipe.
----------------------------------------------------------------------
rsh mbsunf 'fsck /dev/smo0a; echo $?'
----------------------------------------------------------------------
#! /bin/sh
(rsh mbsunf "fsck /dev/smo0a && echo MUMBLE" ) | grep -s MUMBLE
echo $?
----------------------------------------------------------------------
stat=`rsh mbsunf fsck /dev/smo0a; echo $?`
The variable "stat" should contain the exit status
----------------------------------------------------------------------
rstat=`rsh mbsunf 'fsck /dev/smo0a; echo $?'`
----------------------------------------------------------------------
status=`rsh mbsunf "fsck /dev/smo0a > /dev/null 2>&1; echo $?"`
Then check the variable status. This will, of course, cause you to
lose the output of the fsck command.
----------------------------------------------------------------------
$status=`rsh othermachine 'dowhateveriwanttodo ; echo $?'`
$status is the $? from the remote machine, not rsh.
----------------------------------------------------------------------
----------------------------------------------------------------------
----------------------------------------------------------------------
DEFAULT LOGIN SHELL = /bin/csh
==============================
----------------------------------------------------------------------
rsh mbsunf 'fsck /dev/smo0a; echo $status'
----------------------------------------------------------------------
set stat = `rsh mbsunf fsck /dev/smo0a; echo $status`
The variable "stat" should contain the exit status
----------------------------------------------------------------------
#!/bin/sh
RSH_STAT=`rsh mbsunf "fsck /dev/smo0a >& /dev/null ; echo \$status"`
echo $? # tells if rsh worked
echo $RSH_STAT # tells if fsck worked
this assumes that you are running as root, root can rsh from your machine to
mbsunf and that the default shell for root on mbsunf is /bin/csh. Change
"status" to "\?" if root's default shell is /bin/sh.
----------------------------------------------------------------------
Maybe I am being naive, but can't you just type
rsh mbsunf '(fsck /dev/smo0a ; echo $status)'
or
rsh mbsunf '(fsck /dev/smo0a ; if ($status) echo N; if (! $status) echo Y)'
----------------------------------------------------------------------
set RTNSTAT=`rsh machine ' fsck /dev/smo0a; echo $status'`
----------------------------------------------------------------------
----------------------------------------------------------------------
----------------------------------------------------------------------
OTHER ANSWERS
----------------------------------------------------------------------
Why don't you try using the "on" command with the "rexd" daemon enabled
on the remote host. This will allow you to examine the return value of
the command in the script you execute and echo a value back to your
host, use the mail or someting to that nature.
----------------------------------------------------------------------
#!/bin/sh
# @(#)ersh 2.1 89/12/07 Maarten Litmaath
# this rsh front-end returns the exit status of the remote command
# works OK with sh/csh-compatible shells on the remote side (!)
# beware of `funny' chars in `status' when working in sh-compatible shells
# if there is no remote command present, /usr/ucb/rlogin is invoked
# usage: see rsh(1)
hostname=
lflag=
nflag=
case $1 in
-l)
;;
*)
hostname=$1
shift
esac
case $1 in
-l)
lflag="-l $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 $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 $nflag "${*-:}"'; sh -c "echo $?0 $status >&2"' \
2>&1 >&3 | awk "$AWK" >&2
MY 'C' BIT
==========
if (strcmp(host,diskhost)==0)
{
str_cpy(command,"");
}
else
{
str_cpy(command,"rsh ");
str_cat(command,diskhost);
}
str_cat(command," '/etc/fsck -n ");
str_cat(command,devname);
str_cat(command," < /dev/null >& /dev/null ; echo \$status > ");
str_cat(command,inuse);
str_cat(command,".fsck '");
system(command);
str_cpy(filename,inuse);
str_cat(filename,".fsck");
if ((file = fopen(filename,"r")) == 0)
{ finish("can't access tempoary file",NONUMBER);
refresh();
}
if ((fscanf(file,"%s",inline) == EOF) || (strcmp(inline,"0")!=0))
{
str_cpy(command,"echo ' fsck(8) of optical disk has failed, (USER=");
str_cat(command,user);
str_cat(command,")(HOST=");
str_cat(command,host);
str_cat(command,") ' | /usr/ucb/mail ");
str_cat(command,mailwho);
system(command);
finish("fsck failed find a Systems Administrator",NONUMBER);
}
RICK DIPPER, Wolfson Image Analysis Unit, rick@uk.ac.man.mb.wiau
Department of Medical Bio-Physics, University of Manchester 061-275-5158
.............................Meemberrr the of Fumblee Ingers Culb..............
This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:06:10 CDT