Skip to content

Instantly share code, notes, and snippets.

@lumue
Last active March 11, 2021 16:37
Show Gist options
  • Save lumue/112adb3364121ccfd1bf to your computer and use it in GitHub Desktop.
Save lumue/112adb3364121ccfd1bf to your computer and use it in GitHub Desktop.
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
Copy link

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
Copy link

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