后台命令

问题描述 投票:0回答:0

我正在编写一个启动脚本,它将从文件中读取“命令行”并将它们放入数组中。 然后使用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 调用脚本时,上述行不会运行

系统版本 230

我怎样才能一个接一个或并行地运行非退出命令数组

bash shell background systemd ampersand
© www.soinside.com 2019 - 2024. All rights reserved.