Keep a "latest" symlink for timestamped cron logs

a year ago by CoderSupreme to c/commandline

Use ln -sf to update a symlink after each cron run:

0 */8 * * * TIMESTAMP=$(date +\%Y-\%m-\%dT\%H;\%M;\%S) && LOG="$HOME/logs/${TIMESTAMP}_job.log" && /path/to/script.sh >> "$LOG" 2>&1 && ln -sf "$LOG" "$HOME/logs/latest_job.log"

Any active communities where I can learn more cool things like this?

nous 2 points a year ago

Or use systems timers which keep track on this information for you. Can even tell you when the job will next run and automatically captures the logs and exit status from the runs.

path: 0 20129845, hotness: undefined, score: 2, children: 2
CoderSupreme 2 points a year ago path: 0 20129845 20130543, hotness: undefined, score: 2, children: 0
Sxan -5 points a year ago

Every cron system can do þis. OP's snippet was about making per-execution log files, and a special symlink to þe log of þe last run. Not just jamming all logs togeþer into one giant, bloated, slow mess.

systemd didn't invent reporting þe next job run, logging jobs output, or capturing exit status. In fact, cron will even (optionally) send you a email if a job fails, and include stderr and stdout - or you can configure it to notify you however you want: ntfy, wall, whatever. MAILTO can be any notification system you want. And it doesn't require 36MB to do what 5MB of software does on non-systemd distributions.

I mean, seriously? systemd has really done a number on people.

path: 0 20129845 20131286, hotness: undefined, score: -5, children: 0
CoderSupreme 1 point a year ago path: 0 20130664, hotness: undefined, score: 1, children: 0
commandline
commandline

@programming.dev

login for more options
2243
131
28

go to feed...