Tuesday, 16 April 2013

How to List installed perl module


Use instmodsh (interactive inventory for installed Perl modules) command to find out what modules already installed on my system. instmodsh command provides an interactive shell type interface to query details of locally installed Perl modules.
 
To display the list enter the following command:
$ instmodsh

This will show the below options,
 
Available commands are:
l - List all installed modules
m - Select a module
q - Quit the program
cmd?

type l to list all installed modules:cmd? l
Installed modules are:
Archive::Tar
CPAN
Class::Spiffy
Compress::Zlib
Cwd
Digest::SHA
IO::Zlib
MIME::Lite
Module::Build
Module::Signature
Net::Telnet
PAR::Dist
Perl
Spiffy
Term::ReadLine
Test::Base
Test::Simple
Text::Glob
Weather::Com
XML::Simple
YAML
cmd?
 
This command itself is a perl script that use ExtUtils::Installed module. type q to exit.

Thursday, 11 April 2013

Find And Replace Text with VI


Both vi and vim text editor comes with substitute command for finding and replacing text.

Syntax

:%s/WORD-To-Find-HERE/Replace-Word-Here/g
OR
:%s/FindMe/ReplaceME/g

Examples

The substitute command can be used as per your requirements.

VI / Vim Basic Find and Replace

To find each occurrence of 'UNIX', and replace it with 'Linux', enter (press ESC, type : and following command)::%s/UNIX/Linux/g

Find and Replace with Confirmation

Find a word called 'UNIX' and replace with 'Linux', but ask for confirmation first, enter:
:%s/UNIX/Linux/gc

Find and Replace Whole Word Only

Find whole words exactly matching 'UNIX' to 'Linux'; and ask for confirmation too:
:%s/\<UNIX\>/Linux/gc

Case Insensitive Find and Replace

Find 'UNIX' (match UNIX, unix, UnIx, Unix and so on) and replace with 'Linux':
:%s/unix/Linux/gi
Same command with confirmation:
:%s/unix/Linux/gic

Case sensitive Find and Replace

Find each 'UNIX' and replace with 'bar':
:%s/UNIX/bar/gI
Same command with confirmation:
:%s/UNIX/bar/gIc

Replace In the Current Line Only

Find 'UNIX' and replace with 'Linux' in the current line only (note % is removed from substitute command):
:s/UNIX/Linux/g
NOTE: You need to prefix % the substitute command to make changes on all lines:
:%s/UNIX/Linux/g

Replace All Lines Between line 100 and line 250

:{START-n},{END-n}s/word1/word2/g
Find 'UNIX' and replace with 'Linux' all lines between line 100 and line 250, enter:
:100,200s/UNIX/Linux/g
OR
:100,200s/UNIX/Linux/gc

Friday, 8 March 2013

Network File System (NFS)

Features:

  • Transparent access to remote  file system.
  • Uses RPC for communication.
To check the nfs package, run the command:
rpm  -qa | grep  -i nfs
rpm  -ql nfs-utils
chkconfig --list nfs
chkconfig --level 35 nfs on

1.  Export a directory on the server using /etc/exports 

/path_to_directory         IP_ADDR (options)

#mkdir /nfs1
#vi /etc/exports
/nfs1     192.168.198.134(rw)
:wq

Start NFS service
#service nfs start

Confirm exports using exportfs -v
#exportfs -v

2. Export /nfs2

#mkdir /nfs2
a.       Create a entry in /etc/exports
b.      Update current exports using exportfs –a


3.  Mount Both exports on a remote system:

mount  -t nfs 192.168.198.136:/nfs1         /nfs1
mount –t nfs 192.168.198.136:/nfs2         /nfs2


4.   Allow Local root user  the ability to write to /nfs1 exports:

#vi /etc/exports
/nfs1     192.168.198.136(rw, no_root_squash)
:wq
exportfs  -a
exportfs  -v


Then on client system,

#umount /nfs1
#mount -t nfs 192.168.198.136:/nfs1       /nfs1
#mount
# cd /nfs1
#seq 1000 >  test.txt

5. Setup mount point so that they are available upon reboot

Client system
a.       #vi /etc/fstab
192.168.198.136:/nfs1            /nfs1     nfs          defaults
192.168.198.136:/nfs2            /nfs2     nfs          defaults

Unmount and confirm that NFS mount points will be available when the client system changes run level.
#umount  /nfs1
#umount  /nfs2
#mount –a
#df -h


6. Attempt to mount /nfs1 and /nfs2 from an unauthorized system:

Mount –t nfs  192.168.198.136:/nfs1 /nfs1
Fails because client IP does not match server /etc/exports
So , update server /etc/exports to allow additional hosts/subnet/etc

/nfs1     192.168.198.0/24(rw,, no_root_squash)
/nfs2     192.168.198.0/24(ro)

exportfs –a to update export table.