Shell Statistics Log Information
In general applications, log information is logged using log4j and a log file is generated daily, with each file ending on the date of the day.
How do I count and analyze these log messages?
In the simplest cases, use shell scripts for statistical analysis:
The following script counts and lists the number of rows of log files for the last week and compares them to last week's.
You can export the parsed information to a specific file, send the file to a message, or display it to the Web service.
dateecho "========================================================" echo "======== date ======== Week volume ====== = = Last week volume ===== this week-last week = = "for i in {1..7}do ddate=$ (date +%y-%m-%d-%w --date="-$i day ") xdate=$ (date +%y-%m-%d --date="-$i day ") ydate=$ (date +% Y-%m-%d --date= "-$[i+7] day") x=$ (cat "Receive-sms.log. $xdate" | wc - L) y=$ (cat "Receive-sms.log. $ydate" | wc -l) echo " $ddate | $x | $y |   $[X-Y] " xtotal=$[xtotal+x] ytotal=$[ytotal+y] echo " -----------------------------------------------------"doneecho " total value | $xtotal | $ytotal | $[ Total-ytotal] "Echo&nbsP; " -----------------------------------------------------"echo " average value | $[xtotal/7] | $[ytotal/7] |   $[XTOTAL/7-YTOTAL/7] "echo " ========================================================= "
output result:
2015 11 month 18 day Wednesday 17:27:00 cst======================================================= ====== Date ======== Week volume ======== last week volume ===== this week-last week ===2015-11-17-2 | 19597 | 16325 | 3272--------------------------------------- ----------------2015-11-16-1 | 18615 | 15851 | 2764------------------------------------------------------- 2015-11-15-0 | 10623 | 9058 | 1565-------------------------------------------------------2015-11-14-6 | 12215 | 10985 | 1230-------------------------------------------------------2015-11-13-5 | 16268 | 16331 | -63------------------------------------------------------ -2015-11-12-4 | 16864 | 37047 | -20183-------------------------------------------------------2015-11-11-3 | 15066 | 40440 | - 25374-------------------------------------------------------total value | 109248 | 146037 | -146037----------------------------- --------------------------average value | 15606 | 20862 | -5256=======================================================
Shell Statistics Log Information