简体   繁体   English

通过Fabric运行要运行后台运行命令的shell脚本

[英]Running a shell script through Fabric which wants to run a background running command

I am a newbie in Fabric, and want to run one command in a background, it is written in shell script, and I have to run that command via Fabric, so lets assume I have a command in shell script as: 我是Fabric的新手并且想在后台运行一个命令,它是用Shell脚本编写的,因此我必须通过Fabric运行该命令,因此假设我在Shell脚本中有一个命令如下:

#!/bin/bash/
java  &

Consider this is a file named myfile.sh 考虑这是一个名为myfile.sh的文件

Now in Fabric I am using this code to run my script as: 现在在Fabric中,我正在使用以下代码以如下方式运行脚本:

put('myfile.sh', '/root/temp/')
sudo('sh /root/temp/myfile.sh')

Now this should start the Java process in background but when I login to the Machine and see the jobs using jobs command, nothing is outputted. 现在,这应该在后台启动Java进程,但是当我登录计算机并使用Jobs命令查看作业时 ,什么都没有输出。

Where is the problem please shed some light. 问题出在哪里,请阐明一下。

搭配使用

run('nohup PATH_TO_JMETER/Jmetercommand & sleep 5; exit 0)

maybe the process exists before you return. 您返回之前,该过程可能已经存在。 when you type in java, normally it shows up help message and exits. 当您输入Java时,通常会显示帮助消息并退出。 Try a sleep statement or something that lingers. 尝试睡眠声明或其他持续存在的事物。 and if you want to run it in the background, you could also append & to the sudo call 如果您想在后台运行它,还可以在sudo调用后附加&

I use run("screen -d -m sh /root/temp/myfile.sh",pty=False) . 我使用run("screen -d -m sh /root/temp/myfile.sh",pty=False) This starts a new screen session in detached mode, which will continue running after the connection is lost. 这将以分离模式启动新的屏幕会话,该会话将在连接断开后继续运行。 I use the pty=False option because I found that when connecting to several hosts, the process would not be started in all of them without this option. 我使用pty=False 选项,因为我发现当连接到多个主机时,如果没有该选项,则不会在所有主机中启动该过程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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