bash 命令似乎不起作用,但它的 echo 起作用了?
好吧,我是 Linux 新手,所以这可能是一个非常新手的事情,事情是这样的:
我有一个脚本,在其中我试图将一些不同的作业发送到远程计算机(实际上是 Amazon 的 EC2 实例),这些作业实际上是我使用不同参数运行的相同函数。
最终在脚本代码中我有这一行:
nohup ssh -fqi key.pem ubuntu@${Instance_Id[idx]} $tmp
如果我这样做:
echo nohup ssh -fqi key.pem ubuntu@${Instance_Id[idx]} $tmp
我得到:
nohup ssh -fqi key.pem [email protected] '(nohup ./Script.sh 11 1&)'
现在奇怪的事情。如果我运行脚本中没有回显的代码,它就不起作用!它在 nohup.out 中说(在我的笔记本电脑中,远程实例中没有创建 nohup.out) bash: (nohup ./Script.sh 10 1&): No such file or directory
文件确实存在于本地和远程并且是 chmod +x。 如果我只是运行相同的脚本,并在有问题的行前面添加 echo,然后复制其输出并粘贴到终端中,它就可以工作!
欢迎任何线索,谢谢!
Well, I'm new to linux so this may be a very newbie kinda of thing, here it goes:
I have a script in which I'm trying to send some different jobs to remote computers (in fact Amazon's EC2 instances), these jobs are in fact the same function which I run with different parameters.
eventually in the script code I have this line:
nohup ssh -fqi key.pem ubuntu@${Instance_Id[idx]} $tmp
if I do:
echo nohup ssh -fqi key.pem ubuntu@${Instance_Id[idx]} $tmp
I get:
nohup ssh -fqi key.pem [email protected] '(nohup ./Script.sh 11 1&)'
Now the weird thing. If I run the code with no echo in the script it doesnt work! it says in the nohup.out (in my laptop, no nohup.out is created in the remote instance) bash: (nohup ./Script.sh 10 1&): No such file or directory
The file does exist locally and remotely and is chmod +x.
If I simply run the very same script with an echo in front of the problematic line and copy its output and paste in the terminal, it works!.
Any clues welcome, thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试从 $tmp 中删除单引号。看起来 bash 将
(nohup ./Script.sh 10 1&)
视为不带参数的命令,但从技术上讲,nohup
是带参数的命令./Script.sh 10 1
。Try removing the single quotes from $tmp. It looks like bash is treating
(nohup ./Script.sh 10 1&)
as the command with no parameters, but technicallynohup
is the command with the parameters./Script.sh 10 1
.问题是
$tmp
变量中 nohup 命令周围的单引号。这些不会在本地 shell 上使用,因此 SSH 会逐字传递它们。这意味着远程 ssh 服务器尝试将(nohup ./Script.sh 10 1&)
解释为命令(查找名为该文件的文件),但显然没有。确保删除$tmp
中的单引号。The problem is the single quotes around the nohup command in your
$tmp
variable. These don't get used on the shell locally, so SSH passes them verbatim. This means remotely the ssh server tries to interpret(nohup ./Script.sh 10 1&)
as a command (looks for a file named that) which there clearly isn't. Make sure you remove the single quotes in$tmp
.