Day-4 Basic Linux Shell Scripting for DevOps Engineers

Table of contents

What is Kernal
Kernal is the main component of Linux OS, It is an interface between hardware and processes. The below mentioned taken care of by Kernal
Memory management: Keep track of how much memory is used to store what, and where
Process management: Determine which processes can use the central processing unit (CPU), when, and for how long
Device drivers: Act as mediators/interpreters between the hardware and processes
System calls and security: Receive requests for service from the processes
What is Shell
Shell is the interface of the Kernal, Shell takes input as a command from you and printed the output of the command in a human-readable format.
$ is prompt, which is also called a command prompt. You can type your command by following the prompt. like
$date
What is Linux Shell Scripting?
Shell Scripting is a language and a method to bind multiple sets of commands in a file to perform operations tasks.
- Explain in your own words and examples, what is Shell Scripting for DevOps.
Linux Shell scripting is playing an important role in DevOps engineers can automate repetitive tasks, configure infrastructure, deploy applications, and manage environments.
#!/bin/bash
pwd
ls
What is
#!/bin/bash?
can we write#!/bin/sh
as well?#!/bin/bash informs the system that the shell script is being started. This tells the system that the commands that follow are to be executed by the Bourne again shell. It's called a shebang because the # symbol is called a hash, and the ! symbol is called a bang.
#!/bin/sh indicates the default system shell. Both allow executing the script using the specified shell.
We can use #!/bin/sh also for writing the script.
Write a Shell Script that prints
I will complete #90DaysOofDevOps challenge
1 - Create a file from command line vim first_script.sh ###### Insert below lines in that script and save the file with :wq! !/bin/bash echo "I will complete #90DaysOofDevOps challenge" GoTo the Prompt and execute the script ~$bash first_script.sh #Output of the Script is# ubuntu@ip-172-31-86-23:~/Script$bash first_script.sh I will complete #90DaysOofDevOps challenge
Write a Shell Script to take user input, input from arguments and print the variables.
# Script Name is print_variable.sh# #!/bin/bash # Author : Syed Farhan Naqvi # Script follows here: ### Defining Variable & This line will take input as Argument### name=$1 #This line will Print the Output# echo "I will finish the $name" #Output of the Script is# ubuntu@ip-172-31-86-23:~/Script$ ./print_variable.sh Challenge I will finish the Challenge ubuntu@ip-172-31-86-23:~/Script$
Write an Example of If else in Shell Scripting by comparing 2 numbers
# Script Name is compare_no.sh# #!/bin/bash # Author : Syed Farhan Naqvi # Script follows here: # Defining Variable and it will take input as argument val1=$1 val2=$2 if [ $val1 -eq $val2 ] then echo "Value is equal" else echo "Value is Different" fi #Output of the Script is# ubuntu@ip-172-31-86-23:~/Script$ ./compare_no.sh 2 2 Value is equal ubuntu@ip-172-31-86-23:~/Script$ ./compare_no.sh 2 3 Value is Different
Conclusion:
ππ Congratulations π π π π Now you've gained valuable skills in shell scripting by practicing the basic concept of shell scripts like Print, argument & comparison.
Stay in touch with my latest insights and articles on DevOps and Weblogicπ by following me on Hashnode, LinkedIn (www.linkedin.com/in/syed-farhan-naqvi-06aa5259),
Subscribe to my newsletter
Read articles from Syed Farhan Naqvi directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
