Bash 脚本如何远程运行命令然后退出远程终端

Bash 脚本如何远程运行命令然后退出远程终端

我正在尝试执行以下命令:

ssh nvidia@ubuntu-ip-address "/opt/ads2/arm-linux64/bin/ads2 svcd &"

到目前为止,此方法有效,只是在"/opt/ads2/arm-linux64/bin/ads2 svcd&"执行时它会挂在远程终端,除非我输入 ctrl+c(见下图)。

在此处输入图片描述

所以我正在寻找一个命令,该命令在执行"/opt/ads2/arm-linux64/bin/ads2 svcd &"命令后退出远程终端并继续执行本地 bash 脚本。

以下是我正在编写的 bash 脚本

#!/usr/bin/env bash

echo "Welcome to ADS2 Session Start..."

while  true 
do
echo "Starting service Daemon on the targert"
echo "Enter the ip-address of the target"
read x
if [ -z "$x" ]
then 
    echo "ip-address is empty"
else
    echo "Connecting with target..."
    if [[ $x =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ || $x =~ ^fdt-c-agx-[0-9][0- 
      9][0-9][0-9]$ ]]
    then
        ssh nvidia@"$x"   "/opt/ads2/arm-linux64/bin/ads2 svcd &"; exit 0 
        if ! ssh nvidia@"$x"
        then
            echo -e "\033[31mconnection failed\e[0m" 
        else
            echo -e "\033[32m connection succeded\e[0m"
        
            break
        fi
    else
        "Make sure the io address in the coorect form"  
    fi

fi
done

相关内容