Shell Scripting For Devops :

Dinesh khadeDinesh khade
2 min read

Shell : Shell is a utility to communicate with kernel .

I am using two types of shell 1. sh 2.bash

Script: A Shells are tools that let us interact with the kernel. I use two types of shells: 1. sh and 2. bash

  • sh: This is a type of shell used for writing scripts.

  • bash (Bourne Again Shell): This is another type of shell, more popular and advanced than sh.

Script: A combination of shell command :

A shell script ends with the .sh extension and starts with a shebang [#!/bin/bash].

  1. Comments: There are two types of comments used in Shell Scripting:

    1. Single Line Comments

    2. Multi-Line Comments

Single line comments start with #, and multi-line comments start with <<name and end with name.

  1. Variables and Constants:

    a=2

    a is a variable, and 2 is a constant. Variables can change, but constants have a fixed value can't change .

Variables: Used to store and manipulate data in scripts. They can be changed and accessed using the $ symbol.

  1. Taking Input From User :

    There are two ways

    1. read variable_name

      #!/bin/bash

      echo "Please enter your name:" read user_name

      echo "Hello, $user_name!"

    2. read -p "Enter your favorite color: " color echo "Your favorite color is $color."

  2. Installing nginx with ShellScript :

  3. Installing Packages With Arguments:

  4. Conditional [if-elif]:

  5. Backups :

    I learned about some following backups :

    1. zip -r <backup-file-name.zip <path/to/script-folder>

      zip: The command used to create a zip archive.

      r: This option stands for "recursive," meaning it will include all files and directories within the specified folder.

      1. Taking backup with passing sources as argument and adding the timestamp.

        i write script for it .

      2. Auto backup for 2min/10min/1hr etc . Using Tool name is cron.

        crontab -e

        learn about this tool deeply on crontab.guru

        * command_to_execute

        Where the five asterisks represent:

        1. Minute (0-59)

        2. Hour (0-23)

        3. Day of Month (1-31)

        4. Month (1-12)

        5. Day of Week (0-6, where 0 is Sunday

  1. Function in ShellScriipting :

    stx:

    function_name() { # commands }

I write ShellScripts for backups, package installation, conditionals, variables, arguments, and nginx installation. You can find all of these on my GitHub account..

Here is the link of github profile :https://github.com/Dinesh-Khade

Here is the Link of Shell Script for Devops repo :https://github.com/Dinesh-Khade/Shell_Scripting-for_Devops.git

0
Subscribe to my newsletter

Read articles from Dinesh khade directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Dinesh khade
Dinesh khade

I am learning about Devops and Devops Tools .