Self reflection post on Shell Scripting
In the workshop, organized by LinuxWorld Informatics Pvt Ltd under the mentorship and guidance of the World Record Holder, Mr. Vimal Daga, I learned the following things:-
Shell scripting is a set of commands that can be run consecutively by writing them in a file and running the file in CLI. It is a kind of automation. There are generally 2 types of OS interfaces: GUI(Graphical User Interface) and CLI(Command Line Interface). GUI interface is a graphics-based interface to operate on OS which is more user-friendly. CLI is a shell command-based interface through which we can interact with OS through respective commands. CLI uses much less compute resources as compared to GUI. Shell is a program available in all the OS which executes a process in both GUI and CLI as per user need. For e.g, Bash is one of the shells usually found in almost all Linux OS. A variable is that which stores the memory location of a particular value in a particular shell program. Types of variables: temporary, pre-defined, and user-defined. Exit code is a code that tells whether a process completion status is successful or failed. A file in which a set of commands are written is called a script.
The hashbang/shebang is used to specify the scripting language of the script. To parameterize a script just pass a variable in the script using the dollar($) symbol and pass the value in the terminal along with the script file name. Migration operation is the process of transferring files from one system to another. I/O redirection is a process that is used to send input or output to any file or to any other user terminal. ‘read’ command is used to take input in the shell. ‘while’ loop is mainly used when we want to iterate a program infinite times. The ‘cut’ command is used to cut any field from any file. ‘(date +%F)’ — It can be used to get the current timestamp in Linux OS.
‘awk’ is a command in Linux which is used to search a specific string in a huge amount of data, almost works like the ‘grep’ command but it is more powerful than ‘grep’. ‘watch’ command in Linux OS enables to run any command in real time, i.e the command keeps on running in the terminal for infinite time. The command for getting the total number of false client hits — “awk ‘$9==404 {print $0}’ access_log | sort | uniq | wc -l”.
The ‘tail’ command is used to get the last 10 lines from 10+ lines of data. To get filter dd:mm:yy from date output — ‘date +%e:%m:%g’. To run multiple commands altogether we need to use the symbols in the CLI terminal : “&& || ;”. Command to create multiple files together — ‘touch td{1..10}.txt’. we can use the following command to sort and count the line the log file: “awk ‘{ print $0 }’ <file name> | sort | wc -l”. To pass the value to the command which requires value on the run time, we need to use the option ‘ — stdin’ along with the command. To search a specific pattern using the awk command we have to run the command: awk ‘/pattern/ { print}’ file.
SED stands for Stream Editor. It can perform the following operations on a text file: replace, insert and delete