Shell Scripting

Hello! I'm a student passionate about becoming a Cloud and DevOps Engineer. I have a solid foundation in AWS Cloud, Linux, Docker, and Kubernetes.
Introduction
In the previous blog, we talked about the basics of Linux. This blog is about shell scripting.
Shell scripting is very helpful for automating day-to-day tasks.
For example, if you want to print numbers from 1 to 10, you can simply use the
echo command 10 times. Or, if you want to do a health check of your instance every hour, you can do it manually, but DevOps is about automating, so it is crucial to learn shell scripting.
Writing first Shell-Script
log into your Linux machine whether it is in cloud or you have installed it locally.
Create a file using
touchcommand with extension.shtouch first-shell-script.shcheck the file using
lscommand, or you can usels -ltrto see what arguments one can use with a command or to get information about the command use
manwhich stands for manual. For example you want to know about touch command typeman touchand it will provide all the information about touch command. pressqto quit.Now to write our Script inside the file we just created we need to open it using an editor, we will be using vi editor
type
vi first-shell-script.sh, it opens the file in command mode, then pressiWrite the script.

now let's understand this script -
the first line
!#/bin/bashis Shebang that tells which executable will execute this file as we saw in previous blog that there are different types of shell like sh, zsh, ksh, dash etc.the
echocommand is used to print in the console.after writing the script press
escand then:wq!
esc command will take you out of insert mode and :wq! command will save the file and quit.Now we have to change file permission.
chmod 777 first-shell-script.shwhich will give permission for read, write and execute to owner, file's group member and other.
and then execute the script ./first-shell-script.sh

we got our first script working fine.
Some Important commands for Checking instance
free -m: shows the info about RAM.nproc: list the no. of CPUdf: report file system disk space usagetop: list all the processes and their memory, RAM usage.
Thankyou for reading.



