Breaking News

SED to remove whitespaces.

[root@localhost ~]# cat example.txt

                                   AB BC CD
                                EF FG GH
                                    HI JK LM
                                 NO PQ RS
                                TU VW XY

So we want to look this file as

[root@localhost ~]# cat example.txt

To delete only the whitespaces at the beginning of one single line, use

 # sed -i 's/^ *//' example.txt


# sed "s/^[ \t]*//" -i example.txt
Read more ...

SED to add specific string for the very much first line, beginning of a file.

Sometimes you might have required to add just a specific string at the beginning of a file.

so don't worry our friend SED will help us out.


I have a file named as myweekdays.txt that contains all the weekdays as.

[root@cyberkeeda ~]# cat myweekday.txt


Now i need to simlpy add Weekdays at the beginning of the same file to look it as

[root@cyberkeeda ~]# cat myweekday.txt


SED Command to do.

Check and verify the output using 

[root@cyberkeeda ~]# sed -e ' 1iWeekdays\' imyweekday.txt

Write the orignal file using -i parameter

 [root@cyberkeeda ~]# sed -i -e ' 1iWeekdays\' imyweekday.txt
Read more ...

Bash - Insert data in mysql table from a file using LOAD DATA LOCAL INFILE command.

As every Linux operator loves text file, a text file is enough to process anything within linux using commands.

Today, we will use the power of BASH to insert data into MYSQL table using LOAD DATA LOCAL INFILE commnad from a local text file.

Here i have some data stored into a file named as myfile.txt

Database name - mydb
Table name      - mytable
filename          - myfile.txt

[root@cyberkeeda ~]# mysql -uYOUR_USERNAME -pYOUR_PASS -D mydb -e "load data local infile '/tmp/myfile.txt' into table mytable fields terminated by ',' lines terminated by '\r\n'"

Read more ...

Configuring A High Availability Cluster (Heartbeat) On CentOS

This guide shows how you can set up a two node, high-availability HTTP cluster with heartbeat on

CentOS. Both nodes use the Apache web server to serve the same content.

Pre-Configuration Requirements

1. Assign hostname node01 to primary node with IP address to eth0.

2. Assign hostname node02 to slave node with IP address

Run the commands now...

Note: on node01

#uname –n

must return node01.

On node02

#uname –n

must return node02. is the virtual IP address that will be used for our Apache webserver (i.e., Apache will

listen on that address).


1. Download and install the heartbeat package. In our case we are using CentOS so we will install heartbeat with yum:

#yum install heartbeat

or download these packages:


heartbeat-pils- 2.08

heartbeat-stonith- 2.08

2. Now we have to configure heartbeat on our two node cluster. We will deal with three files. These are:



3. Now moving to our configuration. But there is one more thing to do, that is to copy these files to the /etc/ha.d directory. In our case we copy these files as given below:

#cp /usr/share/doc/heartbeat-2.1.2/authkeys /etc/ha.d/

#cp /usr/share/doc/heartbeat-2.1.2/ /etc/ha.d/

#cp /usr/share/doc/heartbeat-2.1.2/haresources /etc/ha.d/

4. Now lets start configuring heartbeat. First we will deal with the authkeys file, we will use authentication method 2 (sha1). For this we will make changes in the authkeys file as below.

#vi /etc/ha.d/authkeys

Then add the following lines:

auth 2
2 sha1 test-ha

Change the permission of the authkeys file:

chmod 600 /etc/ha.d/authkeys

