Shell Statistics Log Information

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.