[英]Invoking subshells from script does not work if run in background
I have a script running in background, like: 我有一个在后台运行的脚本,例如:
su - insite1 -c "invokeTest.sh" &
Now this script, invokeTest.sh has contents: 现在,此脚本invokeTest.sh具有以下内容:
while [ 1 ]
do
echo "Hello World from invokeTest" >> /tmp/invokeTest
( exec "/tmp/test.sh" )
done
Although it prints, "Hello World from invokeTest" it does not call test.sh. 尽管它打印“ Hello World from invokeTest”,但它不会调用test.sh。
My question: Is there any way to call test.sh in infinite while loop directly from su - insite1 -c" "
so that we can totally skip invokeTest.sh
itself (but test.sh needs to run in background"? 我的问题:有什么方法可以直接从
su - insite1 -c" "
在无限while循环中直接调用test.sh,这样我们就可以完全跳过invokeTest.sh
本身(但test.sh需要在后台运行)?
If no, how to make sure test.sh is called from invokeTest.sh
? 如果否,如何确保从
invokeTest.sh
调用test.sh?
To answer your question about running the command without a script, you can put any shell commands into the -c
argument, including a while
loop. 要回答有关不使用脚本来运行命令的问题,可以将任何shell命令放入
-c
参数中,包括while
循环。 So you can write: 所以你可以这样写:
su - insite1 -c 'while :; do echo "Hello World" >> /tmp/invokeTest; /tmp/test.sh; done' &
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.