5. Moving to our second file ( which is the most important. So edit the file with vi:

#vi /etc/ha.d/

Add the following lines in the file:

logfile /var/log/ha-log
logfacility local0
keepalive 2
deadtime 30
initdead 120
bcast eth0
udpport 694
auto_failback on
node node01
node node02

Note: node01 and node02 is the output generated by #uname -n

6. The final piece of work in our configuration is to edit the haresources file. This file contains theinformation about resources which we want to highly enable. In our case we want the webserver (httpd) highly available:

#vi /etc/ha.d/haresources

Add the following line:

node01 httpd

7. Copy the /etc/ha.d/ directory from node01 to node02:

#scp -r /etc/ha.d/ root@node02:/etc/

8. As we want httpd highly enabled let's start configuring httpd:

#vi /etc/httpd/conf/httpd.conf

Add this line in httpd.conf:


9. Copy the /etc/httpd/conf/httpd.conf file to node02:

#scp /etc/httpd/conf/httpd.conf root@node02:/etc/httpd/conf/

10. Create the file index.html on both nodes (node01 & node02):

On node01:

echo "node01 apache test server" > /var/www/html/index.html

On node02:

echo "node02 apache test server" > /var/www/html/index.html

11. Now start heartbeat on the primary node01 and slave node02:

#/etc/init.d/heartbeat start

12. Open web-browser and type in the URL:

It will show node01 apache test server.

13. Now stop the hearbeat daemon on node01:

#/etc/init.d/heartbeat stop

In your browser type in the URL and press enter.

It will show node02 apache test server.

14. We don't need to create a virtual network interface and assign an IP address (

to it. Heartbeat will do this for you, and start the service (httpd) itself. So don;t worry about


Don't use the IP addresses and for services. These addresses are used

by heartbeat for communication between node01 and node02. When any of them will be used

for services/resources, it will disturb hearbeat and will not work. Be carefull!!!

Read more ...

Bash Addition and Subtraction With Variables.

So we gonna find two integers and store them into two variable, so that we gonna use it further to add or subtract.

For Subtraction you can use

COUNT=`expr $value1 - $value2`

For Addition you can sue

COUNT=`expr $value1 + $value2`

Or you can use it 

SUM=$(( $value1 + $value2 ));

SUB=$(( $value1 -  $value2 ));

Read more ...

How to echo output everytime from a new line

Might be it would be a silly post for some, but it could be helpful for those who got this link from google.

So here are few words =, take it as a example.

What i have with me that looks like --    cat  rat mat fat 

Requirement is that i want to use it as 


So A simple trick is just to use /n in the below mentioned manner.

# echo -e "cat\nrat\nmat\nfat" 

Now if you are playing with variables then you just need to add $ , here my variables are simply dep1,dep2,dep3,dep4

# echo -e "$dep1\n$dep2\n$dep3\n$dep4" 

his is really helpful in shell scripts as texts in this manner can be further used in various loops.

Read more ...

Ignore or stop cron mail to users using >/dev/null 2>&1

Crond comes with it's default policy of sending mails to root after the proper execution of cronjobs with given specific interval.
Now take an example, if you have to set a cron job for every 5 minutes, then crond will send emails to root's or user's mail directory the same no of times of mail.
It  means for every successfully cronjob excution it will send a mail and the mail directory keeps on increasing without any notification.

Sometimes it required and sometimes not, so if you don't need those cron mails then use the below mentioned strings after your cronjob entry.

 >/dev/null 2>&1 

Example --: This will stop crond to send mails every minutes

*/5 * * * * /tmp/ >/dev/null 2>&1 

-- Description --

> is for redirect

/dev/null is a black hole where any data sent, will be discarded

2 is the file descriptor for Standard Error

> is for redirect

& is the symbol for file descriptor (without it, the following 1 would be considered a filename)

1 is the file descriptor for Standard Out

Read more ...

Fix Vulnerability -- Apache Web Server ETag Header Information Disclosure

To fix this bug, we have to simply update the apache configuration http.conf file.

To remove the complete Etag info then use FileETag None
To hide only Inode info then use FileETag -INode

By removing the ETag header, you disable caches and browsers from being able to validate files, so they are forced to rely on your Cache-Control and Expires header.
Read more ...

Seq Utility to create specific string with numbers

I have a requirement to create a specific text as


Here one can observe that just the numbers are increasing, yes we can create specific text appended bye each line using SEQ command.

~]# seq -f "harley%02g" 10


Change harley with your own word
Change 10 with your required number.

Now if you don't need to add 0 before your number like 01,02,03 then use the below mentioned command.

]# seq -f "harley%01g" 10


Read more ...

Command to open GUI File Manager window using SSH

So if you too have a requirement for some freak Redhat/Centos GUI lovers and you have the only way to provide the same through SSH, probably it will help you out.

Like if you own a linux workstation there is a Linux Workstation located remotely and VNC access , Vino access is strictly prohibited over there and the only protocol that can be used is SSH, then this is the exactly the post you are looking for.

Here our approach is to toggle remote workstation's directory through GUI File-Manager instead of using cd path/to/some/ditectory

First of all, you need to simply ssh to remote linux Host.

# ssh youruser@10.x.x.x

The moment you logged into the remote host it will provide you the default shell with default location, it varies for all of us.

Now to toggle the directories further graphically, simply run the command gnome-open .

# gnome-open .

The moment you enter it, a pop up window will appear showing the default present folders and file.

  • If you want to toggle the know directory use it.

# gnome-open  /your/own/directory

Hope it will work for you too.

Read more ...

