Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
truncate syslog after suspend
[Unit]
Description=deletes all but the last 1000 lines of syslog due to possible logging spam by VLC
[Service]
Type=oneshot
ExecStart=-/usr/local/sbin/truncate_syslog.sh
TimeoutSec=0
StandardOutput=syslog
After=suspend.target
[Install]
WantedBy=multi-user.target sleep.target
#!/bin/bash
# save in /usr/local/sbin/truncate_syslog.sh
# deletes all but the last 1000 lines in syslog and vacuums journalctl down to 50 MB
LINES=1000
tail -n $LINES /var/log/syslog > /tmp/tmpfile
cat /tmp/tmpfile > /var/log/syslog
rm /tmp/tmpfile
service syslog restart
journalctl --vacuum-size=50M
logger syslog "emptied and service restarted; journalctl vacuumed down to 50 MB"
sudo cp truncate_syslog_after_resume.service /etc/systemd/system/
sudo systemctl enable truncate_syslog_after_resume.service --now
@samirsaliba
Copy link

samirsaliba commented Feb 23, 2021

just added this after VLC spamming gbs into my syslog.
thanks for the help, @rubo77

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment