Created
July 5, 2019 10:58
-
-
Save tomaszklim/ae4d011cd61b31d0ca193d32a6333114 to your computer and use it in GitHub Desktop.
Send stdout logs from running Docker containers by email.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Written by Tomasz Klim, 2019-07-05 | |
# | |
# This is a simplified, open source version. It relies on $MAILTO variable | |
# defined in /etc/crontab file for all cron tasks. A better approach would | |
# be to send emails in dedicated format, to dedicated list of recipients. | |
# | |
# Add this to /etc/crontab: | |
# * * * * * root /etc/local/docker-logtail.sh | |
if [ ! -x /usr/bin/docker ] || [ ! -x /usr/sbin/logtail ]; then exit 0; fi | |
for ID in `/usr/bin/docker ps -q --no-trunc`; do | |
infile=/var/lib/docker/containers/$ID/$ID-json.log | |
offsetfile=/var/lib/docker/tmp/$ID.offset | |
/usr/sbin/logtail -f$infile -o$offsetfile | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment