Bash Scripting for DevOps

DevOps

COURSE OVERVIEW


This 10-day intensive course , Bash Scripting for DevOps, focuses on providing the foundational and advanced scripting skills necessary for automating modern infrastructure and delivery pipelines.

The program begins with the core principles of the Linux command line and shell environments, quickly progressing to the creation of robust, automated scripts. Participants will learn to handle complex data using text processing tools like awk and sed, manage system processes, and implement professional error-handling and debugging techniques. The latter half of the course bridges the gap between basic scripting and enterprise operations by integrating Bash into Docker containers and major CI/CD platforms like Azure DevOps and GitLab. To ensure practical mastery, the course includes multiple real-world DevOps Automation Projects, ranging from server health monitoring to automated deployment systems.


Learning Objectives

By the end of this course, participants will be able to:

  • Navigate and Manage Linux Systems: Efficiently use the command line for file operations, permission management, and system navigation.
  • Develop Advanced Bash Scripts: Create structured scripts using variables, conditional logic, loops, and reusable functions.
  • Automate Data Extraction: Master text processing tools such as grep, sed, and awk to extract and manipulate data from logs and configuration files.
  • Implement Professional Error Handling: Utilize exit codes, conditional checks, and debugging modes (set -x) to build resilient automation.
  • Control System Processes: Manage foreground and background processes and utilize job control commands like ps, top, and kill.
  • Integrate with CI/CD Pipelines: Build and maintain automated scripts for build, test, and deployment phases within Jenkins, GitLab, and Azure DevOps.
  • Orchestrate Containers: Automate Docker workflows, including container start-up scripts and health checks.
  • Schedule and Secure Tasks: Configure Cron Jobs for routine automation and apply security best practices to prevent credential exposure.

 

Pre-requisite:

  •   Basic computer science knowledge

COURSE OUTLINE


1. Introduction to Bash and Shell Scripting

1.1 What is a Shell

  • Definition of a shell
  • Role of shell in operating systems
  • Shell vs terminal vs command line

1.2 Introduction to Bash

  • What is Bash
  • History and features
  • Bash vs other shells

1.3 Shell Environments

  • Interactive shell
  • Non-interactive shell
  • Login shell

1.4 Installing and Accessing Bash

  • Using Bash on Linux
  • Using Bash on macOS
  • Using Bash on Windows (WSL)

Example Linux systems:

  • Ubuntu
  • Red Hat Enterprise Linux

 

2. Linux Command Line Basics

2.1 Navigating the File System

  • pwd
  • ls
  • cd

2.2 File Operations

  • cp
  • mv
  • rm
  • mkdir

2.3 Viewing File Contents

  • cat
  • less
  • head
  • tail

2.4 File Permissions

  • chmod
  • chown
  • umask

 

3. Introduction to Bash Scripts

3.1 What is a Bash Script

  • Shell commands vs scripts
  • Use cases of scripts

3.2 Creating Your First Script

Example:

#!/bin/bash

echo "Hello DevOps"

3.3 Script Execution

  • Making scripts executable
  • Running scripts

chmod +x script.sh

3.4 Script Structure

  • Shebang (#!/bin/bash)
  • Comments
  • Command execution

 

4. Variables in Bash

4.1 What is a Variable

  • Variable concept in Bash

4.2 Declaring Variables

Example:

name="DevOps"

4.3 Accessing Variables

echo $name

4.4 Environment Variables

Common variables:

  • PATH
  • HOME
  • USER

4.5 Exporting Variables

export VAR=value

5. Input and Output

5.1 Printing Output

echo "Hello"

5.2 Reading User Input

read username

5.3 Formatting Output

  • escape characters
  • multiline output

6. Bash Operators

6.1 Arithmetic Operators

  • addition
  • subtraction
  • multiplication

6.2 Comparison Operators

  • -eq
  • -ne
  • -gt
  • -lt

6.3 Logical Operators

  • AND (&&)
  • OR (||)
  • NOT (!)

7. Conditional Statements

7.1 if Statements

7.2 if-else Statements

7.3 Nested Conditions

7.4 Case Statements

Example:

8. Loops in Bash

8.1 For Loop

8.2 While Loop

8.3 Until Loop

8.4 Loop Control

  • break
  • continue

9. Bash Functions

9.1 Creating Functions

9.2 Calling Functions

9.3 Function Parameters

9.4 Returning Values

10. Working with Files and Text Processing

10.1 File Handling in Bash

  • reading files
  • writing files

10.2 Text Processing Tools

grep

Search text patterns

awk

Data extraction

sed

Stream editing

cut

Column extraction

sort

Sorting data

11. Process Management

11.1 Understanding Processes

  • foreground processes
  • background processes

11.2 Managing Processes

Commands:

  • ps
  • top
  • kill

11.3 Job Control

  • jobs
  • bg
  • fg

12. Bash Script Arguments

12.1 Passing Arguments to Scripts

Example:

./script.sh file.txt

12.2 Positional Parameters

  • $0
  • $1
  • $2

12.3 Special Variables

  • $#
  • $@
  • $?

13. Bash Error Handling

13.1 Exit Codes

exit 1

13.2 Checking Command Success

if [ $? -eq 0 ]

13.3 Debugging Bash Scripts

set -x

14. Bash Automation for DevOps

14.1 System Administration Automation

Examples:

  • Disk monitoring
  • Service restart
  • Backup scripts

14.2 Log Monitoring

  • Searching logs
  • Alert scripts

14.3 Cron Jobs

Scheduling automation

Example:

crontab -e

15. Bash in CI/CD Pipelines

Automating pipelines in:

  • Azure DevOps
  • GitLab
  • Jenkins

Examples:

  • build scripts
  • deployment scripts
  • testing automation

16. Bash with Containers

16.1 Bash in Docker

Automation with:

  • Docker

Examples:

  • container start scripts
  • container health checks

17. Security Best Practices

  • Secure script writing
  • Avoiding credential exposure
  • Permission management
  • Secure automation pipelines

18. Bash Script Optimization

  • Script performance
  • Efficient loops
  • Parallel execution
  • Resource management

 

20. DevOps Automation Projects

Project 1

Server health monitoring script

Project 2

Automated backup system

Project 3

Log monitoring and alerting

Project 4

Deployment automation script


REGISTER NOW