How to fix logrotate cron job error (/etc/cron.daily/logrotate)

After migrating my database to a new server running Ubuntu 14.04.4 LTS i received an email with the following content:

Subject

Cron test -x /usr/sbin/anacron || ( cd / && run-parts –report /etc/cron.daily )

Body

/etc/cron.daily/logrotate:
error: error running shared postrotate script for ‘/var/log/mysql.log /var/log/mysql/mysql.log /var/log/mysql/mysql-slow.log /var/log/mysql/error.log ‘
run-parts: /etc/cron.daily/logrotate exited with return code 1

The reason why i was getting this error was because i imported my old mysql tables, including the users.
This particular cron job uses a mysql user debian-sys-maint to flush the logs, but i changed the password by importing all of my old tables.

You can fix this by creating the user with the correct password which can be found in the /etc/mysql/debian.cnf file:

# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host = localhost
user = debian-sys-maint
password = xxxxxxxxxxxxxxxx
socket = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host = localhost
user = debian-sys-maint
password = xxxxxxxxxxxxxxxx
socket = /var/run/mysqld/mysqld.sock
basedir = /usr

Take the password and fix the mysql user in the mysql console:

1
2
GRANT RELOAD, SHUTDOWN, PROCESS, SHOW DATABASES, SUPER, LOCK TABLES ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY 'xxxxxxxxxxxxxxxx';
FLUSH PRIVILEGES;

You can check if it worked by executing:

1
mysqladmin --defaults-file=/etc/mysql/debian.cnf ping

It seems that sometimes the password found in /etc/mysql/debian.cnf isn’t hashed, in my case it was.
If the above snippet did not work try

1
2
GRANT RELOAD, SHUTDOWN, PROCESS, SHOW DATABASES, SUPER, LOCK TABLES ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY PASSWORD 'xxxxxxxxxxxxxxxx';
FLUSH PRIVILEGES;

Thanks to Lorna Jane Mitchell post on this and the commentators.

2 thoughts on “How to fix logrotate cron job error (/etc/cron.daily/logrotate)

  1. Many thanks, not sure I’d have found that by myself. If that would be Stack Overflow, you’d get a +1 now.

Leave a Reply

Your email address will not be published. Required fields are marked *