In this page I describe how to manage LOG files on a router (Asus RT-AC56U)
- we use an Entware package, so please
refer to this page on how to install Entware on a router.
On a router we can install any type of daemon, and most daemons create and
manage a LOG file which can become bigger and bigger and take up a lot of space
on the router's internal storage. The management of LOG files is of vital
importance especially when dealing with limited storage, such as that of a
router, so managing a LOG file becomes vital to avoid taking up the storage on a
router. To manage the LOG files we will use a Linux application called "LOGROTATE"
which allows, if executed, to properly manage the LOG files, following the
indications of a properly configured configuration file.
In order to install the "LOGROTATE" application with
the Entware packages, we must execute the following command :
opkg install logrotate
The above-mentioned package contains the executable file "/opt/sbin/logrotate"
and the configuration file "/opt/etc/logrotate.conf". We create a backup copy of
the "/opt/etc/logrotate.conf" configuration file.
The following is a sample content of the above-mentioned configuration file
"/opt/etc/logrotate.conf" :
# see "man logrotate" for details # rotate log files weekly weekly # keep 4 weeks worth of backlogs rotate 4 # create new (empty) log files after rotating old ones create # use date as a suffix of the rotated file dateext # uncomment this if you want your log files compressed #compress # RPM packages drop log rotation information into this directory include /opt/etc/logrotate.d # system-specific logs may be also be configured here.
Refer
to this page for further details about configuration file "logrotate.conf".
In the above-mentioned example:
Obviously in the above example file, there is no reference to an already existing .LOG file, we will include it now.
As an example we take the LOG file of the Transmission daemon (refer to this page for further details on how to install and configure the above-mentioned Transmission daemon). To find out where it is located, use the following command "ps | grep transmission-daemon"; in the output line containing the Transmission daemon, after the "-e" parameter we can see the path and the LOG file of the above-mentioned daemon. We complete the configuration file "logrotate.conf" in order to have a reference to the above LOG file of the Transmission daemon.
# see "man logrotate" for details # rotate log files weekly weekly # keep 4 weeks worth of backlogs rotate 4 # create new (empty) log files after rotating old ones create # use date as a suffix of the rotated file dateext # uncomment this if you want your log files compressed #compress # Some packages can drop log rotation information into this directory include /opt/etc/logrotate.d # system-specific logs may be also be configured here. "/opt/var/log/transmission.log" { create 666 nobody nobody daily missingok nocompress nomail notifempty rotate 10 size 100k su nobody nobody }
In the above-mentioned configuration file, we have created a dedicated section for the LOG file of the Transmission with the path "/opt/var/log/transmission.log" that is the path where the LOG file of the Transmission is placed. Within this section we include the parameters and configuration options dedicated to the above LOG file, these parameters have priority over those ones outside the above-mentioned section. The parameters provide the following configuration:
In the above-mentioned configuration file we have set the
rotation of the LOG files every day, so every day we will run the "LOGROTATE"
application.
We create a script file, for example we call it "daily.sh", with the following
content :
#!/bin/sh chmod 644 /opt/etc/logrotate.conf /opt/sbin/logrotate /opt/etc/logrotate.conf