如何使用ssh运行变量中存在的nohup命令?

问题描述 投票:2回答:3

我是Linux新手。我在变量中存储了一个命令

a="nohup ./startWebLogic.sh &".

我需要在远程服务器上运行此命令以及其他一些命令。我试过如下......

ssh user@server << EOF
few shell commands then
eval "$a"
EOF

当我运行上面的脚本时,它在登录远程服务器后没有做任何事情,既不会抛出任何错误,也不会运行nohup命令。我的意图是使用nohup启动远程服务器上的WebLogic。 。谢谢!!

shell ssh nohup
3个回答
1
投票

你可以运行它:

ssh user@server "$a"

变量$a将被扩展并传递给server的shell。

如果你想使用<

ssh user@server sh -s <<EOF
few shell commands then
eval "$a"
EOF

请注意sh -s这里,我删除了<<EOF之间的空间。


0
投票

使用了=“nohup ./startWebLogic.sh”nohup.out 2>&1&“


0
投票

我有类似的问题,尝试创建一个文件,如a.sh

#!/bin/bash
nohup ./startWebLogic.sh &
exit 0

并设置a="./a.sh"

© www.soinside.com 2019 - 2024. All rights reserved.