แสดงบทความที่มีป้ายกำกับ awk แสดงบทความทั้งหมด
แสดงบทความที่มีป้ายกำกับ awk แสดงบทความทั้งหมด

วันศุกร์ที่ 20 กุมภาพันธ์ พ.ศ. 2558

awk print error from Apache error logs



Apache log can contain several line of error. Counting the occurrence of each error is a good way to start.

Apache log separate field with "[ ]". Using sort for sorting error and uniq with -c option to count the number of occurrence.

Here to list all in error regardless of warning or error :
awk -F'[\[\]]+' '{print $7}' error.log | sort | uniq -c | sort -nr

To filter for error add the logic to awk :

awk -F'[\[\]]+' '$4 == "error"{print $7}' error.log | sort | uniq -c | sort -nr

From http://sudarmuthu.com/blog/how-to-print-unique-errorswith-count-from-apache-error-logs/

วันพฤหัสบดีที่ 12 มกราคม พ.ศ. 2555

awk basic

awk is very useful tool for linux user.
For example, you have output from ps aux like this :

#ps aux 

root      2213  0.0  0.4   6596  2428 pts/2    S    12:08   0:00 bash
root      2235  0.0  0.1   4848   952 pts/2    S+   12:08   0:00 /bin/bash xxx
root      2236  0.0  0.6   7132  3236 pts/2    S+   12:08   0:04 ssh xxx

The second column is PID, and 8th is process state.
To find the zombie process you just execute the following command  :

# ps aux | awk '{ print $8 " " $2 }' | grep -w Z


See just use $th of the column, you will get the value of that column. Also, you can apply even you have comma separated field with -F option.

For more usage of this command please consult
#man awk

:)