Search This Blog

Wednesday, June 30, 2010

All About NFS

2)Why to use
3)External source for reading.

1)The Network File System (NFS) is an industry standard.

2)NFS allows entire file systems to be shared among other machines in a network.

3)A very good article about NFS can be found at following location.

Before we talk about the syntax lets make some things clear about nfs.

In NFS architecture there is a Server and client(s).
Server is the one who is having a disk space to share.
Client is the one who want to use space on remote machine.

The syntax for using the mount command to mount remote file system is basically the same as for local file systems.
The difference being that you specify the remote host along with the exported path. For example, if I want to mount the man-pages from, I could do it like this:
First make following path exists in client .
if it doesn't exists then create it.

run following command at client command prompt.
#mount -t nfs [-o options] /usr/man


In following example i m sharing a folder using NFS.

NFS Server:
Make sure nfs service is running.
# service nfs status
rpc.mountd (pid 10428) is running...
nfsd (pid 10425 10424 10423 10422 10421 10420 10419 10418) is running...

I m sharing below folder.

# ls -ltrd /shareddocument/
drwxr-xr-x 2 root root 4096 Jan 25 17:16 /shareddocument/

Command to share the folder to client.

# exportfs client_ip_address:/shareddocument

type exportfs to list shared folders and clients who can share them.

# exportfs
/shareddocument client_ip_address

NFS Client:

Make sure nfs service is running.

Mount the folder

# mount server_ip_address:/shareddocument /shareddocumentonserver

NFS mount using exportfs is well documented in below link.

More on this coming soon.

Tuesday, June 22, 2010

How to trim variable in linux.


use following simple commands to trim it.

# echo $(echo $MACHINE_NAME)

This will cause MACHINE_NAME to contain ABCDF without any white spaces in either left or right sides.

Linux sed command.

In this article for sed command we will deal with below queries.

1)How to delete a line of a file specifying line number?
2)How to change case of letters/characters using sed?
3)How to delete blank lines of files.

How to delete a line of a file specifying line number?

content of temp.txt


We can delete a specific line of file using sed.
For example .
If we need to delete 2nd line of a file temp.txt .
#sed "2d" temp.txt

What if we need to include a variable that defines the line number to be deleted.

#var=2; sed "${var}d" temp.txt

(Note:here sed command doesnt make any changes the actual content of a file instead it is just shows the output after deleting the second line of a file.
For actually deleting the line in a file. you need to generate separate file using the output provided by sed command and then replace it with existing file using mv.)

for example.
above code can be written as.
#var=2; sed "${var}d" temp.txt > tmp.txt
#mv temp.txt tmp.txt
More information and different ways to accomplish the task can be found at.

How to change case of letters/characters using sed?

# cat /tmp/names.txt

# cat /tmp/names.txt |sed 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'

Transliterate the characters in the pattern space which appear in source to the corresponding char-acter in dest.

3)How to delete blank lines of files.

Lets create a file called File1.txt .
# cat File1.txt
Agnes Gonxha Bojaxhiu more commonly known as Mother Teresa

Mother Teresa's Missionaries of Charity at the time of her death had 610 missions in 123 countries including hospices

Notice the two spaces between the lines.
Lets use delete to delete those line(you may use i operator instead of e for modifying the file File1.txt).
# sed -e '/^ *$/d' File1.txt
Agnes Gonxha Bojaxhiu more commonly known as Mother Teresa
Mother Teresa's Missionaries of Charity at the time of her death had 610 missions in 123 countries including hospices

^ (caret) : used for matching the beginning of the line.
$ (dollar sign) : used for matching end of the line.
* (asterisk) : used for matching zero or more occurrences of the previous character ( the previous character in this case is a space).


Awk Programming.

1) Simple Awk commands:

# date
Mon Nov 30 09:46:09 IST 2009

# date | awk '{print $2}'

# date | awk '{print $2 " " $6}'
Nov 2009

# date | awk '{print "Month : " $2 " Year : " $6}'
Month : Nov Year : 2009
2) Awk command with a use of variable:
#Command | awk -v h="$hostname" '{print $0, h}'

