简体   繁体   中英

Shell script on remote server terminates ssh session

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

从 ssh 命令中删除“超时 45”后,问题得到解决

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM