#day4 - Basic Linux Shell Scripting for DevOps Engineers.

#day4 - Basic Linux Shell Scripting for DevOps Engineers.

What is Kernel?

In Linux, the kernel is the core component of the operating system. It acts as a bridge between the hardware and software layers, managing system resources and providing essential services to other parts of the operating system and applications.

The kernel is responsible for tasks such as process management, memory management, device driver handling, and system security. It provides a set of interfaces or system calls that allow applications to interact with the underlying hardware and access system resources.

Essentially, the kernel serves as the foundation of the operating system, enabling the execution of programs and facilitating communication between software and hardware components in a Linux-based system.

What is Shell?

In Linux, the shell refers to the command-line interface or interpreter that allows users to interact with the operating system. It is a program that takes commands from the user and executes them, acting as a bridge between the user and the operating system kernel.

The shell provides a text-based interface where users can enter commands and receive outputs or perform various operations. It interprets the commands and communicates with the underlying system to carry out the requested actions, such as launching programs, managing files and directories, configuring system settings, and more.

Linux has various shell programs available, with the most common one being called "Bash" (Bourne Again SHell). Other popular shells include "Zsh" (Z Shell) and "Fish" (Friendly Interactive SHell). Each shell has its own set of features and functionalities, but they all serve as powerful tools for interacting with a Linux system via the command line.

What is Linux Shell Scripting?

Shell scripting is a scripting language that is used to automate tasks and procedures in a Unix/Linux environment. It is an important tool for DevOps because it enables the automation of repetitive tasks such as software deployment, configuration management, system monitoring, and log analysis.
Some common tasks that can be automated with shell scripting include:

-Deploying applications to production environments
-Provisioning and configuring servers
-Monitoring system performance and health
-Automating backups and data recovery
-Managing user accounts and permissions
-Running batch jobs and scheduled tasks

Shell scripting can also be used in conjunction with other DevOps tools such as configuration management tools like Ansible, Puppet, or Chef, and continuous integration/continuous deployment (CI/CD) tools like Jenkins.

Overall, shell scripting is an essential tool for DevOps professionals because it enables them to automate repetitive tasks and focus on higher-level strategic work.

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

#!/bin/bash is called a shebang or hashbang, and it is a special syntax that appears at the beginning of a script file. It tells the operating system which interpreter to use for executing the commands in the script. In this case, #!/bin/bash specifies that the commands in the script should be interpreted by the Bash shell.
Yes, it is possible to use #!/bin/sh instead of #!/bin/bash. However, it's important to note that /bin/sh may not always be the same shell as Bash, as it can vary depending on the operating system and distribution. In some cases, /bin/sh may point to a different shell, such as Dash, which may not support all of the features of Bash. If you want to use Bash-specific features in your script, it's better to specify #!/bin/bash to ensure that the script is executed by Bash.

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

Steps:

  • Sign in to the AWS Management Console at console.aws.amazon.com and create an EC2 instance with Ubuntu Server 22.04 AMI

  • Create a shell script with the name devops.sh

  • Edit devops.sh, write the below commands and save the file

  • Provide execute permission to devops.sh file via cmd: chmod 755 devops.sh

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

Steps:

  • Create a shell script with the name input.sh via cmd: touch input.sh

  • Edit input.sh, write the below commands and save the file

  • Provide execute permission to input.sh file via cmd: chmod 755 input.sh

Task#3: Write an Example of If else in Shell Scripting by comparing 2 numbers

Steps:

  • Create a shell script with the name compare.sh via cmd: touch compare.sh

  • Edit compare.sh, write the below commands and save the file

  • Provide execute permission to compare.sh file via cmd: chmod 755 compare.sh

Thanks for Reading!

Keep Learning...