0

We have several scripts on remotehost which we trigger from my localhost using ssh like below.

ssh remuser@remhost sh /web/bin/stop.sh

We had OS patching activity this weekend post which the above ssh command never returns and feels like it is hung or waiting for input.

It may be difficult to get details regarding what patch was applied to the OS.

Here are the details of the stop.sh

cat stop.sh
exec /usr/bin/java -jar /web/service.jar -DLOG_PATH=/web/logs --server.address=10.23.41.211 --server.port=10500 --spring.profiles.active=dev >> /web/logs/boot.log
exit 0;

First, we tried this solution from this forum but it does not return.

ssh remuser@remhost 'sh /web/bin/stop.sh my.jar dev &> /dev/null < /dev/null'

Debug output of ssh -vv when it freezes and does not return is below:

debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: client_input_channel_req: channel 0 rtype [email protected] reply 0
debug2: channel 0: rcvd eow
debug2: channel 0: chan_shutdown_read (i0 o0 sock -1 wfd 4 efd 6 [write])
debug2: channel 0: input open -> closed

We then tried the below and the ssh started returning but was unable to run the script on the remote host.

ssh -fN remuser@remhost sh /web/bin/stop.sh my.jar dev

Note: ssh remuser@remhost id does return and works fine. Other scripts also work fine.

The issue is only with the scripts that have <or << or > or >> where the control returns back to the invoker host.

Can you please suggest?

Note: There is no reason to debug the scripts. They are not the cause of issue as all the script are different and some very simple.

17
  • If you don't know what is causing the problem, how can you be so certain it isn't something in the scripts that's triggering it? Commented Apr 20, 2021 at 18:20
  • Does ssh remuser@remhost id return a value? (Not interested in what the value is, just whether it returns one.) If it does then the problem is in your script. This is basic diagnosis 101 Commented Apr 20, 2021 at 18:21
  • 1
    yes ssh remuser@remhost id returns value. Also update the original post with ssh -vv debug output
    – Ashar
    Commented Apr 20, 2021 at 18:37
  • I suggest to show the code of the script /web/bin/stop.sh (or some other script that reproduces the problem). What exactly means "was unable to run the script on the remote host"? Please copy&paste the exact error message to your question.
    – Bodo
    Commented Apr 20, 2021 at 18:47
  • @Bodo i shared by updating the original post
    – Ashar
    Commented Apr 20, 2021 at 18:48

2 Answers 2

1

The following helped resolve the issue and now the control comes back while the script gets executed on the target host.

ssh -f -n remuser@remhost 'sh -c /web/bin/stop.sh my.jar dev'
1
  • "-f" option worked Commented Nov 7, 2022 at 23:37
1

For anyone else not satisfied by needing to put ssh in the background (perhaps if you need the exit status of the remote command), in my situation the issue was from X11 forwarding enabled in the .ssh/config.

Ensuring X11 is not forwarded with -x worked for me:

ssh -x remuser@remhost 'sh -c /web/bin/stop.sh my.jar dev'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .