Module 07 · DevOps · CI/CD, IaC & Operations · about 19 min to read
Continue where you left off ×
Scripts that do not surprise: bash, text tools and cron
The Assembly Line · Open board
The assembly line where each step hands its result to the next. A shell script is a small line like this, and this lesson is about making each step stop the line when it fails, instead of passing a broken part along.
The idea in 30 seconds
Every command leaves an exit status, where 0 is success, and a script that ignores it carries on after a failure.
set -euo pipefail stops a script at a failed command, an unset variable or a failed part of a pipeline.
grep keeps lines, sed rewrites them and awk splits fields and does sums.
xargs turns lines into arguments, -print0 with -0 keeps odd names whole, and -P runs work side by side.
An idempotent script is safe to run twice, because it checks before it changes anything.
Cron runs a script by the clock in a plainer environment than your terminal, and flock -n stops two copies overlapping.
Read the story
Lesson 48 of 70 in DevOps
The rest of this lesson is part of a plan.
A plan opens every lesson, board, video, lab and paper on chalk. Yearly is $39/year .
See plans Already a member? Sign in
Or start free : a free account opens lessons 2 and 3 of every track.
In this lesson A cleanup script runs in the wrong folder Exit status: the number every command leaves behind Safe mode: three switches that stop the script at the first mistake Pipefail: a pipe is only as honest as its last step grep, sed and awk: three tools that cut a log down to an answer xargs: turn lines into arguments, and run them side by side Idempotent: the script you can run twice Cron: the clock that runs your script, and the lock that stops two at once What each switch does, and where -e stops working A script that checks its own inputs Quoting: why "$dir" has quotes Atomic writes, so no reader sees half a file awk, sed and grep: the choices that decide which tool xargs: more than one way to hold a batch Cron, in detail Where cron stops being enough Terms it explains: exit status, safe mode, `grep`, `sed`, `awk`, `xargs`, idempotent, Cron, lock, Common mistakes, CI.
Review DevOps
Mark as read Saved in this browser, and to your account when you sign in.