相关疑难解决方法(0)

如何从bash脚本并行运行多个程序?

我正在尝试编写一个同时运行许多程序的.sh文件

我试过这个

prog1 
prog2
Run Code Online (Sandbox Code Playgroud)

但是运行prog1然后等到prog1结束然后开始prog2 ...

那我怎么能并行运行呢?

parallel-processing bash

218
推荐指数
12
解决办法
23万
查看次数

使用xargs并行运行程序

我目前有当前的脚本.

#!/bin/bash
# script.sh

for i in {0..99}; do
   script-to-run.sh input/ output/ $i
done
Run Code Online (Sandbox Code Playgroud)

我希望使用xargs并行运行它.我试过了

script.sh | xargs -P8
Run Code Online (Sandbox Code Playgroud)

但这样做只在当时执行一次.也没有运气-n8.添加&在脚本for循环中执行的行的末尾将尝试一次运行脚本99次.如何在当时仅执行8次循环,最多100次.

parallel-processing bash xargs

70
推荐指数
4
解决办法
6万
查看次数

并行bash脚本运行多个脚本

我有一个bash脚本,其中包含串行运行的其他脚本.但是,运行它们需要相当长的时间.有没有办法并行运行这些脚本以提高整体性能?它们彼此独立.

它看起来类似于:

#!/bin/bash

#some code here
cppcheck.sh
churn.sh
run.sh
Run Code Online (Sandbox Code Playgroud)

更新:

**git log --pretty=format: --numstat | perl -ane'$c{$F[2]} += abs($F[0]+$F[1]) 
if $F[2];END {print "$_\t$c{$_}\n" for sort keys %c}' > ${OUTPUT_DIR}/churn.txt**
sed -i -e '/deps/d;/build/d;/translations/d;/tests/d' -e 30q ${OUTPUT_DIR}/churn.txt
sort -r -n -t$'\t' -k2 ${OUTPUT_DIR}/churn.txt -o ${OUTPUT_DIR}/churn.txt
echo "set term canvas size 1200, 800; set output '${OUTPUT_DIR}/output.html'; 
unset key; set bmargin at screen 0.4; set xtics rotate by -90 scale 0,0; 
set ylabel 'Number of lines changed (total)'; set title 'Files with high …
Run Code Online (Sandbox Code Playgroud)

parallel-processing bash

48
推荐指数
1
解决办法
6万
查看次数

如何执行并行命令

我正在处理大型项目,我们有多个npm packages.

我想并行安装所有软件包,这意味着我希望所有软件包同时运行(以节省时间),并且在最后一次安装完成后继续我的脚本。

示例脚本:

#!/bin/zsh
#...

NPM_FOLDERS=(
    common.library/audit
    common.library/cipher
    common.library/logger
    ...
)

# Get the number of total folders to process
counter=${#NPM_FOLDERS[@]};

# counter for user feedback to the current install folder index
index=1;

# loop and install all the required packages
for folder in $NPM_FOLDERS;
do 
    #  Print the installation message with the folder & couters
    echo "\033[38;5;255m($index/$counter) Executing npm install in: \033[38;5;226m$folder";
    
    # change the folder to the required location    
    cd $ROOT_FOLDER/$folder;
    
    # Execute install on …
Run Code Online (Sandbox Code Playgroud)

bash shell ubuntu zsh node.js

4
推荐指数
1
解决办法
545
查看次数

标签 统计

bash ×4

parallel-processing ×3

node.js ×1

shell ×1

ubuntu ×1

xargs ×1

zsh ×1