Alerting on your own device

A check you have to remember to run is a check you will stop running. This set covers keeping a check quiet by default, comparing two states, appending rather than overwriting, and giving cron everything it needs to run your job without you.

4 questions 1 task Read the lesson

Questions

Each one is marked as you go, and the explanation arrives straight after, which is the part worth reading.

4 questions, marked as you go.

1 Why should a check print nothing when everything is fine?
2 What does diff -q do when the two files match?
3 Why use >> rather than > when writing the alert log?
4 Why must a cron job name the full path to the script?

Tasks

These need your own device. Run the command in Termux, then paste what it printed. The marking looks at what the output means, so spacing, version numbers and ordering do not matter. If you have not installed anything yet, the lesson covers the setup.

Fire one alert, quietly

This compares two short lists, finds that one line was added, and appends a single stamped alert to a log. Run it twice if you like: the second run adds nothing, because nothing changed.

Run this in Termux On your own device. Nothing on this page executes it. The command runs in your terminal, and this box only reads what you paste back.

cd ~; printf 'a\nb\n' > base.txt; printf 'a\nb\nc\n' > now.txt; if ! diff -q base.txt now.txt >/dev/null; then printf '%s ALERT new line: %s\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)" "$(comm -13 base.txt now.txt | tr '\n' ' ')" >> alert.log; fi; cat alert.log
Marking your own work Both halves of this are checked in your browser, with no server involved, so nothing stops you from pasting output you did not run. The tasks are written so that the easiest way to pass one is to actually do it and read the result, which is the whole intention.

All sets Read the lesson