have logrotate files handle acct absence
Marc Haber
3 years ago
47 | 47 | 4. |
48 | 48 | --- a/psaccs_atop |
49 | 49 | +++ b/psaccs_atop |
50 | @@ -10,11 +10,18 @@ | |
50 | @@ -10,11 +10,12 @@ | |
51 | 51 | postrotate |
52 | 52 | # check if process accounting is installed |
53 | 53 | # |
54 | 54 | - if [ -e /etc/logrotate.d/psacct ] |
55 | + if [ -e /etc/logrotate.d/psacct ] || grep -q 'savelog' /etc/cron.daily/acct | |
56 | then | |
55 | - then | |
56 | + if grep -q 'savelog' /etc/cron.daily/acct 2>/dev/null; then | |
57 | 57 | # check if process accounting is actually in use |
58 | 58 | # |
59 | 59 | - ACCTFILE=`awk '$2 == "{" {print $1}' /etc/logrotate.d/psacct` |
60 | + if [ -e /etc/logrotate.d/psacct ] | |
61 | + then | |
62 | + ACCTFILE=`awk '$2 == "{" {print $1}' /etc/logrotate.d/psacct` | |
63 | + fi | |
64 | + if grep -q 'savelog' /etc/cron.daily/acct | |
65 | + then | |
66 | + ACCTFILE=`sed -n "/savelog[^\/]\+\(\/[[:alnum:]\/]\+\).*/{s//\1/;p;q;}" /etc/cron.daily/acct` | |
67 | + fi | |
60 | + # this is a heuristic that will fail once acct's cron.daily job changes | |
61 | + # please file a bug report against atop if you encounter this | |
62 | + ACCTFILE=$(sed -n "/savelog[^\/]\+\(\/[[:alnum:]\/]\+\).*/{s//\1/;p;q;}" /etc/cron.daily/acct) | |
68 | 63 | |
69 | 64 | if [ -f "$ACCTFILE" ] |
70 | 65 | then |
75 | 70 | create 0600 root root |
76 | 71 | postrotate |
77 | 72 | - if [ -e /etc/logrotate.d/psacct ] |
78 | + if [ -e /etc/logrotate.d/psacct ] || grep -q 'savelog.*/var/log/account/pacct' /etc/cron.daily/acct | |
73 | + if grep -q 'savelog.*/var/log/account/pacct' /etc/cron.daily/acct 2>/dev/null | |
79 | 74 | then |
80 | 75 | # if the atop daemon does not run, restart it after |
81 | 76 | # accounting file is rotated |