Here h is a variable called hostname .
If a ouput of command is
Aaa 111 222
Bbb 333 444
Ccc 444 444
And when you pipe it to awk .
For example.
#Command | awk -v h="$hostname" '{print $0, h}'
The output will be:
Aaa 111 222 hostname
Bbb 333 444 hostname
Ccc 444 444 hostname

Advanced AWK

#xm list" < /dev/null | grep -v Name |awk 'BEGIN {tot=0} "totalvcpu" {tot=tot+$4} END {print tot}'
The above command will sum up 4 column returned by xm list" < /dev/null | grep -v Name and display to total of every value in column 4.
More will be coming soon.

Please Leave us with your comments and Queries/Suggestions.
I will try to reply asap.

Monday, June 21, 2010

FTP setup in Linux

for setting up ftp server you will need vsftpd rpm (OEM OS).

I have got the rpm from OEM 4.7 CD itself (CD 3).

vsftpd rpm is version specific.

vsftpd-2.0.1-6.el4.i386.rpm is suitable for OEM 4.7.

You may get the same rpm

Then i have read following documents for setting up FTP.

This is done so as to provide root to ftp login into system.
We had difficulties from other user logins such as ftp .We were not allowed to change the directories.
So I have setup root to ftp login However it is not recommended for security reasons.

How to add a new repository to Oracle Virtual Server.

Mounting NFS Share as repository.
To make sure which repository is currently exist in the server .
#/opt/ovs-agent-latest/utils/ -l
typically for the first run it won't list anything.

Create a share on storage then add the share as repository.
#/opt/ovs-agent-latest/utils/ -n

You should get something like this.
#/opt/ovs-agent-latest/utils/ -l
c9a30a22-f0c5-435f-8f31-376e95f54107 =>

To make the repository as root .
#/opt/ovs-agent-latest/utils/ -r 86bacbb6-99a4-48e6-b2f9-89598943e16e
[ * ] c9a30a22-f0c5-435f-8f31-376e95f54107 =>

(here [ * ] indicates its a root )

For more detailed information on different options available with

Mounting Local shares as repositories.

#/opt/ovs-agent-2.3/utils/ -n /dev/sda5
#/opt/ovs-agent-2.3/utils/ -n /dev/sdb1
#/opt/ovs-agent-2.3/utils/ -n /dev/sdc1
List the repositories.
#/opt/ovs-agent-2.3/utils/ -l
Make one as root repository.
#/opt/ovs-agent-2.3/utils/ -r a7d5463b-288f-4c14-b28a-5e999c987a29
More on this coming soon.

Difference between ethtool and miitool

ethtool is use widely in the linux distributions.

However miitool is not outdated, but superseded. According to the net, it still can handle some older NICs that ethtool can't.

Sunday, June 20, 2010

How to Partition a Hard Disk In Linux.

Tomcat Installation

Step 1 : Install an Operating System.

Operating System: OEL5.2_32bit
For Default installation you will need first 3 cds namely.


Step2:Install Tomcat, JDK, JRE and define a save point.

We are going to install following softwares in the newly created machines.

Make a folder named install in /.
Copy all the required softwares in /install.

Installation Guide:

I have choosen linux version of tomcat.
For Initial Setup You should always go for
Core version download.
downloaded apache-tomcat-5.5.29.tar.gz
#gunzip apache-tomcat-5.5.29.tar.gz
#tar -xvf apache-tomcat-5.5.29.tar.gz
This will create a new folder as apache-tomcat-5.5.29 in same directory.
go to apache-tomcat-5.5.29/bin

it will not run as java new version is not yet installed.

2) jdk-6u20-linux-i586-rpm.bin:
Next we will install latest jdk version.
#chmod +x jdk-6u20-linux-i586-rpm.bin
#./ jdk-6u20-linux-i586-rpm.bin
This will create a new folder in
use it for JAVA_HOME.

3) jre-6u20-linux-i586-rpm.bin
Next we will install latest jre version.
#chmod +x jre-6u20-linux-i586-rpm.bin
This will create a new folder in
use it for JRE_HOME.

After installation of above mentioned 3 important software its time to take snapshot of the machine.

Step3:Configure java and TOMCAT and define a savepoint.

# javac -version
javac 1.6.0_20
# java -version
java version "1.4.2"
gij (GNU libgcj) version 4.1.2 20071124 (Red Hat 4.1.2-42)

Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO

