0

We have Linux Red Hat servers - version 7.2. We have the following Hive logs under /var/log/hive.

How can we configure the Linux logrotate so every log file that's older than one month will be deleted:

-rw-r--r--  1 hive hadoop    2427759 May  7 23:57 hiveserver2.log.2018-05-07
-rw-r--r--  1 hive hadoop    2428734 May  8 23:58 hiveserver2.log.2018-05-08
-rw-r--r--  1 hive hadoop    2428044 May  9 23:59 hiveserver2.log.2018-05-09
-rw-r--r--  1 hive hadoop    2427299 May 10 23:57 hiveserver2.log.2018-05-10
-rw-r--r--  1 hive hadoop    2428044 May 11 23:59 hiveserver2.log.2018-05-11
-rw-r--r--  1 hive hadoop    2427299 May 12 23:57 hiveserver2.log.2018-05-12
-rw-r--r--  1 hive hadoop    2407579 May 13 23:57 hiveserver2.log.2018-05-13
-rw-r--r--  1 hive hadoop    2427773 May 14 23:57 hiveserver2.log.2018-05-14
-rw-r--r--  1 hive hadoop    2428315 May 15 23:59 hiveserver2.log.2018-05-15
-rw-r--r--  1 hive hadoop    2427299 May 16 23:57 hiveserver2.log.2018-05-16
-rw-r--r--  1 hive hadoop    2428044 May 17 23:58 hiveserver2.log.2018-05-17
-rw-r--r--  1 hive hadoop    2427299 May 18 23:57 hiveserver2.log.2018-05-18
-rw-r--r--  1 hive hadoop    2428044 May 19 23:58 hiveserver2.log.2018-05-19
-rw-r--r--  1 hive hadoop    2427299 May 20 23:57 hiveserver2.log.2018-05-20
-rw-r--r--  1 hive hadoop    2428044 May 21 23:58 hiveserver2.log.2018-05-21
-rw-r--r--  1 hive hadoop    2427611 May 22 23:57 hiveserver2.log.2018-05-22
-rw-r--r--  1 hive hadoop    2428524 May 23 23:57 hiveserver2.log.2018-05-23
-rw-r--r--  1 hive hadoop    2427779 May 24 23:57 hiveserver2.log.2018-05-24
-rw-r--r--  1 hive hadoop    2428524 May 25 23:57 hiveserver2.log.2018-05-25
-rw-r--r--  1 hive hadoop    2427779 May 26 23:57 hiveserver2.log.2018-05-26
-rw-r--r--  1 hive hadoop    2423593 May 27 23:58 hiveserver2.log.2018-05-27
-rw-r--r--  1 hive hadoop    2427779 May 28 23:57 hiveserver2.log.2018-05-28
-rw-r--r--  1 hive hadoop    2428524 May 29 23:58 hiveserver2.log.2018-05-29
-rw-r--r--  1 hive hadoop    2427779 May 30 23:57 hiveserver2.log.2018-05-30
-rw-r--r--  1 hive hadoop    2418662 May 31 23:57 hiveserver2.log.2018-05-31
-rw-r--r--  1 hive hadoop    2428050 Jun  1 23:59 hiveserver2.log.2018-06-01
-rw-r--r--  1 hive hadoop    2428253 Jun  2 23:57 hiveserver2.log.2018-06-02
-rw-r--r--  1 hive hadoop    2428050 Jun  3 23:57 hiveserver2.log.2018-06-03
-rw-r--r--  1 hive hadoop    2428524 Jun  4 23:57 hiveserver2.log.2018-06-04
-rw-r--r--  1 hive hadoop    2428280 Jun  5 23:57 hiveserver2.log.2018-06-05
-rw-r--r--  1 hive hadoop    2403598 Jun  6 23:57 hiveserver2.log.2018-06-06
-rw-r--r--  1 hive hadoop    2428050 Jun  7 23:57 hiveserver2.log.2018-06-07
-rw-r--r--  1 hive hadoop    2428524 Jun  8 23:59 hiveserver2.log.2018-06-08
-rw-r--r--  1 hive hadoop    2428524 Jun  9 23:59 hiveserver2.log.2018-06-09
-rw-r--r--  1 hive hadoop    2427779 Jun 10 23:57 hiveserver2.log.2018-06-10
-rw-r--r--  1 hive hadoop    2428524 Jun 11 23:57 hiveserver2.log.2018-06-11
-rw-r--r--  1 hive hadoop    2428050 Jun 12 23:58 hiveserver2.log.2018-06-12
-rw-r--r--  1 hive hadoop    2428524 Jun 13 23:57 hiveserver2.log.2018-06-13
-rw-r--r--  1 hive hadoop    3071577 Jun 14 23:57 hiveserver2.log.2018-06-14
-rw-r--r--  1 hive hadoop    2428253 Jun 15 23:57 hiveserver2.log.2018-06-15
-rw-r--r--  1 hive hadoop    2428321 Jun 16 23:58 hiveserver2.log.2018-06-16
-rw-r--r--  1 hive hadoop    2423593 Jun 17 23:57 hiveserver2.log.2018-06-17
-rw-r--r--  1 hive hadoop    2417917 Jun 18 23:57 hiveserver2.log.2018-06-18
-rw-r--r--  1 hive hadoop    2426466 Jun 19 23:57 hiveserver2.log.2018-06-19
-rw-r--r--  1 hive hadoop    2428524 Jun 20 23:57 hiveserver2.log.2018-06-20
-rw-r--r--  1 hive hadoop    8886204 Jun 21 23:59 hiveserver2.log.2018-06-21
-rw-r--r--  1 hive hadoop   16072582 Jun 22 23:59 hiveserver2.log.2018-06-22
-rw-r--r--  1 hive hadoop   16050344 Jun 23 23:59 hiveserver2.log.2018-06-23
-rw-r--r--  1 hive hadoop    7206583 Jun 24 23:58 hiveserver2.log.2018-06-24
-rw-r--r--  1 hive hadoop    4091983 Jun 24 23:59 hivemetastore.log.2018-06-24
-rw-r--r--  1 hive hadoop    2428754 Jun 25 23:58 hiveserver2.log.2018-06-25
-rw-r--r--  1 hive hadoop    5207183 Jun 25 23:58 hivemetastore.log.2018-06-25
-rw-r--r--  1 hive hadoop    2452573 Jun 26 23:58 hiveserver2.log.2018-06-26
-rw-r--r--  1 hive hadoop    1593985 Jun 26 23:58 hivemetastore.log.2018-06-26
-rw-r--r--  1 hive hadoop    2649871 Jun 27 23:58 hiveserver2.log.2018-06-27
-rw-r--r--  1 hive hadoop    1252899 Jun 27 23:58 hivemetastore.log.2018-06-27
-rw-r--r--  1 hive hadoop    4056832 Jun 28 23:58 hiveserver2.log.2018-06-28
-rw-r--r--  1 hive hadoop    1239494 Jun 28 23:58 hivemetastore.log.2018-06-28
-rw-r--r--  1 hive hadoop    2457595 Jun 29 23:58 hiveserver2.log.2018-06-29
-rw-r--r--  1 hive hadoop    1190070 Jun 29 23:58 hivemetastore.log.2018-06-29
-rw-r--r--  1 hive hadoop    2456850 Jun 30 23:58 hiveserver2.log.2018-06-30
-rw-r--r--  1 hive hadoop    1190164 Jun 30 23:58 hivemetastore.log.2018-06-30
-rw-r--r--  1 hive hadoop    2618713 Jul  1 23:58 hiveserver2.log.2018-07-01
-rw-r--r--  1 hive hadoop    1764492 Jul  1 23:58 hivemetastore.log.2018-07-01
-rw-r--r--  1 hive hadoop    2428524 Jul  2 23:58 hiveserver2.log.2018-07-02
-rw-r--r--  1 hive hadoop    1189251 Jul  2 23:58 hivemetastore.log.2018-07-02
-rw-r--r--  1 hive hadoop    2428050 Jul  3 23:58 hiveserver2.log.2018-07-03
-rw-r--r--  1 hive hadoop    1377416 Jul  3 23:58 hivemetastore.log.2018-07-03
-rw-r--r--  1 hive hadoop    2530639 Jul  4 23:58 hiveserver2.log.2018-07-04
-rw-r--r--  1 hive hadoop    1278000 Jul  4 23:58 hivemetastore.log.2018-07-04
-rw-r--r--  1 hive hadoop    2428984 Jul  5 23:58 hiveserver2.log.2018-07-05
-rw-r--r--  1 hive hadoop    1197379 Jul  5 23:58 hivemetastore.log.2018-07-05
-rw-r--r--  1 hive hadoop    2428050 Jul  6 23:58 hiveserver2.log.2018-07-06
-rw-r--r--  1 hive hadoop    1189221 Jul  6 23:58 hivemetastore.log.2018-07-06
-rw-r--r--  1 hive hadoop    3027808 Jul  7 23:58 hiveserver2.log.2018-07-07
-rw-r--r--  1 hive hadoop    1186460 Jul  7 23:58 hivemetastore.log.2018-07-07
-rw-r--r--  1 hive hadoop    1313786 Jul  8 23:58 hivemetastore.log.2018-07-08
-rw-r--r--  1 hive hadoop    8491552 Jul  8 23:59 hiveserver2.log.2018-07-08
-rw-r--r--  1 hive hadoop     418648 Jul  9 23:58 hivemetastore.log.2018-07-09
-rw-r--r--  1 hive hadoop   13521450 Jul  9 23:59 hiveserver2.log.2018-07-09
-rw-r--r--  1 hive hadoop     403619 Jul 10 23:58 hivemetastore.log.2018-07-10
-rw-r--r--  1 hive hadoop    9516982 Jul 10 23:59 hiveserver2.log.2018-07-10
-rw-r--r--  1 hive hadoop     403650 Jul 11 23:58 hivemetastore.log.2018-07-11
-rw-r--r--  1 hive hadoop    9588437 Jul 11 23:59 hiveserver2.log.2018-07-11
-rw-r--r--  1 hive hadoop     403890 Jul 12 23:58 hivemetastore.log.2018-07-12
-rw-r--r--  1 hive hadoop    9636082 Jul 12 23:59 hiveserver2.log.2018-07-12
-rw-r--r--  1 hive hadoop     404364 Jul 13 23:58 hivemetastore.log.2018-07-13
-rw-r--r--  1 hive hadoop    9578278 Jul 13 23:59 hiveserver2.log.2018-07-13
-rw-r--r--  1 hive hadoop     403890 Jul 14 23:58 hivemetastore.log.2018-07-14
-rw-r--r--  1 hive hadoop    9505343 Jul 14 23:59 hiveserver2.log.2018-07-14
-rw-r--r--  1 hive hadoop     404093 Jul 15 23:58 hivemetastore.log.2018-07-15
-rw-r--r--  1 hive hadoop    9588093 Jul 15 23:59 hiveserver2.log.2018-07-15
-rw-r--r--  1 hive hadoop    5146008 Jul 16 23:58 hiveserver2.log.2018-07-16
-rw-r--r--  1 hive hadoop     968828 Jul 16 23:58 hivemetastore.log.2018-07-16
-rw-r--r--  1 hive hadoop    2470754 Jul 17 23:58 hiveserver2.log.2018-07-17
-rw-r--r--  1 hive hadoop    1276013 Jul 17 23:58 hivemetastore.log.2018-07-17
-rw-r--r--  1 hive hadoop    2428524 Jul 18 23:58 hiveserver2.log.2018-07-18
-rw-r--r--  1 hive hadoop    1392995 Jul 18 23:58 hivemetastore.log.2018-07-18
-rw-r--r--  1 hive hadoop    2542335 Jul 19 23:58 hiveserver2.log.2018-07-19
-rw-r--r--  1 hive hadoop    1589517 Jul 19 23:58 hivemetastore.log.2018-07-19
-rw-r--r--  1 hive hadoop    2468078 Jul 20 23:58 hiveserver2.log.2018-07-20
-rw-r--r--  1 hive hadoop    1390898 Jul 20 23:58 hivemetastore.log.2018-07-20
-rw-r--r--  1 hive hadoop    2467848 Jul 21 23:58 hiveserver2.log.2018-07-21
-rw-r--r--  1 hive hadoop    1223634 Jul 21 23:58 hivemetastore.log.2018-07-21
-rw-r--r--  1 hive hadoop    2553161 Jul 22 23:58 hiveserver2.log.2018-07-22
-rw-r--r--  1 hive hadoop    1495781 Jul 22 23:58 hivemetastore.log.2018-07-22
-rw-r--r--  1 hive hadoop    2466780 Jul 23 23:58 hiveserver2.log.2018-07-23
-rw-r--r--  1 hive hadoop    1439100 Jul 23 23:58 hivemetastore.log.2018-07-23
-rw-r--r--  1 hive hadoop    2467047 Jul 24 23:58 hiveserver2.log.2018-07-24
-rw-r--r--  1 hive hadoop    1439367 Jul 24 23:58 hivemetastore.log.2018-07-24
-rw-r--r--  1 hive hadoop    2452448 Jul 25 23:58 hiveserver2.log.2018-07-25
-rw-r--r--  1 hive hadoop    1433751 Jul 25 23:58 hivemetastore.log.2018-07-25
-rw-r--r--  1 hive hadoop    2466780 Jul 26 23:58 hiveserver2.log.2018-07-26
-rw-r--r--  1 hive hadoop    1456257 Jul 26 23:58 hivemetastore.log.2018-07-26
-rw-r--r--  1 hive hadoop    2466780 Jul 27 23:58 hiveserver2.log.2018-07-27
-rw-r--r--  1 hive hadoop    1439367 Jul 27 23:58 hivemetastore.log.2018-07-27
-rw-r--r--  1 hive hadoop    2466780 Jul 28 23:58 hiveserver2.log.2018-07-28
-rw-r--r--  1 hive hadoop    1439634 Jul 28 23:58 hivemetastore.log.2018-07-28
-rw-r--r--  1 hive hadoop    2653774 Jul 29 23:58 hiveserver2.log.2018-07-29
-rw-r--r--  1 hive hadoop    1623419 Jul 29 23:58 hivemetastore.log.2018-07-29
-rw-r--r--  1 hive hadoop    2701943 Jul 30 23:58 hiveserver2.log.2018-07-30
-rw-r--r--  1 hive hadoop    1448742 Jul 30 23:58 hivemetastore.log.2018-07-30
-rw-r--r--  1 hive hadoop    2701713 Jul 31 23:58 hiveserver2.log.2018-07-31
-rw-r--r--  1 hive hadoop    1474521 Jul 31 23:58 hivemetastore.log.2018-07-31
-rw-r--r--. 1 hive hadoop         31 Aug  1 16:14 hive.out
-rw-r--r--. 1 hive hadoop         83 Aug  1 16:14 hive.err
-rw-r--r--. 1 hive hadoop          0 Aug  1 16:15 hive-server2.out
-rw-r--r--. 1 hive hadoop         83 Aug  1 16:15 hive-server2.err
-rw-r--r--  1 hive hadoop    2131837 Aug  1 16:34 hiveserver2.log
-rw-r--r--  1 hive hadoop    1093248 Aug  1 16:34 hivemetastore.log
-rw-r--r--  1 hive hadoop       4346 Aug  1 16:36 hivemetastore-report.json.tmp
-rw-r--r--  1 hive hadoop       4438 Aug  1 16:36 hiveserver2-report.json.tmp

