Skip to content
EgyKode
01 · FoundationsLab 5 / 59
Guided lablinux

Bash Automation: A Script You Can Trust

Write a backup script that fails loudly instead of silently, and schedule it so a missed run does not go unnoticed.

Time
40 min
Level
Beginner
Objectives
4 objectives
Cost
Free

Where this fits in the platform

This lab adds

  • A script that fails loudly instead of half-running

Which lets you

Before you start

You will need

  • bash 4+
  • systemd or cron

You do not need these already — the lab environment below provides them.

You will be able to

  • Write a script that stops at the first real error
  • Quote variables so a space cannot become a second argument
  • Exit with codes that CI and systemd can act on
  • Schedule work and detect a run that never happened

CostFree

— no cloud resources

Nothing to pay in the browser. Open the terminal runs this against a simulated cloud — the same API calls and the same commands, with no account and no bill. The figure above applies only if you build it in your own.

The scenario#

There is a backup script on the server. It has 'run successfully' every night for eight months. The backup directory is empty.

It has been exiting 0 the whole time, because nothing in it ever checked whether anything worked.

Hands-on environment

Run this lab in a real terminal, free and in your browser. The environment is temporary and yours alone — break it as much as you like.

Open the terminal

Opens in Killercoda, in a new tab — keep this page open for the steps.

Run it on your own machine

Run this lab on your own machine. One command starts the environment, with everything the lab needs already installed:

You will need:

  • bash
git clone https://github.com/EgyKode/EgyKode-lab.git
cd EgyKode-lab
./egykode start
./egykode shell
ssh node1

You need Docker and Git installed. Everything else runs inside the environment. The first start downloads it and takes a few minutes; later starts are seconds.

Not sure what you already have? Run: npm run doctor — it checks and changes nothing.

Anything you tick here is your own record. EgyKode cannot see inside that terminal, so the success criteria stay self-assessed even when the environment checks your work for you.

The four lines that make a script trustworthy

Step 1 of 3

Success criteria

0 of 4

The concept behind it

Ready to try it without help?Do the challenge

Next up

Lab 5 of 59 on the project path

Git Branching & CollaborationWork a change through a branch, a rebase and a conflict, and recover from the three mistakes everyone makes.45 minBeginner

Previous: Linux Networking & Troubleshooting