How can I automatically remove system log files in order to free up disk space?
By default, new instances are automatically configured to delete log files on a daily basis.
However, if your virtual machine (VM) does not have these files at /opt/maintenance-daily.sh
or if you have deleted them, you can easily configure the deletion process by following the steps below.
To create a script that deletes log files on your VM, begin by accessing the terminal (Open Terminal). You can find it within the service details on the top right side of the dashboard.
Once the terminal is open, copy and paste the provided code below to create the script responsible for deleting log files.
#Create maintenance daily log removinga script to remove logs every day.
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#Grant the script executable permissions to scriptpermissions.
chmod +x /opt/maintenance-daily.sh
#Create#To run these scripts every day, create a cron job on VMthe tovirtual run these scripts on daily basis.machine.
crontab -l | { cat; echo "0 1 * * * /opt/maintenance-daily.sh"; } | crontab -
You can modify these cron execution times by replacing 0 1 * * *
with your own cron execution times.
We keep a 30-mb log file by default, however, you can change the 30m
number to something else if you wish to keep a larger log file.