Logs not rotated


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Logs not rotated
# 1  
Old 12-12-2018
Logs not rotated

I'm fairly new to this...

System: Kali Linux - based on Debian (Stretch)
uname -a : Linux kali 4.18.0-kali3-amd64 #1 SMP Debian 4.18.20-2kali2 (2018-11-30) x86_64 GNU/Linux

I noticed that the space on my root partition was continuously shrinking even though I didn't do much on the machine and it wasn't even running continuously. Then I tested a script with a lot of calls to sudo in it and noticed that var/log/auth.log was getting rather large - understandable because of the sudo calls. I took a closer look at /var/log and it looks like there haven't been any log rotations since the end of August.

According to crontab they should be rotated every day. (I'm not sure what role anacron plays here currently which may be responsible for this kind of task if the machine isn't running 24/7.)

I took a look at /etc/cron.daily/logrotate (see below) and I don't understand the purpose of the test for the existence of /run/systemd/system and the exit if it exists. The directory is empty but it exists - so unless it disappears periodically the rest of the script will never execute.

I then executed the command /usr/sbin/logrotate /etc/logrotate.conf (at the end of the script) by hand and the logs were rotated.

Code:
root@kali:/var/log# ll auth*
-rw-r----- 1 root adm      2013 Dec 12 16:25 auth.log
-rw-r----- 1 root adm 264686726 Dec 12 15:15 auth.log.1
-rw-r----- 1 root adm      1107 Aug 28 05:39 auth.log.2.gz
-rw-r----- 1 root adm      2342 Aug  5 21:10 auth.log.3.gz
-rw-r----- 1 root adm      4927 Jul 30 08:39 auth.log.4.gz

Okay, I may be on a completely wrong track here and would benefit from a hint in the right direction.

Here the code of /etc/cron.daily/logrotate:
Code:
#!/bin/sh

# skip in favour of systemd timer
if [ -d /run/systemd/system ]; then
    exit 0
fi

# this cronjob persists removals (but not purges)
if [ ! -x /usr/sbin/logrotate ]; then
    exit 0
fi

/usr/sbin/logrotate /etc/logrotate.conf
EXITVALUE=$?
if [ $EXITVALUE != 0 ]; then
    /usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
fi
exit $EXITVALUE

Thanks.
# 2  
Old 12-12-2018
Is cron running? Check with service cron status or service crond status. Alternatively look at cron entries in system log files. Does it show up in ps? Any error messages?
# 3  
Old 12-12-2018
I suppose you could run this as root and see what happens. Try with the debug/trace turned on:-
Code:
bash -x /etc/cron.daily/logrotate

What is in /etc/cron.daily/logrotate? It may be working as designed, but there are no rules being activated.

It will probably be something trivial, but infuriating. I've had 'fun' with them myself.



Kind regards,
Robin
# 4  
Old 12-12-2018
Looks like it does:
Code:
root@kali:~# service cron status
● cron.service - Regular background program processing daemon
   Loaded: loaded (/lib/systemd/system/cron.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2018-12-13 01:54:32 CST; 7h left
     Docs: man:cron(8)
 Main PID: 552 (cron)
    Tasks: 1 (limit: 4915)
   Memory: 1.1M
   CGroup: /system.slice/cron.service
           └─552 /usr/sbin/cron -f

Dec 13 01:54:32 kali systemd[1]: Started Regular background program processing daemon.
Dec 13 01:54:32 kali cron[552]: (CRON) INFO (pidfile fd = 3)
Dec 13 01:54:32 kali cron[552]: (CRON) INFO (Running @reboot jobs)
Dec 13 01:55:01 kali CRON[949]: pam_unix(cron:session): session opened for user root by (uid=0)
Dec 13 01:55:01 kali CRON[950]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Dec 13 01:55:01 kali CRON[949]: pam_unix(cron:session): session closed for user root

--- Post updated at 10:10 AM ---

It does what I expected. The directory /run/systemd/system exists and hence:


Code:
root@kali:/etc/cron.daily# bash -x logrotate
+ '[' -d /run/systemd/system ']'
+ exit 0


I run another Debian based distribution (Raspbian) on a Raspberry Pi. That one has a shorter version of /etc/cron.daily/logrotate. It doesn't test for existence of /run/systemd/system. No problems over there:

(transcribed by hand):
Code:
#!/bin/sh


test -x /usr/sbin/logrotate || exit 0
/usr/sbin/logrotate /etc/logrotate.conf

# 5  
Old 12-12-2018
grep for "rotate" in the system logs I find


Code:
Dec 12 08:30:08 RudisPC systemd[1]: Started Rotate log files.

What do you?


Hoppla - cross posted. Looks like it thinks you have cron running in parallel to systemd timer. Need to read deeper.
# 6  
Old 12-12-2018
Do you mean /var/log/syslog?


Code:
root@kali:/var/log# cat syslog | grep "rotate"
root@kali:/var/log#

Nothing there.
# 7  
Old 12-12-2018
grep and most other utilities do not need cat's help to read a file.
Code:
grep "rotate" filename

Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

If I ran perl script again,old logs should move with today date and new logs should generate.

Appreciate help for the below issue. Im using below code.....I dont want to attach the logs when I ran the perl twice...I just want to take backup with today date and generate new logs...What I need to do for the below scirpt.............. 1)if logs exist it should move the logs with extention... (1 Reply)
Discussion started by: Sanjeev G
1 Replies

2. Shell Programming and Scripting

Help needed on Perl Script to Handle Log files that are rotated using logrotate

Hello all, I am working on a perl script which will read weblogic logfile and send the error messages to Zenoss Monitoring tool. At present the script works and it can able to send the error messages to Zenoss. The problem comes when the logrotate has been applied to the weblogic log file. At... (3 Replies)
Discussion started by: kar_333
3 Replies

3. UNIX Desktop Questions & Answers

regarding logs

Hi , I am running an application on my windows and it logs are generated at /var/logs and for this i have to go this location and then do tail -f , Is there any command you can advise me so that when I execute this command at this location that logs get displayed fully and as the application... (3 Replies)
Discussion started by: KAREENA18
3 Replies

4. Shell Programming and Scripting

Grep yesterday logs from weblogic logs

Hi, I am trying to write a script which would go search and get the info from the logs based on yesterday timestamp and write yesterday logs in new file. The log file format is as follows: """"""""""""""""""""""""""... (3 Replies)
Discussion started by: harish.parker
3 Replies

5. UNIX for Advanced & Expert Users

logs

Hy, I have a question I have a directory in a unix server, Some of my files have a diffrent access time, from the time i accessed them last, I think some one has copied it,it's not an important file,but none the less,it is my file,It mistakenly had a 777 permission( yes ,I know it is a noob's... (1 Reply)
Discussion started by: lordmod
1 Replies

6. Shell Programming and Scripting

Logs

Hey Guys, i am new into shell programming and i have to do one script which have to record all the commands entered by a specific user. Example of that, i have a system running on unix, several users are using this system, i have to create like a databse which will record every user entered that... (5 Replies)
Discussion started by: charbel
5 Replies

7. UNIX for Dummies Questions & Answers

logs

can i include this command into my crontab file > /var/adm/wtmp to clear the contents on a regular basis ? what about file permissions ? (6 Replies)
Discussion started by: cubicle^dweller
6 Replies

8. UNIX Desktop Questions & Answers

Logs

hi My name is Juan I dont can clear wtmp and similiar files how i do it? thanks (4 Replies)
Discussion started by: jtapia
4 Replies
Login or Register to Ask a Question