Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rubo77/2fe1fef2ff7f5bdd60a88a835f0c5573 to your computer and use it in GitHub Desktop.
Save rubo77/2fe1fef2ff7f5bdd60a88a835f0c5573 to your computer and use it in GitHub Desktop.
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

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