How to delete system log files automatically to clear up disc space
By default, on new instances,instances weare auto-automatically configured to delete the log files automaticallyon daily,a butdaily basis.
However, if your VMvirtual doesn'tmachine (VM) does not have these filefiles at /opt/maintenance-daily.sh
or if you have deleted it thenthem, you can easily configure itthe deletion process by following the belowsteps steps. below.
To create a script tothat deletedeletes alllog logsfiles on your VMVM, firstbegin openby accessing the terminal from(Open theTerminal). dashboard youYou can find it insidewithin the service details on the top right side.side of the dashboard.
AfterOnce opening athe terminal is open, copy and paste the belowprovided code below to create the script responsible for deleting log files.
#Create maintenance daily log removing script
echo 'echo "$(tail -c 30m /tmp/appStack.log)" > /tmp/appStack.log' >> /opt/maintenance-daily.sh
echo 'echo "$(tail -c 30m /var/log/syslog)" > /var/log/syslog' >> /opt/maintenance-daily.sh
echo 'journalctl --vacuum-time=10d --vacuum-size=500M;' >> /opt/maintenance-daily.sh
#Provide executable permissions to script
chmod +x /opt/maintenance-daily.sh
#Create a cron job on VM to run these scripts on daily basis.
crontab -l | { cat; echo "0 1 * * * /opt/maintenance-daily.sh"; } | crontab -
You can also changemodify these cron execution times by replacing 0 1 * * *
them with your customown cron timeexecution values.times.
We keep a 30-mb log file by default, however, you can change the 30-mb number to something else if you wish to keep a larger log file.