Ravindra BagaleCourses & study guides मराठी

Ravi Sir's Cards › DevOps

Chapter 5: Bash Scripting for Automation: Cards

मराठी cards · Open the chapter

Revision cards

Why script: the morning ten commands. Repeating commands by hand is slow and error-prone.
Revision card 1 of 11: Why script: the morning ten commands · Download PNG · Open card page

Lesson: 5.1 Why script — the morning ten commands

Shebang, permissions, first script. Without these, scripts run with the wrong shell or keep going after errors.
Revision card 2 of 11: Shebang, permissions, first script · Download PNG · Open card page

Lesson: 5.2 Shebang, permissions, first script

Variables, quotes and exit codes. Unquoted variables break on spaces; ignored exit codes hide failures.
Revision card 3 of 11: Variables, quotes and exit codes · Download PNG · Open card page

Lesson: 5.3 Variables, quotes and exit codes

if and loops for health checks. Checking many servers by hand misses some.
Revision card 4 of 11: if and loops for health checks · Download PNG · Open card page

Lesson: 5.4 if and loops for health checks

Idempotent-ish habits: check before install. Scripts that break on a second run are dangerous.
Revision card 5 of 11: Idempotent-ish habits: check before install · Download PNG · Open card page

Lesson: 5.5 Idempotent-ish habits — check before install

cron basics: schedule the script. Scripts nobody runs are useless.
Revision card 6 of 11: cron basics: schedule the script · Download PNG · Open card page

Lesson: 5.6 Cron basics — schedule the script

Secrets: never hardcode. Hardcoded secrets end up in Git and logs, and leak.
Revision card 7 of 11: Secrets: never hardcode · Download PNG · Open card page

Lesson: 5.7 Secrets — never hardcode

Reading arguments and a full sample script. Hard-coded values make one script per environment.
Revision card 8 of 11: Reading arguments and a full sample script · Download PNG · Open card page

Lesson: 5.8 Reading arguments and a full sample script

Functions keep scripts readable. Long scripts without structure are hard to fix.
Revision card 9 of 11: Functions keep scripts readable · Download PNG · Open card page

Lesson: 5.9 Functions — keep scripts readable

Debugging scripts without guessing. Guessing wastes hours on simple bugs.
Revision card 10 of 11: Debugging scripts without guessing · Download PNG · Open card page

Lesson: 5.10 Debugging scripts without guessing

Lab: health-check script with dry run. A dry run lets you test scripts safely before they change anything.
Revision card 11 of 11: Lab: health-check script with dry run · Download PNG · Open card page

Lesson: 5.11 Lab — health check script with dry-run

Interview cards

When should you automate with a script? When a task is repeated, has many steps, or must be done the same way by anyone.
Interview card 1 of 11: When should you automate with a script? · Download PNG · Open card page

Lesson: 5.1 Why script — the morning ten commands

What does set -euo pipefail do? -e stop on error, -u error on unset variables, pipefail fail if any command in a pipe fails.
Interview card 2 of 11: What does set -euo pipefail do? · Download PNG · Open card page

Lesson: 5.2 Shebang, permissions, first script

What is an exit code? A number every command returns: 0 = success, anything else = failure. Scripts and CI use it to decide what to do next.
Interview card 3 of 11: What is an exit code? · Download PNG · Open card page

Lesson: 5.3 Variables, quotes and exit codes

Write a loop that checks health URLs. for each host, if curl -sf succeeds print OK, else print DOWN and remember a failure.
Interview card 4 of 11: Write a loop that checks health URLs. · Download PNG · Open card page

Lesson: 5.4 if and loops for health checks

What does idempotent mean in automation? Running it many times gives the same result as running it once.
Interview card 5 of 11: What does idempotent mean in automation? · Download PNG · Open card page

Lesson: 5.5 Idempotent-ish habits — check before install

Why does a script work by hand but fail in cron? cron has a minimal PATH and environment, a different working directory, and no terminal; use full paths and log output.
Interview card 6 of 11: Why does a script work by hand but fail in cron? · Download PNG · Open card page

Lesson: 5.6 Cron basics — schedule the script

How do scripts get secrets safely? From environment variables set by CI secrets or a secret manager, never written in the file or printed.
Interview card 7 of 11: How do scripts get secrets safely? · Download PNG · Open card page

Lesson: 5.7 Secrets — never hardcode

How do you handle script arguments? Read $1, $2, check $#, show a usage message and exit non-zero if wrong.
Interview card 8 of 11: How do you handle script arguments? · Download PNG · Open card page

Lesson: 5.8 Reading arguments and a full sample script

Why use functions in Bash? To reuse code, give steps names, and keep the main flow short and readable.
Interview card 9 of 11: Why use functions in Bash? · Download PNG · Open card page

Lesson: 5.9 Functions — keep scripts readable

How do you debug a failing Bash script? Run with bash -x to trace, check with shellcheck, and read the exact failing line and its exit code.
Interview card 10 of 11: How do you debug a failing Bash script? · Download PNG · Open card page

Lesson: 5.10 Debugging scripts without guessing

Why add a dry-run mode? To see what the script would do without changing anything; safer testing and reviews.
Interview card 11 of 11: Why add a dry-run mode? · Download PNG · Open card page

Lesson: 5.11 Lab — health check script with dry-run

Comparison cards

Single vs double quotes in Bash. Quotes group text so spaces don't split it.'single': text exactly as typed."double": variables like $APP are filled in.
Comparison card 1 of 3: Single vs double quotes in Bash · Download PNG · Open card page

Lesson: 5.3 Variables, quotes and exit codes

cron vs a sleep loop. cron: a system service that runs a command on a schedule.sleep loop: a script that runs forever, sleeping between runs.
Comparison card 2 of 3: cron vs a sleep loop · Download PNG · Open card page

Lesson: 5.6 Cron basics — schedule the script

Environment variable vs hardcoded value. Hardcoded: value written inside the script.Environment variable: value given from outside when it runs.
Comparison card 3 of 3: Environment variable vs hardcoded value · Download PNG · Open card page

Lesson: 5.7 Secrets — never hardcode