Save the output of cron shell scripts to a sqlite db
Find a file
2025-12-22 16:48:01 +01:00
.vscode feat: visualization and output toggle 2025-12-05 12:31:59 +01:00
cmd chore: moved files around to prepare for middleware 2025-12-22 16:48:01 +01:00
litestream feat: a bit of template updates and paging 2025-12-04 18:20:37 +01:00
server chore: moved files around to prepare for middleware 2025-12-22 16:48:01 +01:00
store feat: move the configuration to the database 2025-12-21 15:16:03 +01:00
.air.toml feat: a bit of template updates and paging 2025-12-04 18:20:37 +01:00
.editorconfig feat: move the configuration to the database 2025-12-21 15:16:03 +01:00
.gitattributes Initial import 2025-12-01 17:07:22 +01:00
.gitignore feat: a bit of template updates and paging 2025-12-04 18:20:37 +01:00
application.json chore: update the config file 2025-12-21 15:31:01 +01:00
create_log.sh feat: move the configuration to the database 2025-12-21 15:16:03 +01:00
cronlogger_deploy.sh feat: move the configuration to the database 2025-12-21 15:16:03 +01:00
doc.go Initial import 2025-12-01 17:07:22 +01:00
go.mod feat: move the configuration to the database 2025-12-21 15:16:03 +01:00
go.sum feat: move the configuration to the database 2025-12-21 15:16:03 +01:00
LICENSE Initial commit 2025-12-01 17:06:40 +01:00
Makefile feat: move the configuration to the database 2025-12-21 15:16:03 +01:00
pipereader.go Initial import 2025-12-01 17:07:22 +01:00
pipereader_test.go Initial import 2025-12-01 17:07:22 +01:00
README.md chore: README update 2025-12-22 11:58:16 +01:00
show_log.sh feat: create a simple http server to show the contents of the sqlite db. 2025-12-02 16:51:01 +01:00

Cronlogger

Capture the output of cron-tasks and store the output in a sqlite DB.

  • cmd/logger

Visualize the contents of the sqlite DB in a simple web UI.

  • cmd/server

Usage

Logger

The cronlogger reads the piped output via stdin an stores it in the db

echo "${COMMAND_OUTPUT}" | /usr/local/bin/cronlogger \
    --app=<appname> \
    --code=${RESULT_CODE} \
    --db=/var/cronlog/cronlog-store.db

Server

The server provides an http endpoint which shows the result of the executions. Typically a systemd service is used to start the server.

cronlogger_server.service:

[Unit]
Description=Cronlogger HTTP Server

[Service]
User=cronlogger
Group=cronlogger
Restart=always
ExecStart=/usr/local/bin/cronlogger_server -db /var/cronlog/cronlog-store.db -host localhost

[Install]
WantedBy=multi-user.target

Deployment

A simple git-deployment was established for the target-system following ths gist: https://gist.github.com/noelboss/3fe13927025b89757f8fb12e9066f2fa

# steps performed on the target-system

# the target folder to clone artifacts to
mkdir ~/cronlogger.deployment

# create a deployment git-repo
git init --bare ~/cronlogger.git

# create a post-receive hook script
touch cronlogger.git/hooks/post-receive
chmod +x post-receive

# -----------------------------------------------------------------------------------
# local/development system
# add remote on local/development system
git remote add production user@system:cronlogger.git

The post-receive hook takes care of the deployment

post-receive:

#!/bin/bash
TARGET_FOLDER="/path/to/cronlogger.deployment"
DEPLOYMENT_FOLDER="/usr/local/bin"
CONFIG_FOLDER="/etc/cronlogger"
GIT_DIR="/path/to/cronlogger.git"
BRANCH="main"

while read oldrev newrev ref
do
        # only checking out the master (or whatever branch you would like to deploy)
        if [ "$ref" = "refs/heads/$BRANCH" ];
        then
                echo "Ref $ref received. Deploying ${BRANCH} branch to production..."
                git --work-tree=$TARGET_FOLDER --git-dir=$GIT_DIR checkout -f $BRANCH
                sudo cp -f ${TARGET_FOLDER}/cronlogger ${DEPLOYMENT_FOLDER}/cronlogger
                sudo cp -f ${TARGET_FOLDER}/cronlogger_server ${DEPLOYMENT_FOLDER}/cronlogger_server
                sudo cp -f ${TARGET_FOLDER}/application.yaml ${CONFIG_FOLDER}/application.yaml
                sudo systemctl restart cronlogger_server
                sudo systemctl status cronlogger_server
                echo "Deployment done; server restarted; have fun!"
        else
                echo "Ref $ref received. Doing nothing: only the ${BRANCH} branch may be deployed on this server."
        fi
done