ssh remote execution of scripts and return codes for success or failure

ssh remote execution of scripts and return codes for success or failure

am 21.09.2007 16:16:00 von gerry.brennan

findfile.sh "filename" returns 0 or 1 ...... depending on success or
failure.

I am trying to remotely execute this

ssh operator@141.102.3.110 findfile.sh filename2 >> /dev/null &
ssh operator@141.102.3.110 findfile.sh filename2 >> /dev/null &
wait
Is there a way to determine the result of the above operations


/gerry

Re: ssh remote execution of scripts and return codes for success orfailure

am 21.09.2007 18:20:49 von Icarus Sparry

On Fri, 21 Sep 2007 07:16:00 -0700, gerry.brennan wrote:

> findfile.sh "filename" returns 0 or 1 ...... depending on success or
> failure.
>
> I am trying to remotely execute this
>
> ssh operator@141.102.3.110 findfile.sh filename2 >> /dev/null &
> ssh operator@141.102.3.110 findfile.sh filename2 >> /dev/null &
> wait
> Is there a way to determine the result of the above operations
>
>
> /gerry

Method 1
Record the process id's of the ssh's (use $!), then use "wait" with the
process id as an arguement.

Method 2

if ssh -n operator@1.2.3.4 whatever
then
echo 1.2.3.4 worked
else
echo 1.2.3.4 failed
fi &

Re: ssh remote execution of scripts and return codes for successor failure

am 21.09.2007 18:28:55 von Michael Tosch

gerry.brennan@gmail.com wrote:
> findfile.sh "filename" returns 0 or 1 ...... depending on success or
> failure.
>
> I am trying to remotely execute this
>
> ssh operator@141.102.3.110 findfile.sh filename2 >> /dev/null &
> ssh operator@141.102.3.110 findfile.sh filename2 >> /dev/null &
> wait
> Is there a way to determine the result of the above operations
>
>
> /gerry
>


tail /dev/null

:-\

Honestly, it is more efficient to do the > /dev/null
on the remote machine:
ssh operator@141.102.3.110 "findfile.sh filename2 > /dev/null" &


--
Michael Tosch @ hp : com

Re: ssh remote execution of scripts and return codes for success or failure

am 24.09.2007 08:45:54 von gerry.brennan

On Sep 21, 5:28 pm, Michael Tosch
wrote:
> gerry.bren...@gmail.com wrote:
> > findfile.sh "filename" returns 0 or 1 ...... depending on success or
> > failure.
>
> > I am trying to remotely execute this
>
> > ssh opera...@141.102.3.110 findfile.sh filename2 >> /dev/null &
> > ssh opera...@141.102.3.110 findfile.sh filename2 >> /dev/null &
> > wait
> > Is there a way to determine the result of the above operations
>
> > /gerry
>
> tail /dev/null
>
> :-\
>
> Honestly, it is more efficient to do the > /dev/null
> on the remote machine:
> ssh opera...@141.102.3.110 "findfile.sh filename2 > /dev/null" &
>
> --
> Michael Tosch @ hp : com

Sorry guys .. I forgot one important criteria ...
I need to do it in paralell ...

I think both solutions above will only work serially ...

Point taken on the /dev/null issue.

/Gerry.

Re: ssh remote execution of scripts and return codes for success or failure

am 24.09.2007 15:47:22 von Miles

On Sep 24, 1:45 am, gerry.bren...@gmail.com wrote:
> On Sep 21, 5:28 pm, Michael Tosch
> wrote:
>
>
>
> > gerry.bren...@gmail.com wrote:
> > > findfile.sh "filename" returns 0 or 1 ...... depending on success or
> > > failure.
>
> > > I am trying to remotely execute this
>
> > > ssh opera...@141.102.3.110 findfile.sh filename2 >> /dev/null &
> > > ssh opera...@141.102.3.110 findfile.sh filename2 >> /dev/null &
> > > wait
> > > Is there a way to determine the result of the above operations
>
> > > /gerry
>
> > tail /dev/null
>
> > :-\
>
> > Honestly, it is more efficient to do the > /dev/null
> > on the remote machine:
> > ssh opera...@141.102.3.110 "findfile.sh filename2 > /dev/null" &
>
> > --
> > Michael Tosch @ hp : com
>
> Sorry guys .. I forgot one important criteria ...
> I need to do it in paralell ...
>
> I think both solutions above will only work serially ...
>
> Point taken on the /dev/null issue.
>
> /Gerry.

I believe you are going to have a difficult time implementing both of
your criteria: in parallel and checking the return code. Doing one or
the other is quite easy, and ideas have already been posted. But doing
both will be tough. Also, do you want the return code of SSH or the
return code of the command that ssh ran?

My best idea is to run the SSH commands in parallel, saving the output
to a file and then examining every output file. I already have a
script to run SSH commands in parallel, it looks like:
############################################################ ######################
#
############################################################ ######################
COUNT=1
echo "#!/usr/bin/ksh" >$COMMAND_SCRIPT
cat $WORKING_COL_FILE | grep -v "^#" | while read NODENAME
do
NODES[$COUNT]=$NODENAME
echo "/usr/bin/ssh $NODENAME \"$COMMAND\" 1>$WORK_DIR/${0##*/}.
$NODENAME.output.$$.tmp 2>&1 &">>$COMMAND_SCRIPT
let "COUNT += 1"
done
echo "wait" >>$COMMAND_SCRIPT

$COMMAND_SCRIPT

This code just displays the output, but it could easily be modified:
############################################################ ######################
#
############################################################ ######################
print
let "MAX = $COUNT - 1"
COUNT=1
while [[ $COUNT -le $MAX ]]
do
NODENAME=${NODES[$COUNT]}
print "$NODENAME: \c"
cat $WORK_DIR/${0##*/}.$NODENAME.output.$$.tmp | egrep -vip "This
is a private computer"
print
let "COUNT += 1"

done

Miles

Re: ssh remote execution of scripts and return codes for success orfailure

am 24.09.2007 17:42:34 von Icarus Sparry

On Sun, 23 Sep 2007 23:45:54 -0700, gerry.brennan wrote:

[snip, he wants the return code from ssh run in a loop]

>
> Sorry guys .. I forgot one important criteria ... I need to do it in
> paralell ...
>
> I think both solutions above will only work serially ...
>
> Point taken on the /dev/null issue.
>
> /Gerry.

Both my proposed solutions work in 'paralell'.

Which is "better" depends on what you are going to do with the results.