######At this time java is set to default java in linux our aim is to change it to latest java version.
for setting up this you need root login therefore type


######Then you type

#/usr/sbin/alternatives --install /usr/bin/java java /usr/java/jdk1.6.0_20/bin/java 2

######Finally you type
#;/usr/sbin/alternatives --config java
........ and choose '2'nd option.

Now make sure you disable firewall .

# system-config-securitylevel
Disable the firewall

I have created a script called Tomcat and pasted following content inside it.
# This is the init script for starting up the
# Jakarta Tomcat server
# chkconfig: 345 91 10
# description: Starts and stops the Tomcat daemon.

# Source function library.
. /etc/rc.d/init.d/functions

# Get config.
. /etc/sysconfig/network

# Check that networking is up.
[ "${NETWORKING}" = "no" ] && exit 0

export JAVA_HOME=/usr/java/jdk1.6.0_20

echo -n $"Starting Tomcat service: "
#daemon -c

action $"Stopping Tomcat service: " $shutdown


# See how we were called.
case "$1" in
# This doesn't work ;)
status tomcat
echo $"Usage: $0 {start|stop|status|restart}"
exit 1

exit 0

Edit the lines that start with tomcat and export to match where you installed tomcat and your jdk.

Note: I can't remember where I first got the original version of this script so if you deserve credit for this,

Save the script with name “tomcat” to a location “/etc/init.d”

(at least on most newer releases since /etc/init.d is a standard now). Then you have to allow execute access to the script, so run:

#chmod a+x tomcat
Add to appropriate run level directories

The easy way to do this is to just simply run:

#chkconfig --add tomcat

Add username/Password for tomcat manager:
How to add a new user name to tomcat manager:

just add line number 3 and 6 to /install/apache-tomcat-5.5.29/conf/tomcat-users.xml
xml version='1.0' encoding='utf-8'?>
role rolename="manager"/>
role rolename="tomcat"/>
role rolename="role1"/>
user username="manager" password="tomcat" roles="manager,tomcat"/>
user username="tomcat" password="tomcat" roles="tomcat"/>
user username="both" password="tomcat" roles="tomcat,role1"/>
user username="role1" password="tomcat" roles="role1"/>

Restart tomcat server.
By using service tomcat restart.

To check whether the Tomcat is running or not.

#netstat -ntpl | grep java
tcp 0 0 ::ffff: :::* LISTEN 6375/java
tcp 0 0 :::8009 :::* LISTEN 6375/java
tcp 0 0 :::8080 :::* LISTEN 6375/java

You should see at least one java process and you can use ps to identify if this is Tomcat.

# ps -ef | grep 6375
root 6375 1 0 May18 pts/2 00:01:06 /usr/java/jdk1.6.0_20/bin/java -Djava.util.logging.config.file=/install/apache-tomcat-5.5.29/conf/ -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/install/apache-tomcat-5.5.29/common/endorsed -classpath /install/apache-tomcat-5.5.29/bin/bootstrap.jar -Dcatalina.base=/install/apache-tomcat-5.5.29 -Dcatalina.home=/install/apache-tomcat-5.5.29 org.apache.catalina.startup.Bootstrap start
root 9222 5091 0 18:29 pts/2 00:00:00 grep 6375

Network Ethernet Port Checker

If you want to make sure which physical interface is eth0 and which is eth1 or eth2 and so on


#ethtool -p eth0 20

This blinks the LED on the interface for five seconds–without interrupting network traffic.

#ethtool eth0

This will show the port speed .

A good article over ethtool can be found here.

Friday, June 18, 2010

Add new disk to linux server.

Very Good link to teach how to add new hard disk to existing machine.

In below mentioned article author has added a second hard disk to existing machine and formatted it with the ext3 file system. For the purpose of this example, you need to add a second hard drive in a Red Had Linux system where the drive will be recognized as /dev/hdb or /dev/sdb.

this tutorial will create one partition on newly created hard drive which will be /dev/hdb1 or /dev/sdb1.

schedule script in linux using crontab.

Example 1:
This Example will schedule a job on 12 april at 23:00 Pm on Monday.

run following command in Linux.

#crontab -e

You will get a editor in linux .

