I used cron for the first time

And I didn't die

2019-12-11 random

Cron has always been one of those “scary sysadmin things” in my head. But today, I finally used it!

My need

I have access to a private API that happens to clear it’s users if they are inactive for too long. To solve this, I decided to add a small cron job to make an API call once per month. Basically a keepalive.

How I set it up

Adding a cron job to my laptop was very easy. First, I made a bash script for my api call (not needed, but I felt like doing it).

#! /bin/bash
curl --include --header "Accept: application/xml" '<API Endpoint Here>' --user $1:$2

Then, by running crontab -e in my terminal, I just added a new line at the bottom of the file, discribing the task, and when it should be run.

# Edit this file to introduce tasks to be run by cron.
# 
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
# 
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').# 
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
# 
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
# 
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
# 
# For more information see the manual pages of crontab(5) and cron(8)
# 
# m h  dom mon dow   command
00 11 1 * * /usr/local/bin/api-keepalive.sh <username> <password>

This will run once per month, on the 1st, at 11:00.

That’s it! Stupidly simple, and I am no longer scared of cron



Thank you for reading this post. If you enjoyed the content, and want to let me know, or want to ask any questions, please contact me via one of the methods listed here. If you would like to be notified about future posts, feel free to load my rss feed into your favorite feed reader, or follow me on Twitter for notifications about my work and future posts.
If you have the time to read some more, I recommend checking out one of the following posts:
Using Bazel to create Minecraft modpacks
I decided to modernize my system for producing builds of my personal Minecraft modpack using the Bazel buildsystem.
Mounting Google Drive accounts as network drives
I can never get the Google Drive webapp to load quickly when I need it to. My solution: use some command-line magic to mount my drives directly to my laptop's filesystem.
Reading metadata from a bitmap file
Inspired from one of my friend's projects, I built a small tool for displaying bitmap file info from the command line.


Made with ♥ by Evan Pratten | RSS | API Status