SNO Flight Manual

Cron command for live appending logs, with date stamp and without redirecting logs from the storagenode container.

Wanted to keep this simple, which i didn’t, but now it works kinda great…
This will keep a 1min delayed live log saved, without having to redirect your docker log files and thus you can run all scripts by default or run stuff like docker logs storagenode --follow

how to make it work is explained in detail, below and everything is basically copy paste ready.
Enjoy… and i hope some else finds this useful.

#
# Add this to your crontab, using crontab -e
# The command will run a one line command, which maybe could have been working from only cron, but this is the best i got thus far.
#
# * * * * * (tells cron to run the storagenode_append_log.sh script every minute
# >> appends the output of the script to the log file
# $(date +\%Y-\%m-\%d) adds the current date to the log filename
# 2>&1 combines the stdout stderr into a single file (not sure if this is required tho)
#
 * * * * * /storagenodes/storj/scripts/storagenode_append_log.sh >> /storagenodes/storj/logs/storagenode_$(date +\%Y-\%m-\%d).log 2>&1





### Bash script because cron cannot do variables without this getting messy
#
# filename:
# storagenode_append_log.sh

# Location (basically where ever you want,
# Tho do keep in mind to change the location / folder in the crontab -e also
# but i set the location to a scripts folder inside to storj folder.
# seems mostly empty anyways... so... where was i

# Location:
# /storagenodes/storj/storagenode_append_log.sh

# Other related information
# use chmod +x /storagenodes/storj/scripts/storagenode_append_log.sh
# this makes the script below executable

## Bash scripts starts below this point

#!/bin/bash
# Bash script for appending to storagenode log
# If anyone know how to make this into a crontab -e commandline only, don't hold back...

docker logs --since "$(date -d "$date -2 minutes" +"%Y-%m-%dT%H:%M")" --until "$(date -d "$date -1 minutes" +"%Y-%m-%dT%H:%M")" storagenode
2 Likes