LoginSignup
0
0

More than 5 years have passed since last update.

ShellScriptでディレクトリ内の全てのファイルに対してプログラムを実行

Posted at

実行プログラムprogramの実行形式は./program 入力ファイル 出力ファイルとします。
プログラムの入力ファイルはinput/ディレクトリから読み込み、出力ファイルはoutput/ディレクトリ、標準出力と標準エラーのログはlog/ディレクトリに出力します。

script.sh
#!/bin/bash

program="program"
in_dir="input/"
out_dir="output/"
log_dir="log/"

while read -d $'\0' file; do
    f=`echo ${file} | awk -F "/" '{ print $NF }'`
    nohup ./${program} ${in_dir}${f} ${out_dir}${f}.out > ${log_dir}${f}.log 2>&1
done < <(find ${in_dir} -mindepth 1 -maxdepth 1 -print0)

スクリプトファイルを実行するときは&をつけてバックグラウンドで実行すると良いでしょう。

$ ./script.sh &
0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0