Fix - Amazon Recovery mount XFS file system has duplicate UUID problem (XFS: Filesystem sdc1 has duplicate UUID - can't mount )

While mounting my recovery volume on amazon web services , i found the error
Though i was using all sort of wright commands to mount the XSF filesytem directory.

Finally after checking the dmeg log i sort out that it's the same UUID as it's a backup clone at all.

To fix those things i googled out the command to mount the XFS filesystem without UUID

#mount -o nouuid /dev/sdc1 /mnt/recovery
Read more ...

Protect your website from DDOS attacks using apache modules ( mod_evasive )

Below mentioned apache module is quiet famous in terms of security


mod_evasive works very efficiently, it takes one request to process and processes it very well. It prevents DDOS attacks from doing as much damage. This feature of mod_evasive enables it to handle the HTTP brute forceand Dos or DDos attack. This module detects attacks with three methods.
  1. If so many requests come to a same page in a few times per second.
  2. If any child process trying to make more than 50 concurrent requests.
  3. If any IP still trying to make new requests when its temporarily blacklisted.
Find and un comment the line within your http.conf file to make it as
LoadModule evasive20_module modules/

Read more ...

Protect website from brute force attacks using apache modules ( mod_security )

Below mentioned apache module is quiet famous in terms of security


  • It works as a firewall and it is used to monitor real traffic
  • It protects websites from brute force attack
Install on Redhat/CentOS
       # yum install mod_secuirty
       # service httpd restart

Find and un comment the line within your http.conf file to make it as

LoadModule security2_module modules/


    Read more ...

    Basic Apache Server Hardening

    These are few modules within Apache ( httpd ) daemon which are supposed to be commented with respect to various Security concern

    Don't give away too much information about all the sub components  we are running. Comment out this line if you don't mind remote sites
    finding out what major optional modules you are running and edit or comment it.

    Hide OS and Apache Version

    • ServerTokens OS    

               Make it  ---- ServerTokens Prod

    • ServerSignature On

               Make it  ---   ServerSignature Off

    Disable listing of Directories and Files

    By default Apache Lists all directories within html directory

    Append these lines within http.conf file to disable listing of directories and files

    <Directory /var/www/html>
        Options -Indexes
    Read more ...

    Flush or Clear Varnish Cache without restarting Vanish server

    I believe Linux Folks and developers create a cheat code to apply each effect without restarting the server.
    So on Varnish Server too have a command to flush all cache without restarting at all
    varnishadm -T url.purge .
    That will flush the cache.
    Read more ...

    Varnish Cache Server Configuration

    Varnish is now installed under the /usr/local directory.
    The full path to the main binary is /usr/local/sbin/varnishd.
    The default configuration file is /usr/local/etc/varnish/default.vcl.

    You can start Varnish by running the varnishd binary. Before you can do that though, you have to tell Varnish which back-end server it's caching for. Let's specify the back end in the default.vcl file. Edit the default.vcl file as shown below, substituting the values for those of your Web server:

    Note -:  Important is 1st to Change your Apache's http.conf  Listen port to 8080 

    I assume varnishd is in your path. You might want to run pkill varnishd to make sure varnishd isn't running. Become root and type:

    [root@cyberkeeda etc]# vim /usr/local/etc/varnish/default.vcl

     backend default {
         .host = "";
         .port = "8080";

    # pkill varnishd

    Now you can start Varnish with this command:

    [root@cyberkeeda etc]# /usr/local/sbin/varnishd -f /usr/local/etc/varnish/default.vcl -a :6081 -P /var/run/ -s malloc,256m

    Here Apache is using Varnish Cache using port 6081 -- http:/localhost:6081

    The moment you want to move it under production replace it by port 80

    # pkill varnishd

    [root@cyberkeeda etc]# /usr/local/sbin/varnishd -f /usr/local/etc/varnish/default.vcl -a :80 -P /var/run/ -s malloc,256m

    Now you can directly open --: http://localhost

    If you installed Varnish from your package manager, it may be running already. In that case, you can stop it first, then use the command above to start it manually. Otherwise, the options it was started with may differ from those in this example. A quick way to see if Varnish is running and what options it was given is with the pgrep command:
    /usr/bin/pgrep -lf varnish
    Varnish now will relay any requests it receives to the back end you specified, possibly cache the response, and deliver the response back to the client. Let's submit some simple GET requests and see what Varnish does. First, run these two commands on separate terminals:
    To view communication between Varnish and the client (omitting the back end):
    /usr/local/bin/varnishlog -c
    To view communication between Varnish and the back end (omitting the client):
    /usr/local/bin/varnishlog -b
    To view the headers received by Varnish (both the client's request headers and the back end's response headers):
    /usr/local/bin/varnishlog -i RxHeader
    Same thing, but limited to just the client's request headers:
    /usr/local/bin/varnishlog -c -i RxHeader
    Same thing, but limited to just the back end's response headers:
    /usr/local/bin/varnishlog -b -i RxHeader
    To write all log messages to the /var/log/varnish.log file and dæmonize:
    /usr/local/bin/varnishlog -Dw /var/log/varnish.log
    To read and display all log messages from the /var/log/varnish.log file:
    /usr/local/bin/varnishlog -r /var/log/varnish.log

    Read more ...
    Designed By Kunal Saha