Write a one-file script that measures how long each step of a deploy takes.
IntermediateHands-onBash scripting tasks
Answer
step() {
local name="$1"; shift
local start=$SECONDS
echo "--> $name"
"$@"
echo "<-- $name took $((SECONDS - start))s"
}
step "pull image" docker pull myapp:1.4.2
step "run migrate" docker run --rm myapp:1.4.2 ./migrate
step "restart" systemctl restart myapp
Key trick → Wrapping commands in a function that takes "$@" gives you timing, logging and error handling in one place.
More on Bash scripting tasks
Write the safe header you start every Bash script with, and explain each part.BeginnerWrite a script that alerts when any filesystem is above 80% usage.BeginnerParse an Nginx access log and print the top 10 client IPs by request count.BeginnerWrite a backup script that tars a directory with a timestamp and keeps only the last 7 backups.IntermediateWrite a health-check loop that polls a URL until it returns 200, with a timeout.IntermediateParse command-line flags `-e <env>`, `-v` (verbose) and `-h` in a Bash script.Intermediate