0

I have a shell script written by some vendor and does a lot of low level stuffs under the hood which I have no domain specific knowledge on. I have a manual given by the vendor how to execute this script on the CLI manually. it works as expected if executed on the CLI.

Now I write a script to automate this process, but the ssh session of my script will terminate abruptly when the script is completed and the remote commands after the script within the ssh session will not execute. only the local commands out of the ssh session will continue.

echo "LOCAL: start"
sshpass -p ${PSSWD} timeout 45 ssh -n -q -oConnectTimeout=10 -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null user@$ip '( 

function executeFlash(){
    echo "remote: executeFlash: start" 
    flash.sh 
    echo "remote: executeFlash: end" 

}

echo "REMOTE: start"
cp flashrom /usr/sbin/
cp libftdi1.so.2 /usr/lib64/
executeFlash
echo "REMOTE: end"

)'
echo "LOCAL: end"

output is

LOCAL: start
REMOTE: start
remote: executeFlash: start
some logs showing the successful execution of flash.sh
      --- missing remote command for "remote: executeFlash: end" and "REMOTE: end"
LOCAL: end

As shown above, the session seems to be terminated and rest of the remote commands not executed "remote: executeFlash: end" I have tried to call the script in subprocess like flash.sh & or ./flash.sh but no luck. During Manual execution in the CLI, I do not lose the ssh session which is the expected behavior

electricalbah
  • 2,227
  • 2
  • 22
  • 36
  • Try to redirect the input using a here document. – KamilCuk Jun 28 '21 at 08:00
  • Thanks @KamilCuk Can you share a snippet for the part you are suggesting – electricalbah Jun 28 '21 at 08:18
  • https://en.wikipedia.org/wiki/Here_document#Unix_shells `Manual execution in the CLI, I do not lose the ssh session which is the expected behavior` What is "lose ssh session", what do you mean by that? `but the ssh session of my script will terminate abruptly` Add `set -x`, please post the output of `echo $-` _in the remote session_. Try to determine what "CLI" is that - try printing `echo $BASH_VERSION` or such. – KamilCuk Jun 28 '21 at 08:21
  • @KamilCuk : While a HERE document would surely be more natural here, I don't see a technical problem with the approach currently taken. The function _executeFlash_ is obviously run. – user1934428 Jun 28 '21 at 08:27
  • @electricalbah : From the transscript, we see that `flash.sh` is not found. Are you sure that this script exists on the remote host **and** is in the PATH? – user1934428 Jun 28 '21 at 08:27
  • Thanks, all I am waiting for some test devices to be available in the next couple of hours I think I have found the issue, but I need to verify it. I have foolishly added "timeout 45" from another script which I believe is what is killing my ssh session. – electricalbah Jun 28 '21 at 08:33
  • It was silly mistake, I confirmed this was due to timeout I had set in the ssh – electricalbah Jun 28 '21 at 10:17
  • alright, please answer your own question and accept the answer to close it ;) – Camusensei Jun 28 '21 at 12:29

1 Answers1

0

After removing "timeout 45" from the ssh command, the issue got resolved

electricalbah
  • 2,227
  • 2
  • 22
  • 36