?
Solved

ksh remsh return code

Posted on 2003-03-06
10
Medium Priority
?
1,029 Views
Last Modified: 2013-12-26
I am running some remote commands from a ksh script with remsh. Is there a way to retrieve the actual return value of the remote command instead of just the remsh command?

example:
#/usr/bin/ksh
remsh nodeA -n "/usr/bin/ll /tmp/file1"
echo $?      # returns return value of remsh

-> how to get return value of 'll' command ?

thanks
maerkima
0
Comment
Question by:maerkima
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +1
10 Comments
 
LVL 9

Expert Comment

by:HamdyHassan
ID: 8079671
From Man pages

example% rsh lizard cat lizard.file >> example.file

appends the remote file lizard.file from the machine  called
     ``lizard''  to  the  file called example.file on the machine
     called ``example,'' while the command:




so, I think you need to do the following

remsh nodeA -n "/usr/bin/ll /tmp/file1;echo $?" >> local.txt
echo local.txt

0
 
LVL 14

Expert Comment

by:chris_calabrese
ID: 8080908
HamdyHassan is absolutely correct that you're going to have to jump through some hoops to do this.

Of course, his particular example scriptlet is not the only way of doing it, but the basic idea is there.
0
 

Author Comment

by:maerkima
ID: 8081374
Well

It's just one way I tried to get the RC as well. But the example from HamdyHassan does NOT work! (rc 0 is returned)

remsh seems to behave quite tricky with this.

Are there any other suggestions?

Thanx alot
maerkima
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:maerkima
ID: 8081381
Well

It's just one way I tried to get the RC as well. But the example from HamdyHassan does NOT work! (rc 0 is returned)

remsh seems to behave quite tricky with this.

Are there any other suggestions?

Thanx alot
maerkima
0
 

Author Comment

by:maerkima
ID: 8081430
Well

It's just one way I tried to get the RC as well. But the example from HamdyHassan does NOT work! (rc 0 is returned)

remsh seems to behave quite tricky with this.

Are there any other suggestions?

Thanx alot
maerkima
0
 
LVL 14

Accepted Solution

by:
chris_calabrese earned 150 total points
ID: 8081484
I've seen things like this that work quite well (in ksh)

function myrsh {
  typeset -i exit_val=1
  rsh "$@" "; echo RETURN_CODE_IS $?" |
  while read LINE
  do if [[ $LINE = RETURN_CODE_IS\ [0-9]* ]]
     then print "$LINE" | read junk exit_val
     else print -r -- "$LINE"
     fi
  done
  return $exit_val
}
0
 
LVL 5

Expert Comment

by:ecw
ID: 8088691
In this example,
  remsh nodeA -n "/usr/bin/ll /tmp/file1;echo $?" >> local.txt

The apparent exit code is set by the command before remsh.  Variable expansion takes place in double-quotes, ie. $? is evaluated before remsh is called.
0
 
LVL 9

Expert Comment

by:HamdyHassan
ID: 8088780
If ecw's idea is correct, so we need to call script

create myscript.sh as follow

/usr/bin/ll /tmp/file1
echo $?

and remsh command will be

remsh nodeA -n "/home/myscript.sh" >> local.txt
0
 
LVL 5

Expert Comment

by:ecw
ID: 8090040
No all I'm saying is either use single-quotes,
  remsh nodeA '/usr/bin/ll /tmp/file1;echo $?' >>local.txt
or escape the $
  remsh nodeA "/usr/bin/ll /tmp/file1;echo \$?" >>local.txt
rather than a plain $? in double-quotes.

If you're interested in the output of the remote command, use something similar to chris_calabrese's suggestion, if all you interested in is success or failure, discard the output and return the remote $?.



0
 

Author Comment

by:maerkima
ID: 8109509
thanx for your help !
bye
maerkima
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question