Share, , Google Plus, Pinterest,

Print

Posted in:

Error: bad top line in state file – logrotate.status

A while ago i noticed that /var partition on a certain server was almost filled up to a 100% up and started researching what caused this.

I noticed that log files in /var/log directory were not rotating. I decided to run the log rotation manually when i got this error “error: bad top line in state file /var/lib/logrotate.status”.

It was the first time i ever say this error and the fact that the logs stopped rotating was bad news! I needed to fix it asap!

Error: bad top line in state file - logrotate.status (Img Source: http://www.thegeekstuff.com/)
Error: bad top line in state file – logrotate.status (Img Source: http://www.thegeekstuff.com/)

Let’s fix “error: bad top line in state file /var/lib/logrotate.status”!

Since my log files were not rotating i decided to run logrotate manually to see what the problem was. You can run logrotate very simply bi running the logrotate command and pointing to the desired logrotate configuration file.

This is how we run logrotate manually for all logrotate configuration files in /etc/logrotate.d directory:

[root@geekpeek ~]# logrotate /etc/logrotate.d/*
error: bad top line in state file /var/lib/logrotate.status
error: could not read state file, will not attempt to write into it
As we can see, logrotate stopped with an error about logrotate.status file. It says it will not even attempt to write into it which already implies to the solution of this problem.

 

Due to the error i got when running logrotate manually, i decided to backup logrotate.status file by moving (renameing) it:

[root@geekpeek ~]# mv /var/lib/logrotate.status /var/lib/logrotate.status.orig
Let’s try running logrotate again and hopefully not see the “error: bad top line in state file /var/lib/logrotate.status” again:
[root@geekpeek ~]# logrotate /etc/logrotate.d/*
[root@geekpeek ~]#
Voila success! The error did not appear again, seems like our solution worked. Let’s just check if logrotate.status file was successfully recreated by listing the file:
[root@geekpeek ~]# ll /var/lib/logrotate.status
-rw-r--r-- 1 root root 225 Aug 7 08:16 /var/lib/logrotate.status
Beautiful! We are done!

 

If you are still having problems and your logrotate.status file was not recreated you might try forcing the logrotate by adding the “-f” parameter when running the command:
[root@geekpeek ~]# logrotate -f /etc/logrotate.d/*
[root@geekpeek ~]#
I hope this might help somebody solve “error: bad top line in state file /var/lib/logrotate.status” logrotate problems!