Manuals / Linux & CLI for Testers / Ch 7

B · Tester toolkitIntermediate40 min read

7. Small scripts that help testing

Linux & CLI for Testers · 36 pages source format

Loops, variables, exit codes. Automate boring setup: seed data, wait for port, collect logs.

What you'll learn

  • bash basics
  • exit codes
  • set -euo pipefail lite

Wait-for-url script

#!/usr/bin/env bash
set -euo pipefail
url=${1:-https://httpbin.org/status/200}
for i in {1..10}; do
  if curl -sf "$url" >/dev/null; then echo ready; exit 0; fi
  sleep 1
done
echo timeout >&2; exit 1

Do this now

Write a script that curls until 200 or times out.

Clear?

Checklist