Shell Scripting
🔹Scripting is a computer program file containing commands that will execute certain tasks. We can automate stuff using scripts. There are many scripting languages and even we can use python as a scripting language.
🔹We can do automate things with the help of tools such as puppet, chef, Ansible, also using scripting languages.
🔹 We can interact with OS with GUI or CLI. GUI is attractive in Windows environment for easy use of kinds of stuff. But GUI is slow compare to CLI when it compares to certain things. CLI is one more way how we can interact with OS. Linux OS is more often uses CLI for its interaction.
🔹The shell acts as an interface between user and OS which enables us to interact with OS services. Without Shell, we can’t interact with os. Bash shell is the more used shell in a Linux environment. Windows to have Shell called Powershell.
🔹If we have an ’n’ chocolate we would like to store it in someplace. similarly in programming language variable is used to store data values that can be used when it is called or needed for future reference. Variables can be stored in 2 ways user-defined and system-defined.
🔹 Exit code is a type of verification we can do whether our command is executed correctly or not. In Linux, there are 2 ways of Exit coded.
1. If it returns Zero ‘ 0 ‘ then we can say our code is the correct one. It is a successful code.
2. If it returns 1 or more value we can say our code is not correct. There are some errors so this is an unsuccessful one.
🔹 The shebang line is used to specify the absolute path of the program. It starts with #! Symbol. This is always the first line of programming languages such as PHP, Perl, etc.
🔹 Input-output IO redirection refers to guiding our data were to give output and where to get input. This can be achieved using > or < symbol.
🔹 We Can use the cut command to extract any field from data using -d for the specific delimiter and -f for column number, etc.
🔹 We can use the watch command to keep an eye of command which run all time. AWS also uses this command and it is a service called AWS cloud watch.
🔹 With the help of date commands, we can able to add a timestamp.
🔹 The awk command is a powerful command used for analysis and manipulation of data and also generate reports.
🔹 Watch command is used to keep an eye on commands that use regularly. If any kind of unusual behavior is seen we can block certain connections.
🔹Command for getting the total number of false client hits is :
️ $ awk ‘$9 = = 404{ print $0 } ‘ access_log
🔹 Tail command: It is used to display the last set of lines in a file. By default, it displays the last 10 lines. We can set no of lines using the -n option.
🔹 To get filter dd:mm: yy from date output we can use $ date +%d:%m:%y, This helps us to display the data in format dd:mm: yy
🔹 To run multiple commands altogether we can put them in double quotes and separate them using semicolons.
🔹 The command for creating a file without residency is $ touch t{ 1….5}
🔹 Different options available for the awk command are:
️ 1. -F fs to specify a file separator
️2. -f to specify a file that contains awk Script
️ 3. RS to specifies the field separately are some of the commands of AWK
🔹 To search a specific pattern using the awk command is
️ $ awk ‘/pattern /{print}’ filename
🔹 Sed command is stream editor which can be used for search and replace string based on regular expression in a file.
I want to thank Vimal Daga Sir, Preeti Chandak mam and whole LinuxWorld Informatics Pvt Ltd team for coming up with such a great workshop on Shell script from basic to advance use cases .
#ARTH2020
#rightmentor
#righteducation
#Shellscripting
#coretechnologies