add new post
This commit is contained in:
parent
780ab47459
commit
f721b03f18
56
_posts/2019-12-11-Cron.md
Normal file
56
_posts/2019-12-11-Cron.md
Normal file
@ -0,0 +1,56 @@
|
||||
---
|
||||
layout: post
|
||||
title: "I used cron for the first time"
|
||||
description: "And I didn't die"
|
||||
date: 2019-12-11 11:38:00
|
||||
categories: random
|
||||
redirect_from:
|
||||
- /post/cd9dj84kf0/
|
||||
- /cd9dj84kf0/
|
||||
---
|
||||
|
||||
|
||||
[Cron](https://en.wikipedia.org/wiki/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](https://en.wikipedia.org/wiki/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).
|
||||
|
||||
```sh
|
||||
#! /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.
|
||||
```cron
|
||||
# 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
|
Loading…
x
Reference in New Issue
Block a user