ps -p 19105,19107

ps -p 19105,19107

nohupを使って実行するシェルスクリプトを作成しました。スクリプトはさまざまなSQLスクリプトを順次実行しますが、並行して実行することはほとんどありません。私のスクリプトには次の文があります。

echo exit | sqlplus -s ${username}/${pwd}@${DB} @close1.sql
echo exit | sqlplus -s ${username}/${pwd}@${DB} @close2.sql

echo exit | sqlplus -s ${username}/${pwd}@${DB} @insertPricing1.sql &
pid1=$!
echo exit | sqlplus -s ${username}/${pwd}@${DB} @insertPricing2.sql &
pid2=$!

echo "Pricing Insert PIDs => ${pid1}, ${pid2}"

while [ `ps -p ${pid1},${pid2} | wc -l` > 1 ]
do
sleep 5
done

echo exit | sqlplus -s ${username}/${pwd}@${DB} @insertPricing3.sql

目的は、close1 -> close2 -> insertPricing1とinsertingPricing2 -> insertPricing3を並列に実行することです。ここで -> は順番にを意味します。

翌日、結果を確認したら(十分な時間が経過した後に完了する必要があります)、シェルスクリプトがまだ実行中であることを確認しました。 Pricing1とPricing2は完了しましたが、Pricing3はまだ起動していません。 1、2コースが完了しました。

ps -p 19105,19107

  PID TTY          TIME CMD

whileループを実行すると問題が発生します。

 # ps -p 19105,19107 | wc -l
1

しかし、これは -

# while [ `ps -p 19105,19107 | wc -l` > 1 ]
> do
> echo "hello"
> done
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
........ ctrl+C

それでは、1が1より大きくないときにこのループが機能するのはなぜですか?解決策は何でなければなりませんか?

ベストアンサー1

助けてくれた@steeldriverのコメントありがとうございます。私の観点から、これは愚かな間違いです。 > [](またはシェルスクリプトのほとんどの場所)内では、リダイレクト演算子として扱われます。標準使用法は-gt

リンクの答えに従って整数を比較するには -

-eq  #Is equal
-ne  #Is not equal
-lt  #Less than
-le  #Less than or equal
-gt  #Greater than
-ge  #Greater than or equal

おすすめ記事