rsh command

Hi
Does anybody know how to to return the exit code of a remote
command when using rsh?

I know that "rsh" has no built-in ability for that.
The echo $? is showing the results of the rsh command. Not the
remotely executed command.

I am trying to get the return code of psef command from the following:

CRSM4$rsh sundev1 psef bb_filexfer

Thanks a lot....

You can try

rsh sundev1 "psef bb_filexfer && echo $?"

NM, that doesn't work. Your best bet is to put your command into a script that will return the exit code on the remote machine, then just run the script via rsh.

This should work:

 rsh sundev1 "psef bb_filexfer; echo $?"
  1. The echo $? is showing the results of the rsh command. Not the
    remotely executed command.
  2. rsh has no built-in ability to return the exit code of a remote
    command.
  3. Use ssh, it does have the ability to return the exit code.
  4. Modify the script such that it echos the exit code as opposed to
    using the exit command.

...this is an issue with shell quoting.

In my original reply which mistakenly used double quotes, the "$?" was returning the exit code of whatever command was run prior, not of the rsh (the "$?" was being interpreted by the shell before the entire quoted string was sent to the rsh command).

This can be solved with either using single quotes or escaping the "$?" to prevent the shell form interpreting it first:

rsh sundev1 'psef bb_filexfer; echo $?'

or

rsh sundev1 "psef bb_filexfer; echo \$?"

That being said, using ssh (as suggested by Sagar) is a good option as it can be setup more securely and has additional options.

1 Like