Day 4 Task: Basic Linux Shell Scripting for DevOps Engineers
Hello everyone! 👋
I’m excited to share my progress on Day 4 of my DevOps challenge! 🚀
Today’s focus was on Kernel, Shell, and Shell Scripting, fundamental concepts in Linux that play a crucial role in any DevOps journey. These topics are essential for understanding how Linux operates at its core and how to automate tasks efficiently.
Here’s a quick summary of what I learned today:
What is the Kernel?
The kernel is the core component of the Linux operating system, often referred to as the "heart" of the operating system.
It manages system resources such as the CPU, memory, and connected devices.
Acts as a bridge between applications and hardware, ensuring smooth communication and secure operations.
Its primary role is to handle tasks like process management, memory allocation, and device control.
What is the Shell?
The shell serves as the interface between users and the system.
It interprets user commands and executes them at the system level.
Commands can be entered via a command-line shell (e.g., Bash) or through a graphical shell (e.g., GNOME).
Essentially, the shell converts user inputs into instructions that the kernel can process to complete tasks.
What is Linux Shell Scripting?
Shell scripting is a programming language for writing scripts to automate repetitive tasks.
A script is essentially a set of commands written in a file and executed sequentially by the shell.
This approach reduces manual effort, minimizes errors, and improves efficiency by completing operations in less time.
Shell scripting is widely used in DevOps for task automation, deployment pipelines, and system management.
Tasks for Today
Task 1: Explain Shell Scripting for DevOps in Your Own Words with Examples.
→ Shell scripting is a way to write and execute a sequence of commands in a file to automate tasks. For DevOps, it is extremely useful because:
It simplifies task automation, which is a key goal of DevOps.
It plays a vital role in creating CI/CD pipelines.
Example: Writing a script to deploy code automatically, perform backups, or set up environments can save time and reduce human error.
Task 2: What is #!/bin/bash
, and Can We Use #!/bin/sh
Instead?
In shell scripting, #!/bin/bash
is a shebang that indicates the shell to be used for executing the script.
#!/bin/bash
:
Specifies that the script will run using the Bash shell (Bourne Again Shell), which offers advanced features like arrays and string manipulation. Use this when you need Bash-specific functionalities.#!/bin/sh
:
Specifies the use of the sh shell (Bourne Shell), which is more basic and lightweight. Many systems usesh
as a symbolic link to other shells like Dash or Bash. Use this when portability and compatibility are priorities.
Key Difference:
#!/bin/bash
supports advanced features and is ideal for modern Linux systems.#!/bin/sh
is more portable but lacks advanced features.
Task 3 :- Write a Shell Script that prints I will complete #90DaysOfDevOps challenge
.
1️⃣ Create the Script File
Start by creating a file with a
.sh
extension (e.g.,script.sh
).Open the file in edit mode using a text editor.
Begin the script with the shebang
#!/bin/bash
to specify that it should be executed using the Bash shell.
2️⃣ Write the Script
- Add your commands to the file. For example, to print a sentence, use the
echo
command.
3️⃣ Make the Script Executable
By default, the file may have only read and write permissions. To execute the script, you need to grant executable permission using the
chmod
command:700
: Grants read, write, and execute permissions to the owner only.Alternatively, use
chmod 774
script.sh
to allow the group to execute as well, while others have only read permissions.
4️⃣ Run the Script
- Execute the script by typing: ./script.sh
Task 4 :- Write a Shell Script that takes user input, input from arguments, and prints the variables.
Task 5 :- Provide an example of an If-Else statement in Shell Scripting by comparing two numbers.
#DevOpsEngineering #LinuxCommands #TechSkills #CodeNewbie #CloudComputing #ITAutomation #DevOpsTools #LearningPath #OpenSource #TechCommunity #SysAdmin #ITInfrastructure #CodingLife #TechGrowth #BashScripting #CommandLine #ProgrammingJourney #DevOpsCulture