Basic Linux Shell Scripting for DevOps Engineers.

ยท

3 min read

  • What is Kernel?

As a DevOps engineer, let me explain what a "Kernel for DevOps" could mean. In the context of DevOps, a "kernel" refers to a core component or a central part that plays a crucial role in the whole DevOps process. It's like the heart of your DevOps practices, pumping life into your development and operations workflows. ๐Ÿ˜Ž

Think of the kernel as the foundation on which the entire DevOps culture and automation processes are built. It helps streamline collaboration, increase efficiency, and ensures smooth interactions between different teams involved in the software development lifecycle.

Examples of a "Kernel for DevOps" could include:

1. Version Control System (VCS):** Git serves as a vital kernel for DevOps, allowing developers to track changes, work collaboratively, and merge code seamlessly. It's like the "source of truth" for your codebase. ๐Ÿ—‚๏ธ

2. Containerization:** Docker is another kernel that empowers teams to package applications and their dependencies into containers. This ensures consistency across different environments and facilitates easier deployments. ๐Ÿณ

  • What is Linux Shell Scripting?

๐Ÿ˜Ž๐Ÿš Shell scripting for DevOps is like having a magical wand in your hand! ๐Ÿช„ It's all about automating those repetitive tasks that haunt developers and ops teams alike. With a little bit of bash-fu, you can wave away your deployment woes, conjure up server configurations, and cast spells on your CI/CD pipelines! ๐Ÿš€๐Ÿง™โ€โ™‚๏ธ

In a nutshell, shell scripting involves writing scripts in shell languages like Bash, which are executed directly in the command-line interface of Unix-based systems. These scripts are powerful because they can combine multiple commands, conditions, loops, and variables to perform complex operations seamlessly.

For Example: Automating Deployment ๐Ÿšข Imagine you have a web application that needs regular updates. Instead of manually executing each deployment step, we can create a shell script to do it for us!

#! /bin/bash

echo " Starting Deployment "
git pull origin master
npm install
npm run build
pm2 restart my_app
echo "Deployment Successful! "
  • Write a Shell Script that prints I will complete the #90DaysOofDevOps challenge

    as a DevOps engineer, I can help you write a Shell Script to print the statement "I will complete #90DaysOfDevOps challenge".

  • Command: "vim devops_challange.sh" and then type the below-mentioned script

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

    Save the above script in a file named devops_challenge.sh, and then give it executable permissions using the following command

  •   chmod [permission value] devops_challenge.sh
    

To run the script, simply execute:

./devops_challenge.sh

The script will print the statement "I will complete #90DaysOfDevOps challenge" to the console.

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

#!/bin/bash is called a "shebang" or "hashbang." It is a special line at the beginning of a script file in Unix-like operating systems (including Linux) that tells the system which interpreter should be used to execute the script. In this case, #!/bin/bash specifies that the script should be interpreted and executed using the Bash shell

On the other hand, #!/bin/sh specifies that the script should be interpreted using the system's default shell, which is often a POSIX-compliant shell, such as the Bourne shell (sh), Dash (Ubuntu's default /bin/sh since Ubuntu 6.10), or another shell compatible with the POSIX standard.

In summary, yes, you can write #!/bin/sh in your script if you want it to use the system's default shell. If you need specific features or functionalities provided by Bash, then you should use #!/bin/bash.

ย