プロセスが存在しない場合のコマンドの実行を防ぐ方法

プロセスが存在しない場合のコマンドの実行を防ぐ方法

Kornシェルスクリプトでexpdpを実行しています。再利用できるようにスクリプトを設定したため、後でプロセスが失敗した場合は、完了したステップを実行せずに再実行できます。私はバックグラウンドで2つのプロセスを実行しており、スクリプトを続行する前に両方のプロセスが完了するのを待っています。たとえば、次のロジックを使用して待ちます。 expdp プロセスが完了したら、ログ機能を使用して完了したメッセージを作成します。

while   ps | grep "expdp" | grep -v grep
do
    echo expdp is still in the ps output. Must still be running.
    sleep 5
done

WriteLog "Completed exporting client schemas"

expdpプロセスが存在しない場合にのみログ書き込みが行われるように場所を設定するにはどうすればよいですか(例:expdp以降に発生するエラーを修正した後にスクリプトを再利用するなど)。 psでプロセスが見つからない場合は、ログを再作成しないでください。

ベストアンサー1

私はあなたが間違った方法で検索していると思います。私は次のスクリプトを書いています:

if [ "z$STEP5" != "zOK" ] ; then
    expdp -your_options > $logfile &
    while ps ax | grep [e]xpdp ; do
        echo "expdp still in progress..."
        sleep 5
    done
    wait # in order to be sure there is no more background processes...
    tail -n1 $logfile | grep "successfully without warnings" >/dev/null 2>&1
    if [ $? -ne 0 ] ; then 
        echo "Some errors occured while export"
    else
        echo "Export done sucessfully"
    fi
fi

おすすめ記事