複数行条件がある場合 awk する方法

複数行条件がある場合 awk する方法

私のログにはいくつかの問題があり、一致する条件がある場合は警告が必要です。

いくつかのログ条件は次のとおりです。

2019-07-20|20:25|sorry system error|183
2019-07-20|20:25|Internal Error|8
2019-07-20|20:25|System Busy|1

私の期待は、フィールドの場合は次の条件に警告を送信します$4 >= 100print $0curl

curl -X GET "http://x.x.x.x:5000/submit_fajar.php?msg=print $0+`hostname`+time_`date +%d%h%y_%H.%M.%S`"

次の条件を試しましたが、まだcurl使用方法を混乱させています。print $0

cat datafiles  | strings | awk -F"|" '{if ($4 > 100)print ""$1","$2",please check have many error respond MFS",$3,"count :",$4;'}'' 

助けてください

ありがとう

ベストアンサー1

これはあなたがしたいことですか?

while IFS= read -r line; do
    curl "...$line..."
done < <(awk '...')

ところで、awkスクリプトは次のようになります。

awk -F"|" '{if ($4 > 100)print ""$1","$2",please check have many error respond MFS",$3,"count :",$4;'}''

しなければならない:

awk -F'|' '$4 > 100{print $1 "," $2 ",please check have many error respond MFS", $3, "count :", $4}'

あなたのカールはおそらく次のようになります:

hostname="$(hostname)"
now="$(date +'%d%h%y_%H.%M.%S')"
curl -X GET "http://x.x.x.x:5000/submit_fajar.php?msg=\"${line}+${hostname}+${now}\""

最初の2行はループの前にあるので、全体の内容は次のとおりです。

#!/bin/env bash

hostname="$(hostname)"
now="$(date +'%d%h%y_%H.%M.%S')"
while IFS= read -r line; do
    curl -X GET "http://x.x.x.x:5000/submit_fajar.php?msg=\"${line}+${hostname}+${now}\""
done < <(cat datafiles | strings | awk -F'|' '$4 > 100{print $1 "," $2 ",please check have many error respond MFS", $3, "count :", $4}')

理由があるとしますcat

おすすめ記事