Last active
February 20, 2018 11:13
-
-
Save schlomo/7908037 to your computer and use it in GitHub Desktop.
rsh wrapper that correctly returns the exit code of the remote command, just like ssh does. This wrapper installs itself as rsh and calls the real rsh. Written for Bash.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This rsh wrapper supports reporting the exit code of the remote program. | |
# Assumes that remote shell is Bash or compatible and that you don't call | |
# exit directly (that would yield a return 127 regardless of the remote | |
# exit code!) | |
# | |
# Written by Schlomo Schapiro @ ImmobilienScout24 | |
# Licensed under the GNU General Public License, see http://www.gnu.org/licenses/gpl.html for full text | |
# | |
function rsh { | |
local res=$( | |
if [[ "$1" ]] ; then | |
command -p rsh "$@" \; echo -n 'RSH_REMOTE_EXIT_CODE=$?' | |
else | |
command -p rsh | |
fi | |
) || return $? | |
local exit_code="${res##*RSH_REMOTE_EXIT_CODE=}" | |
if [[ ! -n "$exit_code" ]]; then | |
exit_code=127 | |
fi | |
res="${res%%RSH_REMOTE_EXIT_CODE*}" | |
echo -n "$res" | |
return $exit_code | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rsh other.host sudo service foobar start || fail_test Could not start foobar service | |
rsh other.host sudo service foobar status || fail_test Service not running after start | |
rsh other.host sudo service foobar stop || fail_test Could not stop foobar service | |
! rsh other.host sudo service foobar status || fail_test Service still active after stop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment