Shell Scripting Workshop: LW
On 24–25th April 2021 I attended a workshop By LinuxWorld Informatics Pvt Ltd on Shell Scripting. In this workshop we learned about scripting from all the basics like writing a basic script, to all the way advance things like writing a script to lock a user based on certain requirements or performing the same over a remote host.
We learned the basics about awk(Aho, Weinberger, Kernighan) command, how can we use it to achieve different things like printing the logs of all the ip that hit a httpd server which were landed on a non existing page. We learnt to create our own functions. we learnt to use SEd command for searching operations. We learnt to use pipe to for I/O redirection. We learnt to use &&, || and ; to connect multiple command with logical ‘and’, logical ‘or’ and just simple sequence without any logic. We also used conditional operators like if-elif-else to check conditions, case to create a command which can serve different things depending upon provided option, and finally getopts to get options passed by the user. We also learned to debug our script with different options like -x, -e, -xe or -v. We also used tr command to transform data to perform ETL operation. We also learnt to use ‘test’ command to test different cases for example [-d /etc/hadoop/] will return code 0 if /etc/hadoop/ directory exists and some other if not.
A shell is an environment in which we can run our commands, programs, and shell scripts.
Bash (Bourne Again Shell) is a shell program that helps to execute the script or programs, bash is an updated version of the sh shell.
A variable is a memory location where it stores some values.
Exit code show the status of program where 0 refers the success and failure or any error is represented by 1 to 255.
Script is the file that consists of set of commands used to automate a particular tasks.
command is a single operation while script contains set of commands
Shebang starts with #!/bin/bash is basically used to refer the path to the interpreter. # is often called sharp and ! is called Bang.
We can parameterize the scripts by using positional parameters $1,$2 and so on.
Live interpreter is Shell or terminal where result of the commands are displayed Migration operator used to transfer files or folders from one place to another. In shell scripting ‘<’, ‘>’ symbols are used for I/O redirection ‘<’ -It is use to take input from the file ‘>’ — It is use to forward output to the file Redirection is the process of moving commands from where they read input to where they send output. To remove parts from each line of input, use the “cut” order. For example, cut -f<Field> -delimiter> file> The ‘read’ keyword helps to take the input. While loop is used when we don’t know about the number of iterations. The current timestamp can be obtained using $(date +%F) ‘/dev/null’ — works like garbage file.