Day 4 Task: Basic Linux Shell Scripting for DevOps Engineers.

What is Kernel

Day 4 Task: Basic Linux Shell Scripting for DevOps Engineers. What is Kernel

ยท

5 min read

In computing, a kernel is a fundamental component of an operating system (OS). It acts as a bridge between the hardware and the software layers, providing essential services for managing system resources, such as CPU, memory, input/output devices, and handling system calls.

The kernel is responsible for various tasks, including: @shuba

  • Tasks of a Kernel:

    • Process Management: Handling running programs (processes). ๐Ÿ”„ Example: Managing multiple apps running on your smartphone.

    • Memory Management: Allocating and managing memory resources. ๐Ÿง  Example: Allocating RAM for running software on a computer.

    • Device Management: Controlling hardware devices like keyboards and printers. ๐Ÿ–จ๏ธ Example: Sending print jobs from a computer to a printer.

    • File System Management: Organizing and accessing files and directories. ๐Ÿ“ Example: Saving and retrieving documents from a computer's hard drive.

    • System Call Interface: Providing functions for applications to interact with the kernel. ๐Ÿ“ž Example: Opening, reading, and closing files in a program.

  • Types of Kernels:

    • Monolithic Kernel: All kernel services run in a single address space. Example: Linux kernel.

    • Microkernel: Only essential services run in kernel space, while others operate in user space. Example: macOS kernel.

Kernels are crucial for the proper functioning of operating systems, facilitating communication between hardware and software components to ensure smooth operation and resource management.

What is Shell

A shell is a command-line interface (CLI) that allows users to interact with an operating system by typing text-based commands. It serves as a user interface for accessing and managing the system's resources and executing various programs.

  • Features of a Shell:

    • Command Execution: ๐Ÿš€ Users can run programs and do tasks by typing commands into the shell. Example: Typing "ls" to list files in a directory.

    • Scripting: ๐Ÿ“œ Allows users to create and run scripts, which are sequences of commands, for automating tasks. Example: Writing a script to backup files automatically.

    • File Management: ๐Ÿ“ Provides commands for working with files and folders like creating, deleting, and moving them. Example: Deleting a file using "rm" command.

    • Input/Output Redirection: โ†”๏ธ Users can direct input and output of commands to/from files or other programs. Example: Saving the output of a command to a text file.

    • Pipeline: โ›“๏ธ Enables chaining commands together, so the output of one command becomes the input of the next. Example: Using "grep" to filter text, then "sort" to arrange it.

    • Customization: ๐Ÿ› ๏ธ Users can customize their shell environment with shortcuts, settings, and themes. Example: Setting an alias for a long command to a shorter one.

  • Types of Shells:

    • Bourne Shell (sh): ๐Ÿš Basic and found on many Unix-like systems.

    • Bash (Bourne Again Shell): ๐Ÿ”„ Default on many Linux distributions, versatile and widely used.

    • Zsh (Z Shell): ๐Ÿš€ Feature-rich with advanced customization options.

    • Fish (Friendly Interactive Shell): ๐Ÿ  User-friendly with modern features like auto-completion and syntax highlighting.

Shells provide users with a command-line interface to interact with their computers, giving them control and flexibility in managing tasks and automating workflows.

Tasks

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

Shell scripting for DevOps means using simple commands to create scripts that make your life easier when working with computers. These scripts help you automate tasks, like setting up servers, deploying software, and keeping an eye on how everything is running. Imagine having a magic wand that can do all these tasks for you with just a wave!

Whether you're working on developing new software, testing it out, or putting it into action for users, shell scripts are like your trusty sidekick, handling all the repetitive work so you can focus on more exciting things.

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

The line #!/bin/bash (called a "shebang" or "hashbang") at the beginning of a shell script tells the system which shell to use to interpret the script. In this case, #!/bin/bash specifies that the script should be executed using the Bash shell.

Yes, you can use #!/bin/sh as well. This shebang tells the system to use the default shell (sh) to interpret the script. It's a more generic approach that ensures compatibility with different Unix-like systems where Bash might not be available or might be located in a different directory.

Both bash and sh are commonly used shells, but bash (Bourne Again Shell) is an extended version of sh (Bourne Shell) with additional features and capabilities. If your script only uses features that are common to both sh and bash, using #!/bin/sh can provide better portability. However, if your script relies on bash-specific features, it's appropriate to use #!/bin/bash.

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

  • First we edit the file 90days.sh with vim editor

  • Copy the script into 90days.sh file and save it with :wq

  • . Make the script executable by running chmod +x 90days.sh.

  • Run the script by typing ./90days.sh in your terminal.

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

  • Open a text editor like Nano or Vim.

  • Copy the script into a new file India.sh

    • Run the script by typing ./India.sh in your terminal.

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

  • Open a text editor like Nano or Vim.

  • Copy the script into a new file.

ย