Day 4 Task: Basic Linux Shell Scripting for DevOps

🚀 Aspiring DevOps & DevSecOps Engineer | Cloud DevOps (Azure & AWS) | Automation & Security Champion | Passionate Learner🌐
Hi, I’m Yuvraj! 🔥 I'm embarking on an exciting journey in the world of DevOps & DevSecOps, armed with hands-on expertise and a drive to excel. From automating tasks to building robust CI/CD pipelines, I’m dedicated to turning complex challenges into efficient and secure solutions.
What I Bring to the Table: ●Linux & Shell Scripting 🖥️ Automating processes and mastering command-line operations.
●Git & Git Branching 🔀 Seamless version control for effective collaboration.
●Build Tools 🔧 (Maven & npm) Crafting stable builds for quality software.
●CI/CD Tools 🚄 (Jenkins, GitHub Actions, Azure DevOps, GitLab CI/CD) Ensuring smooth & automated deployments.
●Security in DevOps 🛡️ Embedding security at every stage to safeguard development processes.
●Artifact Management 📦 (Nexus & Azure Artifacts) Managing software versions efficiently.
●Containerization & Orchestration 🐳⎈ (Docker & Kubernetes) Deploying scalable, agile applications.
●Infrastructure as Code (IaC) 📜 (Terraform & Ansible) Automating environment provisioning.
●Monitoring & Troubleshooting 🔍 Keeping systems in check with proactive issue resolution.
●Real-world & Corporate Projects 🌟 Hands-on experience with practical implementations.
✨ Always eager to learn, collaborate, and innovate! ✨ I’m ready to transform my academic knowledge and project experiences into real-world impact. Let’s connect and explore how we can drive meaningful change together! 🤝
What is Kernel?
The kernel is a computer program that is the core of a computer’s operating system, with complete control over everything in the system. It manages hardware resources such as memory, CPU and i/o devices and provides essential resources for other parts of the system.
Key functions of a kernel
Memory Management: Kernel manages system's memory, to allocate or deallocate memory space as required. It ensures each process has its own memory space.
Process Management: It ensures that each process gets adequate CPU time and resources while maintaining the system. Kernel handles creation, scheduling and termination of processes.
What is Shell?
A shell is a CLI (command line interpreter) that provides an interface for users to interact with operating system services. It accepts human-readable commands from users and converts them into instructions that the kernel can understand.
Types of shells
Command-line Interpreter: It provides a text-based interpreter that allows users to type commands. some types of cli are Bash- Bourne Again Shell, zsh- Z-Shell,
sh- Bourne Shell.
Graphical User Interface: It provides GUI- Graphical User Interface that allows users to interact with the system using graphical elements such as menus, windows and icons.
What is Linux Shell Scripting?
Linux shell scripting involves writing programs (scripts) that can be run by a Linux shell, such as bash (Bourne Again Shell). These scripts automate tasks, perform system administration tasks, and facilitate the interaction between users and the operating system. Wide range of operations performed by shell scripts include file manipulation, program execution, and printing text.
Key concepts of Shell Scripting
Input/Output Redirection- Shell scripts can redirect input and output using operators like
>,<,>>, and|. This allows for chaining of commands and manipulation of data streams.Error Handling- It can handle errors using techniques such as exit status, trapping signals, and conditional checks.
Functions- A function is a block of code that can be defined once and called multiple times within the script. Functions in shell scripts allow for code reuse and modularity.
Variables: Shell scripts can define and use variables to store and manipulate data.
Examples of Shell Scripting Use Cases
Task 1: Explain in your own words and with examples what Shell Scripting means for DevOps.
Shell scripting for DevOps is the use of scripting languages, such as Bash, zsh to automate various tasks and processes involved in the DevOps lifecycle. DevOps, which stands for Development (Dev) and Operations (Ops), is a collaborative approach that integrates software development and IT operations to streamline the software delivery process, improves the quality of software releases.
Task 2: What is #!/bin/bash? Can we write #!/bin/sh as well?
The "#!/bin/bash" line, commonly known as the shebang or hashbang, The line #!/bin/bash at the top of a script indicates the system to run the script using Bash shell, while #!/bin/sh indicates it to use the sh shell.
Key Differences
Bash (
#!/bin/bash):- Uses the Bash shell, which has many advanced features.
sh (
#!/bin/sh):- Uses the
shshell, which is more basic and widely compatible.
- Uses the
Task 3: Write a Shell Script that prints I will complete #90DaysOfDevOps challenge.
#!/bin/bash
echo "I will complete #90DaysOfDevOps challenge."
Task 4: Write a Shell Script that takes user input, input from arguments, and prints the variables.
#!/bin/bash
# Taking user input
read -p "Enter your name: " user_name
# Taking arguments from the command line
arg1=$1
arg2=$2
# Printing the variables
echo "User Name: $user_name"
echo "Argument 1: $arg1"
echo "Argument 2: $arg2"
Task 5: Provide an example of an If-Else statement in Shell Scripting by comparing two numbers.
#!/bin/bash
# Take two numbers as input
read -p "Enter the first number: " num1
read -p "Enter the second number: " num2
# Compare the numbers
if [ $num1 -gt $num2 ]; then
echo "$num1 is greater than $num2"
elif [ $num1 -lt $num2 ]; then
echo "$num1 is less than $num2"
else
echo "$num1 is equal to $num2"
fi