just enter following lines into it.
00 23 12 4 mon /usr/local/sbin/

Min Hour day month day (script to be executed)
00 23 12 4 mon /usr/local/sbin/

You can use following command to see what jobs are scheduled in the machine.
crontab -l

At command:
You can use at command to execute the command only once. This is to avoid repetitive execution of command.Even if cron is capable of doing this but it is recommended to execute the command using at if it is supposed to run once .

Nice article over crontab.

Please Leave us with your comments and Queries/Suggestions.
I will try to reply asap.

How to add SSH Keygen

Add keygen to avoid prompting for password while running ssh command.

Type ssh-keygen –t rsa command at Server
When asked to save the file just press enter

[root@ServerHostname .ssh]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
#by default the key is saved in /root/.ssh/id_rsa
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/
The key fingerprint is:
49:66:a2:5f:73:5f:d4:fc:31:24:44:41:32:01:58:58 root@SERVERHOSTNAME

there are two methods to add the key to client choose whichever is suited to you.
Method 1:
Then ssh the file to remote server with the name as authorized_keys.
scp -p /root/.ssh/ root@HOSTNAME:/root/.ssh/authorized_keys
Method 2:
Run following command from Server.
# ssh-copy-id -i /root/.ssh/ root@ClientHOst/IP
enter password for client machine.

Validate :
run SSH clientHOST/IP
You should be able to get the terminal of client without asking for any password.

How to run a command on Other server .

First login to the Client say (A) . Type following command.

ssh –t –t -q date

the above command displays date on Server.

Network Speed Allocation.

ethtool -s eth0 speed 100 duplex full autoneg off

to force the first NIC to operate at fix and non-negotiable speed at 100Mbps full duplex.

Use of scp

Copy a file using scp

# scp DEV_template root@

This will copy DEV_template file to /OVS of machine.

How to list hidden files only.

list only hidden files

ls -a | grep ^"\."

How to list directories only.

To find directories only
(suppose a particular directory contains lot of files and directories and if we want to see only directories then use following command)

ls -l | grep ^d

find . -type d

Regular expression metacharacters
^ = Start of line
so "ls -l | grep ^d" will grep each line of output from ls for lines that begin with d and only d. (it will ignore d in any other position of the line).

Please find My post asking users to list directories only.


How to delete file in Linux

Delete Files

Use rm –rf with folder or file name (Use it very carefully)

How to gather Information about Linux Machine.

With a wide variety of Linux distributions available ,Sometime it becomes very essential to know which OS you are using.

I have listed some important commands to accomplish the task.
Name of distribution
# uname -o
Name of kernel version
# uname -r
Version of OS only 4 redhat
# cat /etc/redhat-release
Enterprise Linux Enterprise Linux AS release 4 (October Update 7)

lsb_release –a ----------------------Very useful

Use following program to determine the name of distribution you are using.

function get_distro_name {
if [[ -r '/etc/lsb-release' ]]; then
. /etc/lsb-release
[[ "$DISTRIB_ID" ]] && n="$DISTRIB_ID"
elif [[ -r '/etc/release' ]]; then
n=`head -1 /etc/release | sed 's/ *\([[^0-9]]*\) [0-9].*/\1/'`
elif [[ -r '/etc/arch-release' ]]; then
n="Arch Linux"
elif [[ -r '/etc/debian_version' ]]; then
elif [[ -r '/etc/gentoo-release' ]]; then
elif [[ -r '/etc/knoppix-version' ]]; then
elif [[ -r '/etc/mandrake-release' ]]; then
elif [[ -r '/etc/pardus-release' ]]; then
elif [[ -r '/etc/puppyversion' ]]; then
n='Puppy Linux'
elif [[ -r '/etc/redhat-release' ]]; then
n='Red Hat'
elif [[ -r '/etc/sabayon-release' ]]; then
elif [[ -r '/etc/slackware-version' ]]; then
elif [[ -r '/etc/SuSE-release' ]]; then
elif [[ -r '/etc/xandros-desktop-version' ]]; then
elif [[ -r '/etc/zenwalk-version' ]]; then
[[ "${n:-}" = '' ]] && \echo "ERROR: Could not determine the distro name" >&2 && \exit 1
echo $n