четверг, 14 мая 2015 г.

Using cat, tail, head and mailmgr for generating quarterly reports of sendmail logs

0) I know that big log file begins from Jan 1 2014 and ends till May 14 2015.

Date of first line:
head -n1 ./maillog_k
Jan  1 00:00:01

Date of last line:
tail -n1 ./maillog_k
May 14 04:15:02

Newlines, words, bytes:

# wc ./maillog_k
  3891438  64840971 834912647 ./maillog_k

# cat /etc/asplinux-release
ASPLinux release 11.2 (Ladoga)

mailmgr-1.2.3


1) First quarter 2014:

# cat -n ./maillog_k | grep 'Apr  1' | head -1
616119  Apr  1 00:00:01

# head -616118 ./maillog_k > ./maillog_k_14_1


2) Second quarter 2014:

3891438 - 616118 = 3275320

# tail -3275320 ./maillog_k > ./maillog_k2

# cat -n ./maillog_k2 | grep 'Jul  1' | head -1
614176  Jul  1 00:00:00

# head -614175 ./maillog_k2 > ./maillog_k_14_2


3) Third quarter 2014:

3275320 - 614175 = 2661145

# tail -2661145 ./maillog_k2 > ./maillog_k3

# cat -n ./maillog_k3 | grep 'Oct  1' | head -1
664906  Oct  1 00:00:01

# head -664905 ./maillog_k3 > ./maillog_k_14_3


4) Fourth quarter 2014:

2661145 - 664905 = 1996240

# tail -1996240 ./maillog_k3 > ./maillog_k4

# cat -n ./maillog_k4 | grep 'Jan  1' | head -1
799719  Jan  1 00:00:01

# head -799718 ./maillog_k4 > ./maillog_k_14_4


5) First quarter 2015:

1996240 - 799718 = 1196522

# tail -1196522 ./maillog_k4 > ./maillog_k5

# cat -n ./maillog_k5 | grep 'Apr  1' | head -1
846789  Apr  1 00:00:01

# head -846788 ./maillog_k5 > ./maillog_k_15_1


6) Leave unanalyzed data:

1196522 - 846788 = 349734

# tail -349734 ./maillog_k5 > ./maillog_k


7) I have finally:

# ls -l ./maillog_k*
-rw-r--r--  1 root root  74732033 Май 14 15:45 ./maillog_k
-rw-r--r--  1 root root 137903559 Май 14 14:57 ./maillog_k_14_1
-rw-r--r--  1 root root 134171566 Май 14 15:15 ./maillog_k_14_2
-rw-r--r--  1 root root 142580534 Май 14 15:20 ./maillog_k_14_3
-rw-r--r--  1 root root 169452305 Май 14 15:40 ./maillog_k_14_4
-rw-r--r--  1 root root 176072650 Май 14 15:44 ./maillog_k_15_1
-rw-r--r--  1 root root 697009088 Май 14 15:01 ./maillog_k2
-rw-r--r--  1 root root 562837522 Май 14 15:18 ./maillog_k3
-rw-r--r--  1 root root 420256988 Май 14 15:39 ./maillog_k4
-rw-r--r--  1 root root 250804683 Май 14 15:42 ./maillog_k5


8) Generate reports for 2014 year:

# /usr/bin/mailmgr -l ./maillog_k_14_1 -o /var/www/stat/1/rep_mail_k
MAILMGR: Successfull report generated on /var/www/stat/1/rep_mail_k
# /usr/bin/mailmgr -l ./maillog_k_14_2 -o /var/www/stat/1/rep_mail_k
MAILMGR: Successfull report generated on /var/www/stat/1/rep_mail_k
# /usr/bin/mailmgr -l ./maillog_k_14_3 -o /var/www/stat/1/rep_mail_k
MAILMGR: Successfull report generated on /var/www/stat/1/rep_mail_k
# /usr/bin/mailmgr -l ./maillog_k_14_4 -o /var/www/stat/1/rep_mail_k
MAILMGR: Successfull report generated on /var/www/stat/1/rep_mail_k

After that move all reports to archive from /var/www/stat/1/rep_mail_k and delete maillog_k*.


9) Generate first report of 2015 year:

# /usr/bin/mailmgr -l ./maillog_k_15_1 -o /var/www/stat/1/rep_mail_k
MAILMGR: Successfull report generated on /var/www/stat/1/rep_mail_k

Комментариев нет:

Отправить комментарий