Skip to content

Instantly share code, notes, and snippets.

@lumue

lumue/kodi-syslog-tail.sh

Last active Mar 11, 2021
Embed
What would you like to do?
tail kodi.log (or any other logfile) to syslog
#!/bin/bash
tail -f /home/osmc/.kodi/temp/kodi.log |
while read -r line
do
logger $line
done
@efelon

This comment has been minimized.

Copy link

@efelon efelon commented Feb 26, 2021

A little improvement for the logger call:

logger -t KODI "${line:37}"

-t : sets a tag which is used as program name in syslog
${line:37} : removes the fixed length time stamp from the kodi log (tested only on Debian; length may be different on other platforms?)

.. and the tail command:

tail -n0 -F

-n0 : don't include the last lines when starting the log "transfer"
-F : retry reading the file until access is possible

The last one is needed when starting this process during boot, while the file kodi.log may not be accessible at that time.

@efelon

This comment has been minimized.

Copy link

@efelon efelon commented Mar 11, 2021

In the meantime I switched to this solution after reading that read is not recommended in this context and pure "pipe" is performing better.

tail -n0 -F /home/kodi/.kodi/temp/kodi.log | stdbuf -o0 cut -c37- | logger -t KODI

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