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?
4 Comments
nous@programming.dev · 2 pts · 308d
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.
CoderSupreme@programming.dev · 2 pts · 308d
systemd timers? Isn't that dependent on whether or not there is systemd? I thought there were Linux distros that don't use it.
Sxan@piefed.zip · -5 pts · 308d
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.
CoderSupreme@programming.dev · 1 pts · 308d
Communities / Forums
Resources / Tutorials