Expected results:

-rw-r--r--  1 hive hadoop    2618713 Jul  1 23:58 hiveserver2.log.2018-07-01
-rw-r--r--  1 hive hadoop    1764492 Jul  1 23:58 hivemetastore.log.2018-07-01
-rw-r--r--  1 hive hadoop    2428524 Jul  2 23:58 hiveserver2.log.2018-07-02
-rw-r--r--  1 hive hadoop    1189251 Jul  2 23:58 hivemetastore.log.2018-07-02
-rw-r--r--  1 hive hadoop    2428050 Jul  3 23:58 hiveserver2.log.2018-07-03
-rw-r--r--  1 hive hadoop    1377416 Jul  3 23:58 hivemetastore.log.2018-07-03
-rw-r--r--  1 hive hadoop    2530639 Jul  4 23:58 hiveserver2.log.2018-07-04
-rw-r--r--  1 hive hadoop    1278000 Jul  4 23:58 hivemetastore.log.2018-07-04
-rw-r--r--  1 hive hadoop    2428984 Jul  5 23:58 hiveserver2.log.2018-07-05
-rw-r--r--  1 hive hadoop    1197379 Jul  5 23:58 hivemetastore.log.2018-07-05
-rw-r--r--  1 hive hadoop    2428050 Jul  6 23:58 hiveserver2.log.2018-07-06
-rw-r--r--  1 hive hadoop    1189221 Jul  6 23:58 hivemetastore.log.2018-07-06
-rw-r--r--  1 hive hadoop    3027808 Jul  7 23:58 hiveserver2.log.2018-07-07
-rw-r--r--  1 hive hadoop    1186460 Jul  7 23:58 hivemetastore.log.2018-07-07
-rw-r--r--  1 hive hadoop    1313786 Jul  8 23:58 hivemetastore.log.2018-07-08
-rw-r--r--  1 hive hadoop    8491552 Jul  8 23:59 hiveserver2.log.2018-07-08
-rw-r--r--  1 hive hadoop     418648 Jul  9 23:58 hivemetastore.log.2018-07-09
-rw-r--r--  1 hive hadoop   13521450 Jul  9 23:59 hiveserver2.log.2018-07-09
-rw-r--r--  1 hive hadoop     403619 Jul 10 23:58 hivemetastore.log.2018-07-10
-rw-r--r--  1 hive hadoop    9516982 Jul 10 23:59 hiveserver2.log.2018-07-10
-rw-r--r--  1 hive hadoop     403650 Jul 11 23:58 hivemetastore.log.2018-07-11
-rw-r--r--  1 hive hadoop    9588437 Jul 11 23:59 hiveserver2.log.2018-07-11
-rw-r--r--  1 hive hadoop     403890 Jul 12 23:58 hivemetastore.log.2018-07-12
-rw-r--r--  1 hive hadoop    9636082 Jul 12 23:59 hiveserver2.log.2018-07-12
-rw-r--r--  1 hive hadoop     404364 Jul 13 23:58 hivemetastore.log.2018-07-13
-rw-r--r--  1 hive hadoop    9578278 Jul 13 23:59 hiveserver2.log.2018-07-13
-rw-r--r--  1 hive hadoop     403890 Jul 14 23:58 hivemetastore.log.2018-07-14
-rw-r--r--  1 hive hadoop    9505343 Jul 14 23:59 hiveserver2.log.2018-07-14
-rw-r--r--  1 hive hadoop     404093 Jul 15 23:58 hivemetastore.log.2018-07-15
-rw-r--r--  1 hive hadoop    9588093 Jul 15 23:59 hiveserver2.log.2018-07-15
-rw-r--r--  1 hive hadoop    5146008 Jul 16 23:58 hiveserver2.log.2018-07-16
-rw-r--r--  1 hive hadoop     968828 Jul 16 23:58 hivemetastore.log.2018-07-16
-rw-r--r--  1 hive hadoop    2470754 Jul 17 23:58 hiveserver2.log.2018-07-17
-rw-r--r--  1 hive hadoop    1276013 Jul 17 23:58 hivemetastore.log.2018-07-17
-rw-r--r--  1 hive hadoop    2428524 Jul 18 23:58 hiveserver2.log.2018-07-18
-rw-r--r--  1 hive hadoop    1392995 Jul 18 23:58 hivemetastore.log.2018-07-18
-rw-r--r--  1 hive hadoop    2542335 Jul 19 23:58 hiveserver2.log.2018-07-19
-rw-r--r--  1 hive hadoop    1589517 Jul 19 23:58 hivemetastore.log.2018-07-19
-rw-r--r--  1 hive hadoop    2468078 Jul 20 23:58 hiveserver2.log.2018-07-20
-rw-r--r--  1 hive hadoop    1390898 Jul 20 23:58 hivemetastore.log.2018-07-20
-rw-r--r--  1 hive hadoop    2467848 Jul 21 23:58 hiveserver2.log.2018-07-21
-rw-r--r--  1 hive hadoop    1223634 Jul 21 23:58 hivemetastore.log.2018-07-21
-rw-r--r--  1 hive hadoop    2553161 Jul 22 23:58 hiveserver2.log.2018-07-22
-rw-r--r--  1 hive hadoop    1495781 Jul 22 23:58 hivemetastore.log.2018-07-22
-rw-r--r--  1 hive hadoop    2466780 Jul 23 23:58 hiveserver2.log.2018-07-23
-rw-r--r--  1 hive hadoop    1439100 Jul 23 23:58 hivemetastore.log.2018-07-23
-rw-r--r--  1 hive hadoop    2467047 Jul 24 23:58 hiveserver2.log.2018-07-24
-rw-r--r--  1 hive hadoop    1439367 Jul 24 23:58 hivemetastore.log.2018-07-24
-rw-r--r--  1 hive hadoop    2452448 Jul 25 23:58 hiveserver2.log.2018-07-25
-rw-r--r--  1 hive hadoop    1433751 Jul 25 23:58 hivemetastore.log.2018-07-25
-rw-r--r--  1 hive hadoop    2466780 Jul 26 23:58 hiveserver2.log.2018-07-26
-rw-r--r--  1 hive hadoop    1456257 Jul 26 23:58 hivemetastore.log.2018-07-26
-rw-r--r--  1 hive hadoop    2466780 Jul 27 23:58 hiveserver2.log.2018-07-27
-rw-r--r--  1 hive hadoop    1439367 Jul 27 23:58 hivemetastore.log.2018-07-27
-rw-r--r--  1 hive hadoop    2466780 Jul 28 23:58 hiveserver2.log.2018-07-28
-rw-r--r--  1 hive hadoop    1439634 Jul 28 23:58 hivemetastore.log.2018-07-28
-rw-r--r--  1 hive hadoop    2653774 Jul 29 23:58 hiveserver2.log.2018-07-29
-rw-r--r--  1 hive hadoop    1623419 Jul 29 23:58 hivemetastore.log.2018-07-29
-rw-r--r--  1 hive hadoop    2701943 Jul 30 23:58 hiveserver2.log.2018-07-30
-rw-r--r--  1 hive hadoop    1448742 Jul 30 23:58 hivemetastore.log.2018-07-30
-rw-r--r--  1 hive hadoop    2701713 Jul 31 23:58 hiveserver2.log.2018-07-31
-rw-r--r--  1 hive hadoop    1474521 Jul 31 23:58 hivemetastore.log.2018-07-31
-rw-r--r--. 1 hive hadoop         31 Aug  1 16:14 hive.out
-rw-r--r--. 1 hive hadoop         83 Aug  1 16:14 hive.err
-rw-r--r--. 1 hive hadoop          0 Aug  1 16:15 hive-server2.out
-rw-r--r--. 1 hive hadoop         83 Aug  1 16:15 hive-server2.err
-rw-r--r--  1 hive hadoop    2131837 Aug  1 16:34 hiveserver2.log
-rw-r--r--  1 hive hadoop    1093248 Aug  1 16:34 hivemetastore.log
-rw-r--r--  1 hive hadoop       4346 Aug  1 16:36 hivemetastore-report.json.tmp
-rw-r--r--  1 hive hadoop       4438 Aug  1 16:36 hiveserver2-report.json.tmp

