試圖對日誌文件(即過去30天內的所有反彈)進行精確查詢。我不認爲stdin會拉zcat信息,我認爲也有一個錯誤傳遞給awk的變量。awk grep最近30天內的關鍵字日誌
home # lastDate=$(date -d "last month" 2>&1 {$1, $2, $3}) | cat /var/log/messages | zcat /var/log/messages-* | awk '$0>=from&&$0<=to' from='{ print date +"%m-%d"}' to=$lastDate '{print to}' | grep -i reject
awk: fatal: cannot open file `{print to}' for reading (No such file or directory)
其中朗聲道:
lastDate=$(date -d "last month" 2>&1 {$1, $2, $3})|awk '{print lastDate}'
no error, no output
日期-D 「上個月」 週五7月26日七時十三分四十秒UTC 2013
的lastDate命令也不行。您需要從日期命令中選擇哪些字段? – Raghuram
你認爲這個命令應該做什麼? 'date -d「上個月」2>&1 {$ 1,$ 2,$ 3}' – anubhava
您的命令行毫無意義,它只是僞shell和僞awk代碼的隨機片段。告訴我們你想要做什麼,並提供一些示例輸入和預期輸出。 –