Skip to main content

Command Palette

Search for a command to run...

Day 4 - Unveiling the Power of Shell Scripting in DevOps Journey (30 Nov, 2023)

Updated
2 min read
Day 4 - Unveiling the Power of Shell Scripting in DevOps Journey (30 Nov, 2023)

Tasks

  • Explain in your own words and examples, what is Shell Scripting for DevOps.

  • What is #!/bin/bash? can we write #!/bin/sh as well?

  • Write a Shell Script which prints I will complete #90DaysOofDevOps challenge

  • Write a Shell Script to take user input, input from arguments and print the variables.

  • Write an Example of If else in Shell Scripting by comparing 2 numbers

    Introduction: Embarking on the 90 Days of DevOps challenge has been an exhilarating journey, and today's task takes us into the realm of basic Linux shell scripting. As DevOps engineers, understanding the kernel, the shell, and the art of scripting is fundamental to optimizing system operations and processes.

    Demystifying the Kernel and Shell: At the heart of every operating system lies the kernel, a program with omnipotent control over the system. Complementing the kernel is the shell, a user interface that translates human-readable commands into instructions the kernel comprehends. The shell, initiated when users log in or start a terminal, acts as a command language interpreter.

    1:-Linux Shell Scripting for DevOps: Shell scripting in the context of DevOps is a powerful tool for automating repetitive tasks, streamlining processes, and ensuring efficient management of system resources. DevOps engineers leverage shell scripts to orchestrate workflows, handle configurations, and facilitate seamless integration between development and operations.

    2:-Understanding #!/bin/bash: The shebang #!/bin/bash at the beginning of a shell script informs the system that the script should be interpreted using the Bash shell. Alternatively, #!/bin/sh could be used, but it may invoke a simpler shell interpreter. Choosing Bash provides access to a richer set of features and capabilities.

    3:-Shell Script for #90DaysOfDevOps: Let's dive into a simple shell script that echoes a commitment to completing the #90DaysOfDevOps challenge:

      #!/bin/bash
    
      echo "I will complete #90DaysOfDevOps challenge"
    

  • This concise script encapsulates the determination to succeed in the DevOps journey.

    4:-User Input and Variables in Shell Scripting: Shell scripts can interact with users by accepting input. Here's an example:

      #!/bin/bash
    
      echo "Enter your name:"
      read username
      echo "Hello, $username! Welcome to the DevOps world."
    

  • This script prompts the user for their name, stores it in the variable username, and then greets them.

    5:-If-Else Statements in Shell Scripting: Conditional statements are vital in scripting. Consider the following example:

      #!/bin/bash
    
      echo "Enter two numbers:"
      read num1
      read num2
    
      if [ $num1 -eq $num2 ]; then
        echo "The numbers are equal."
      else
        echo "The numbers are not equal."
      fi
    

  • This script compares two user-input numbers and prints a corresponding message.

More from this blog

DevOps Journey with M Hassan

174 posts

I am writing these blogs because I recently completed a comprehensive DevOps course where I gained in-depth knowledge of the topics mentioned. As I progressed through the course, I realized the importance of having a concise and accessible resource to revise and reinforce my understanding of each topic. Therefore, I decided to create cheat sheets in the form of blog posts. These cheat sheets will not only serve as a handy reference for myself but also benefit others who are also interested in mastering DevOps concepts. By documenting each topic and providing concise explanations, I aim to create a valuable resource that simplifies complex concepts and facilitates hands-on practice. This way, I can solidify my own understanding while helping others on their DevOps journey.