💾 Archived View for tommi.space › Cron%20Jobs.gmi captured on 2023-07-22 at 16:37:21. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2023-01-29)

-=-=-=-=-=-=-

Cron Jobs essentially consist in running some command from the terminal at a predefined time, or every given interval.

They are great and useful since they can be used to automate any type of task.

Configuration

Short answer

Run [crontab -e][crontab]

Long answers

How do I set up a Cron Job?

Creating a custom Cron Job

Ubuntu Community Help Wiky

CronHowto

Crontab Guru

Enable logging

Cron Jobs do not log activity by default, to activate logging for an easier debugging, go to /etc/rsyslog.conf or /etc/rsyslog.d/50-default.conf and uncomment the following line:

cron.*					/var/log/cron.log

then run

sudo service rsyslog restart && sudo service cron restart

Cron Jobs logs will appear in /var/log/cron.log

Troubleshooting

Solve (CRON) info (No MTA installed, discarding output)

My Cron Jobs

rtcwake

This Cron Job schedules [[Linuxplosion]] boot, and it switches it off until the following week.

35 18 * * 1 sudo udisksctl mount -b /dev/sda2 && echo "`date`: Linuxplosion is up and running!" >> ~/rtcwake-log.txt
0 21 * * 1 echo "`date`: Linuxplosion is going back to sleep until next monday at 7PM." >> ~/rtcwake-log.txt && sudo rtcwake -m off -t "$(date -d 'next Monday 18:30' '+%s')"

wayback_archiver

This Cron Job saves a list of predefined pages to The Wayback Machine using wayback_archiver

The Wayback Machine

wayback_archiver

0 1 * * 1 /usr/local/bin/wayback_archiver https://tommi.space/pages-to-archive --crawl --limit=100 --verbose --log=$HOME/wayback_archiver.log && echo "\n$(date) wayback_archiver success!" >> $HOME/wayback_archiver.log

<div class='red box'>
    <a href='https://github.com/buren/wayback_archiver/issues/46' target='_blank' title='The issue I opened for this script not working'>I spent too much time</a> trying to make this script work on [[Server|Xplosion Server]] with [[YunoHost]]. Hence, I am not using this Cron Job anymore, but <a href='https://github.com/marketplace/actions/wayback-machine' target='_blank' title='“Wayback Machine„ GitHub Action'>this GitHub Action</a> instead
</div>

[crontab]: https://man.cx/crontab 'crontab’s man page'

https://man.cx/crontab