2

ファイルから一連のコマンドを実行するスクリプトを作成しようとしています

たとえば、ファイルには3つのコマンドperl script-a、perl script-b、perl script-cのセットがあり、各コマンドは新しい行にあり、このスクリプトを作成しました

#!/bin/bash
for command in `cat file.txt`
do
   echo $command
   perl $command

done

問題は、一部のスクリプトが停止したり、終了するのに時間がかかりすぎたりすることであり、それらの出力を確認したいと考えています。実行されている現在のコマンドでCTRL + Cを送信して、txtファイルの次のコマンドにジャンプし、wole bashスクリプトをキャンセルしない場合に備えて、bashスクリプトを作成することができます。

ありがとうございました

4

2 に答える 2

4

trap 'continue' SIGINT無視するために使用できますCtrl+c

#!/bin/bash
# ignore & continue on Ctrl+c (SIGINT)
trap 'continue' SIGINT

while read command
do
   echo "$command"
   perl "$command"
done < file.txt

# Enable Ctrl+c
trap SIGINT

catまた、ファイルの内容を読み取るために呼び出す必要はありません。

于 2013-09-16T16:46:51.207 に答える
0
#!/bin/bash
for scr in $(cat file.txt)
do
 echo $scr

 # Only if you have a few lines in your file.txt,
 # Then, execute the perl command in the background
 # Save the output.
 # From your question it seems each of these scripts are independent

 perl $scr &> $scr_perl_execution.out &

done

各出力をチェックして、コマンドが期待どおりに実行されているかどうかを確認できます。そうでない場合は、kill各コマンドを終了するために使用できます。

于 2013-09-16T16:50:48.237 に答える