Wednesday, July 18, 2018

How To Troubleshoot When System Drops Into GRUB Rescue Shell

One of my Linux servers (RHEL 7.5) drops into grub rescue shell and had failed to load the operating system. So, I was troubleshooting it and discovered a few steps which could help anyone who is in need, hence, I decided to write this post in my blog site. This post talks about step by step procedure to recover such Linux systems and boot normally. This is tested and re-produced on a virtual system running on VMWare Workstation.

I’m going to document each step with screenshots in this post which would help anyone who wish to recover such failed system.

Sunday, May 13, 2018

Usage Of Functions In Shell Scripting

Benefits of using functions inside shell scripting are:

- Less coding.
- Modular approach.
- Easy to understand.
- Exported as required for portability.
- Easy to expand or edit later.

As mentioned before, we could use functions inside shell scripting whenever required such as when there are set of codes which are common across some shell scripts then those common lines could be grouped into a function and called when required. Like-wise this approach of using functions would provide better readability, which is easier to understand, as well these functions could be amended independently. A group of codes put together to perform a specific task and defined with a name could be called as a function in shell scripting.

Saturday, March 3, 2018

Learn Shell Scripting In One Day

Let’s learn “Shell Scripting". So, in this post I wanted to talk about “What is a shell script?" & "learner guide to shell scripting with examples". Before jumping into learning on how to code and execute shell scripts, let’s talk a bit about “Linux” and history of Linux evaluation.

Linux is technically the kernel, so, there are other utilities such as GNU tools, GCC compiler etc,. which would ideally make a complete operating system (OS). That is the reason it is called GNU (GNUs not Unix) Linux not simply Linux. If I just say Linux then I’m talking about only the kernel.  GNU Linux is one of the widely used OS in market, because it is open-source, so anyone could download/re-use the kernel, publish a new Linux distribution under the guidelines of GPL & Free Software Foundation.

Learn Shell Scripting -- Part 2

Conditional operations using “if…else…fi” statement

We could use “if” statement when it is required to perform a conditional based operation. So, if the condition is true then process a set of commands, otherwise, process some other commands/action. The syntax of this is:

if [ <conditional statement> ]
< statements >    <--------- these statements gets executed if condition is true.
 < statements >   <--------- these statements gets executed if condition fails.

Learn Shell Scripting -- Part 3

Let’s look into some of the commonly used built-in standard shell variables.

In this section we are going to see some of the standard shell built-in variables which we generally use in shell scripting.

#echo $? ---------- this would show the exit status of the previous command run in shell (0 - success, anything other than 0 is considered as failure)
#echo $$ ---------- this shows current shell ID (when run inside a script this would print the PID assigned to
the shell).
#echo $@ OR #echo $* ---------- this prints the arguments passed when called for execution.
#echo $# ---------- this would show up total number of arguments passed.
#echo $! ---------- this would report PID of previous background process.
#echo $_ ---------- this would print last argument being used in the previous command in shell.