Skip to main content

How to delete system log files automatically to clear up disc 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 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 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 30-mb number to something else if you wish to keep a larger log file.