Bash Scripting

Bash Scripting tutorials and beginners guide

How to create an Init script on Centos 6

How to create an Init script on Centos 6In my  last Shell Scripting tutorial, I used “inotifywait” along with rsync to create a real time file syncing script called backup. This script will run till I manually kill it or till I close my terminal, if I run it as a background process. Now I cannot keep my terminal open forever, but I... Read More »

How to use inotify-tools to trigger scripts on filesystem events

How to use inotify-tools to trigger scripts on filesystem eventsIn my last example of Bash if statements we created a backup script which would run “rsync” as per the time set in a cron. But wouldn’t it be nice if we could run our “rsync” script only if there was a change to the files in our directory instead of running a cron every... Read More »

How to display a changing output like top

In my earlier post on linux memory management, I showed you how you can get the exact memory usage of your script by using py_mem.py. This script, without any options will run once and give you the current memory usage of the system. But what if you wanted real time memory usage?, In other words,... Read More »

Advance text processing examples in awk

Advance text processing examples in awkLast week I was reading up on awk and was fascinated by its text processing capabilities despite been written more than 3 decades ago. Let’s take a simple example of awk on the following “/etc/passwd” file. leog:x:502:502::/home/leog:/bin/bash leo:x:506:506::/home/leo:/bin/bash awk:x:911:911::/home/awk:/sbin/nologin This file has fields separated by colons. If I wanted to print only the GID and... Read More »

Bash If statements, Exit Status and Comparison Operators, A beginners guide to bash scripting part 2

Bash If statements, Exit Status and Comparison Operators, A beginners guide to bash scripting part 2In my previous post we looked at a simple bash backup script example, which would sync data between servers using “rsync” and then send us an email. The only problem with this script is if “rsync” fails, we would still get a successful email. Now I am sure you don’t want to find out on... Read More »

A beginner’s guide to bash scripting

A beginner’s guide to bash scriptingA Brief Introduction Bash or Bourne again shell is a replacement to the original unix shell written by Stephen Bourne at Bell Labs. It offers vast improvements over the original shell, which include Integer arithmetic, Indexed arrays, Command line editing, Unlimited command history. Bash scripts are available by default on most Linux distributions. To find... Read More »

Here is How I Built my First RPM

Here is How I Built my First RPMI was building a rpmpackage for Tengine the Dynamic Module loading Nginx fork. As usual since there was a no decent tutorial I decided to write my own. Warning: DO NOT try as root for obvious Reasons First Install the necessary packages. sudo yum install rpm-build sudo yum install redhat-rpm-config Create the rpmbuild directories [userid@hostname... Read More »

What Does echo 1>&2 mean

1 – stdout 2 – stderr This means redirect echo’s output to stderr, with a message on how to use the script, there needs to be exactly three arguments. All error conditions should go to... Read More »

Shell scripting Interview questions

Here are some examples of Shell Scripting interview questions and also shell scripting tips that may help you when you write shell scripts How will you save the output of the TOP command in a file? Use  Top in batch mode top -b -n1 > filename.txt The -b option is for batch mode and the... Read More »

Expect

Dowload expect.pm from ubuntu and install using dpkg packahe manager 1. Expect * a program to control interactive applications o it maybe possible to control interactive applications from other scripting languages as well + python, perl * expect programming is very easy compared to perl! o crackers use expect to try and gain access to... Read More »