2017-11-29 7 views
-2

次のwhileループを作成し、60秒ごとに "string"がファイル内に現れる時間(ファイルパスと文字列省略)を出力します。IF文をwhileループに実装する方法とwhileループを無期限に実行する方法はありますか? (Bash)

while true; do /path/to/file | grep -i "string" | wc -l; sleep 60; done 

出力が100を超えると、電子メールを送信できるようにIF文を実装する最も簡単で簡単な方法は何ですか?私はwhileループを無期限に実行する必要があります。

答えて

0

ifステートメントを含む別のコマンドに直接パイプすることができます。

while true; do 
    /path/to/file | grep -i "string" | wc -l | { 
    read count 
    if [[ $count -gt 100 ]]; then 
     send_email 
    fi 
    echo "$count" 
    } 
done 
関連する問題