Skip to main content

Command Palette

Search for a command to run...

My DevOps Journey: Conquering Automation with Bash Scripting (Milestone 6)

Published
β€’3 min read
My DevOps Journey: Conquering Automation with Bash Scripting (Milestone 6)

Hello everyone, and welcome back to my DevOps and Cloud learning journey! πŸ‘‹

Every path into DevOps eventually arrives at a fundamental skill: automation. For my sixth milestone, I dove headfirst into the powerful tool that makes it all possible: Bash Scripting. This wasn't just about learning commands; it was about learning to make the terminal work for me.

What I Learned: From Variables to Remote Execution

This milestone was packed with foundational concepts that turn simple commands into powerful automations. Here’s a breakdown of the key skills I picked up:

  • The Fundamentals: I started with the basics, from the shebang (#!/bin/bash) to making scripts executable with chmod and running them from the command line.

  • Harnessing Variables: I learned to use standard and system variables (like $USER or $RANDOM) to make my scripts dynamic and reusable.

  • Command Line Arguments: I made my scripts interactive and flexible by learning to process user input with command-line arguments ($1, $2, etc.).

  • Building Logic with Conditionals: Using if-else statements was a game-changer, allowing me to control script flow and make decisions based on specific conditions (e.g., "if a service is down, then restart it").

  • Embracing Repetition with Loops: I used for and while loops to automate repetitive jobs, like creating a batch of new users or processing a list of files.

  • Remote Execution: Finally, I connected everything by using scp to securely copy scripts to remote servers and ssh to execute them, opening up a world of remote management possibilities.

Putting Theory into Practice

To solidify my learning, I focused on hands-on projects that solved real-world problems:

The highlight was creating a fully automated web deployment script. This single script could:

  1. Download a web application from a URL using wget.

  2. Unzip the files.

  3. Deploy them to the Apache (httpd) web server.

I also built a monitoring script that automatically checks if the Apache service is running. If it finds the service has stopped, it restarts it immediately and logs the event. These projects proved just how powerful a few lines of code can be.

Why Bash Scripting is a DevOps Game-Changer

Before this milestone, I saw the server as a place to run commands one by one. Now, I see it as an environment I can control with logic and automation.

Bash scripting is the glue that holds DevOps pipelines together. It empowers you to turn manual, error-prone tasks into reliable, repeatable, and efficient automated workflows.

From provisioning servers to deploying applications and monitoring their health, scripting saves countless hours and ensures consistency every single time.

Check Out the Code

All the scripts I wrote for this milestone, from the simple system monitors to the automated deployment script, are documented and available on my GitHub. Feel free to check them out, use them, or even suggest improvements!

πŸ‘‰ https://github.com/darshan090905/Devops-learning/blob/master/milestone-6/milestone_6_bashscript_doc.md

Thank you for following along! I'll continue sharing my journey milestone by milestone to help other beginners learn in public with me. What are your favorite Bash scripting tricks? Let me know in the comments!