This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. {{tag>linux debian log rotate logrotate cron crontab}} ======logrotate====== There are a number of ways to rotate logs. -Using a script and cron (or systemd.timer) -Using ''logrotate'' ====Logrotate using script==== edit the sudo crontab ''sudo crontab -e'': <code> Example of job definition: # .---------------- minute (0 - 59) # | .------------- hour (0 - 23) # | | .---------- day of month (1 - 31) # | | | .------- month (1 - 12) OR jan,feb,mar,apr ... # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat,sun # | | | | | # * * * * * user-name command to be executed # 0 0 1 * * /home/shared/Myscripts/rotatelog.sh /var/log/UPS/UPSLog.Log #Rotate NUT UPS log file </code> where ''/home/shared/Myscripts/rotatelog.sh'' is: <code>#!/bin/bash logfile=$1 if [ ! -f $logfile ]; then echo "log file not found $logfile" exit 1 fi timestamp=`date +%Y%m%d` newlogfile=$logfile.$timestamp cp $logfile $newlogfile cat /dev/null > $logfile gzip -f -9 $newlogfile </code> Remember to make executable (''sudo chmod +x /home/shared/Myscripts/rotatelog.sh'') ====logrotate==== -Install logrotate - debian: ''sudo apt install logrotate'' - Arch: ''sudo pacman -S logrotate'' *The main logrotate configuration file is here: ''/etc/logrotate.conf'' * ====Links==== [[https://www.linuxshelltips.com/rotate-logs-with-logrotate-linux/|How to Rotate Logs With Logrotate in Linux]] <- home_server:home_server_setup:other_services:samba|Prev ^ home_server:home_server_setup:other_services:index|Start page ^ home_server:home_server_setup:other_services:firmware|Next ->