what I did up until now is this:

$ vi /etc/logrotate.conf

and I add this configuration:

/var/log/hive {
    maxage 30
}

and run this:

$ logrotate /etc/logrotate.conf

to take affect. But this isn't working?

I also set it as

vi  /etc/logrotate.d/hive
/var/log/hive {

postrotate
        /usr/bin/find /var/log/hive -name "hive.log.*" -type f -mtime +21 -exec rm {} \;
endscript
}

but this approach not remove the files that older then 21 day

also this

/var/log/hive/*.log* {

postrotate
        /usr/bin/find /var/log/hive -name "*.log.*" -type f -mtime +21 -exec rm {} \;
endscript
}
0

The pattern on your logrotate will never match any of the timestamp named files. You need to change it to match.

Try this:

/var/log/hive/*.log* {
    maxage 30
}

Look at other examples

Look at how the other logrotate configuration files work:

$ grep 'var/log' /etc/logrotate.d/* | head
/etc/logrotate.d/aide:/var/log/aide/*.log {
/etc/logrotate.d/bootlog:/var/log/boot.log
/etc/logrotate.d/chrony:/var/log/chrony/*.log {
/etc/logrotate.d/cups:/var/log/cups/*_log {
/etc/logrotate.d/glusterfs:/var/log/glusterfs/*.log {
/etc/logrotate.d/glusterfs:/var/log/glusterfs/bricks/*.log {
/etc/logrotate.d/glusterfs:/var/log/glusterfs/samples/*.samp {
/etc/logrotate.d/iscsiuiolog:/var/log/iscsiuio.log {
/etc/logrotate.d/libvirtd:/var/log/libvirt/libvirtd.log {
/etc/logrotate.d/libvirtd.qemu:/var/log/libvirt/qemu/*.log {

postrotate

The other bit about this that bothers me is that you're trying to use logrotate to rotate some other server's log files which it's already got a log4j type of file rotating. That's typically a recipe for disaster.

For example you're dealing with Hive which is part of Hadoop. All the Hadoop services have their own log4j.properties files like this:

$ grep Back /etc/hadoop/conf/log4j.properties
#log4j.appender.DRFA.MaxBackupIndex=30
log4j.appender.RFAS.MaxBackupIndex=${hadoop.security.log.maxbackupindex}
log4j.appender.NNMETRICSRFA.MaxBackupIndex=1
log4j.appender.RFA.MaxBackupIndex=10
log4j.appender.RMSUMMARY.MaxBackupIndex=20

In those cases I resort to doing the "clean up" like this:

/var/log/hive/* {
  ifempty
  size 0

postrotate
            /usr/bin/find /var/log/hive -name "*log*" -type f -mtime +29 -exec rm -f {} \;

endscript
}

Doing it in this manner allows for the use of the find command on whatever days rule you want to use.

Testing

To verify this I used the following techniques.

sample data
$ for i in {01..31};do touch -t 07${i}1200 /var/log/hive/file${i}.log;done
test run
$ logrotate -v /etc/logrotate.d/hive |& tail -10
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
renaming /var/log/hive/file31.log.1 to /var/log/hive/file31.log.2 (rotatecount 1, logstart 1, i 1),
old log /var/log/hive/file31.log.1 does not exist
renaming /var/log/hive/file31.log.0 to /var/log/hive/file31.log.1 (rotatecount 1, logstart 1, i 0),
old log /var/log/hive/file31.log.0 does not exist
log /var/log/hive/file31.log.2 doesn't exist -- won't try to dispose of it
renaming /var/log/hive/file31.log to /var/log/hive/file31.log.1
disposeName will be /var/log/hive/file31.log.1
running postrotate script
removing old log /var/log/hive/file31.log.1

NOTE: It's safe to remove this ifempty & this size 0, I added these merely to work with my fake data.

  • @yael - using it can lead to issues with log4j. If you manipulate files from under log4j, it will no longer rotate files it manages. This can lead to problems with HDD filling up, is one ex. – slm Aug 1 '18 at 19:29
  • what you think about the other option just to create cron job as /etc/cron.d/test , and test include /usr/bin/find /var/log/hive -name "log" -type f -mtime +29 -exec rm -f {} \; , so it will do the job also , what you think – yael Aug 1 '18 at 19:42
  • @yael - I need the size 0 to force it to do my fake touched files. – slm Aug 1 '18 at 19:48
  • so in my case I can not use the "ifempty" and"size 0" ? second what you think about the cron job ? its more simple and do the same job – yael Aug 1 '18 at 19:52
  • @yael - I'd do this w/ the cron as well. – slm Aug 1 '18 at 20:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.