Skip to main content

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/ 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 a script to remove logs every day.
echo 'echo "$(tail -c 30m /tmp/appStack.log)" > /tmp/appStack.log' >> /opt/
echo 'echo "$(tail -c 30m /var/log/syslog)" > /var/log/syslog' >> /opt/
echo 'journalctl --vacuum-time=10d --vacuum-size=500M;' >> /opt/

#Grant the script executable permissions.
chmod +x /opt/

#To run these scripts every day, create a cron job on the virtual machine.
crontab -l | { cat; echo "0 1 * * * /opt/"; } | 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.