我有一个脚本在后台运行,比如:
su - insite1 -c "invokeTest.sh" &
现在这个脚本,invokeTest.sh 有内容:
while [ 1 ]
do
echo "Hello World from invokeTest" >> /tmp/invokeTest
( exec "/tmp/test.sh" )
done
虽然它会打印“Hello World from invokeTest”,但它不会调用 test.sh。
我的问题:
有什么方法可以直接从 su - insite1 -c""
无限循环调用 test.sh,这样我们就可以完全跳过 invokeTest.sh
本身(但 test. sh 需要在后台运行"?
如果不是,如何确保从 invokeTest.sh
调用 test.sh?
最佳答案
要回答关于在没有脚本的情况下运行命令的问题,您可以将任何 shell 命令放入 -c
参数中,包括 while
循环。所以你可以这样写:
su - insite1 -c 'while :; do echo "Hello World" >> /tmp/invokeTest; /tmp/test.sh; done' &
关于linux - 如果在后台运行,从脚本调用子 shell 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40269583/