Inspect logrotate status with logrotate -d
In this final step, you will learn how to use the logrotate
command with the -d
option to perform a "dry run". A dry run simulates the actions that logrotate
would take without actually performing them. This is extremely useful for testing your logrotate
configurations and understanding what will happen when logrotate
runs for real.
The -d
option stands for "debug" or "dry run". When you use it, logrotate
will read its configuration files and report what it would do, but it won't modify any files or rotate any logs.
Since logrotate
typically requires root privileges to access and modify log files in system directories like /var/log
, you will need to use the sudo
command to run logrotate
with the necessary permissions. Remember, the labex
user has sudo
privileges without needing a password in this environment.
Type the following command into your terminal and press Enter:
sudo logrotate -d /etc/logrotate.conf
Let's break down this command:
sudo
: Executes the command with superuser privileges.
logrotate
: The command-line utility for managing log files.
-d
: The option to perform a dry run (debug mode).
/etc/logrotate.conf
: The main configuration file that logrotate
should read.
The output of this command will be quite verbose. It will show you which log files logrotate
is considering, which configuration directives apply to them, and whether rotation is necessary based on the current state and configuration.
You will see output detailing the processing of the main configuration file and the included files from /etc/logrotate.d/
. It will indicate for each log file whether it needs rotating and why (e.g., size, age).
Example output might include lines like:
reading config file /etc/logrotate.conf
including /etc/logrotate.d
reading config file apt
...
rotating pattern: /var/log/apt/term.log /var/log/apt/history.log weekly
...
considering log /var/log/apt/term.log
log does not need rotating
considering log /var/log/apt/history.log
log does not need rotating
...
This output confirms that logrotate
read the configuration for apt
and determined that its log files do not currently need rotation.
Using logrotate -d
is a crucial step before deploying any new or modified logrotate
configurations to ensure they work as expected without causing unintended issues with your log files.
You have now successfully inspected the main logrotate
configuration, viewed the individual configuration files, and performed a dry run to see how logrotate
would behave.
Click Continue to complete this lab.