提问人:KrisJ 提问时间:3/9/2023 最后编辑:KrisJ 更新时间:3/10/2023 访问量:112
systemd 不执行带有 & 符号的 bash 行
systemd doesn't execute bash lines with ampersand
问:
我正在开发一个启动脚本,它将从文件中读取“命令行”并将它们放入数组中。 然后使用 for 循环从数组中逐个执行。当脚本运行时,每件事看起来都很完美。但是,在从 systemd 服务文件中调用脚本后,所有行都执行没有问题,但带有 & 符号 (&) 的行不会执行。 我必须使用后台运行模式来执行所有“命令行”,因为它们不会退出,在某种程度上,数组中的所有“命令行”都应该继续运行。 下面只是一个使用与号 (&) 的函数形式脚本
DoesComponentExist()
{
i=0
for b in "${comparray[@]}"
do
if [[ -f "$CurrentDir/$b/bin/$b" ]];then
echo "file $b exists" >> $OutPutDir/OutputLog.txt
chmod +x $CurrentDir/$b/bin/$b
$CurrentDir/$b/bin/${comparraywitharg[$i]} > $OutPutDir/Output-$b 2&>1 &
echo "executed ${comparraywitharg[$i]}" >> $OutPutDir/OutputLog.txt
else
echo "file $b doesn't exist in $CurrentDir" >> $OutPutDir/OutputLog.txt
fi
i=($i+1)
done
}
$CurrentDir/$b/bin/${comparraywitharg[$i]} > $OutPutDir/Output-$b 2&>1 &
使用 systemd 调用脚本时,上面的行不会运行
systemd 版本 230
如何逐个或并行运行非现有命令数组
答: 暂无答案
评论