Monday 21 December 2015

SNMP installation on Ubuntu

Step 1:
sudo apt-get install snmp snmp-mibs-downloader
this will install the SNMP 

Configuring the SNMP Manager

Open the /etc/snmp/snmp.conf file in your text editor with sudo privileges:
In this file, there are a few comments and a single un-commented line. To allow the manager to import the MIB files, we simply need to comment out the mibs : line:
Save and close the file when you are finished.,
We are now finished configuring the manager portion, but we will still need to use this server to help us configure our agent computer.

Sunday 12 July 2015

LAMP Guide -on Linux Operating System

1. Install Apache

To install Apache you must install the Metapackage apache2. This can be done by searching for and installing in the Software Centre, or by running the following command.
step :
sudo apt-get install apache2

2. Install MySQL

To install MySQL you must install the Metapackage mysql-server. This can be done by searching for and installing in the Software Centre, or by running the following command.
step :
sudo apt-get install mysql-server

3. Install PHP

To install PHP you must install the Metapackages php5 and libapache2-mod-php5. This can be done by searching for and installing in the Software Centre, or by running the following command.
step :
sudo apt-get install php5 libapache2-mod-php5
sudo apt-get install php5-cli
sudo apt-get install php5-mysql


4. Restart Server

Your server should restart Apache automatically after the installation of both MySQL and PHP. If it doesn't, execute this command.
step:
sudo /etc/init.d/apache2 restart

5. Check Apache

Open a web browser and navigate tohttp://localhost/. You should see a message saying It works!


6. Check PHP

php -r 'echo "\n\nYour PHP installation is working fine.\n\n\n";'



This will set up the LAMP on Linux base.

Monday 30 March 2015

CentOS / RHEL Disk space re-sizing / Reallocation


Disk space rallocation in Linux-RHEL/CentoOS

Reducing the size of the /home/ from 500GB to 50GB and allocating it /root
 
scenario :
[root@cloud ~]# df -h /home/
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_cloud-LogVol00
                             12G  9.2G  1.9G  84% /home

Follow the steps :


Step 1:
unmount the the /home

[root@openstack ~]# umount /home/
Step 2:
check the filesystem for Errors using e2fsck command.
[root@openstack ~]# e2fsck -f /dev/mapper/vg_openstack-lv_home
e2fsck 1.41.12 (17-May-2010)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/mapper/vg_openstack-lv_home: 11/3276800 files (0.0% non-contiguous), 251699/13107200 blocks
[root@openstack ~]#
Note: In the above command e2fsck , we use the option '-f' to forcefully check the filesystem , even if the filesystem is clean.

Step 3:
Shrink the size of /home to desire size.
[root@openstack ~]# resize2fs /dev/mapper/vg_openstack-lv_home 50G resize2fs 1.41.12 (17-May-2010) Resizing the filesystem on /dev/mapper/vg_openstack-lv_home to 13107200 (4k) blocks. The filesystem on /dev/mapper/vg_openstack-lv_home is now 13107200 blocks long.
Step 4:
Now reduce the size using lvreduce command.
[root@openstack ~]# lvreduce -L 50G /dev/mapper/vg_openstack-lv_home
  WARNING: Reducing active logical volume to 50.00 GiB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv_home? [y/n]: y
  Reducing logical volume lv_home to 50.00 GiB
  Logical volume lv_home successfully resized
Step 5:
For the safer side , now check the reduced filesystem for errors
 
[root@openstack ~]# e2fsck -f /dev/mapper/vg_openstack-lv_home e2fsck 1.41.12 (17-May-2010) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/mapper/vg_openstack-lv_home: 11/3276800 files (0.0% non-contiguous), 251699/13107200 blocks [root@openstack ~]#


Step 6:  
 Mount the file system and verify the size.



[root@openstack ~]# mount /home/
[root@openstack ~]# df -kh
Filesystem                        Size  Used Avail Use% Mounted on
/dev/mapper/vg_openstack-lv_root   50G  6.0G   41G  13% /
tmpfs                              16G  228K   16G   1% /dev/shm
/dev/sda1                         485M   40M  420M   9% /boot
/dev/mapper/vg_openstack-lv_home   50G  180M   47G   1% /home


Step 7:

Resize the desired partition with required space

lvextend -L 75G /dev/mapper/vg_openstack-lv_root
resize2fs /dev/mapper/vg_openstack-lv_root

check the sze of the partion changes 
df -kh


and you done resizing the partition.

Monday 8 December 2014

Perl Important Tips

Perl  helpfull Trics/Tips:


  1. Get all the Perl module installed via ubuntu/Linux command line

perl -MFile::Find=find -MFile::Spec::Functions -Tlw -e 'find { wanted => sub { print canonpath $_ if /\.pm\z/ }, no_chdir => 1 }, @INC'File::Find and File::Spec::Functions module are used to list all installed modules.
  • -M option loads the module. It executes use module before executing the script
  • -T option enables taint checking, which instructs perl to keep track of data from the user and avoid doing anything insecure with it. Here this option is used to avoid taking the current directory name from the @INC variable and listing the available .pm files from the directory recursively.
  • -l option enables automatic line-ending processing in the output. Print statements will have the new line separator (\n) added at the end of each line.
  • -w option prints any warning messages.
  • -e option indicates that the following string is to be interpreted as a perl script (i.e., sequence of commands).
More simpler Way :

>find / -name \*.pm -type f
to know the pakage related to INC :

find `perl -e 'map {print "$_ "} @INC'` -name \*.pm -type f




2. View Perl Documentation From Unix Command Line

You can use either perldoc or man command to get help about a particular perl module as shown below.
$ perldoc Regexp::Common






(or)

$ man Regexp::Common
If the perl document is not enough, use perldoc option -m,  to view both source code and unformatted pod documentation of the specified perl module.
3.Verify Perl Module Is installed or not ?
Syntax: Perl -M"Module name" 
if it gives not Output i.e indicated that the module is installed, else it show an error stating the module not installed.

4.The flip-flop operator is useful for skipping the first iteration when looping through the records (usually lines) returned by a file handle, without using a flag variable:
while(<$fh>)
{
  next if 1..1; # skip first record
  ...
}

5.The null filehandle diamond operator <> has its place in building command line tools. It acts like <FH>to read from a handle, except that it magically selects whichever is found first: command line filenames or STDIN. Taken from perlop:

while (<>) {
...   # code for each line
}

6.Map 
The map built-in function is one of the most useful tools in your toolkit. map takes a list and applies a code block to every element, returning the list. You can think of it as stream processing: you push the list in one side and get it back on the other side with some transformation applied. Inside the code block, you refer to the current element with the traditional "$_" variable.
Example below demonstrate the function for perl code using map to conver the Uppercase .
my @l = qw(perl php python);
my @uc_l = map { uc($_) } @l;
# Result: PERL PHP PYTHON
7. ||= operator
In Perl, you can use the ||= operator. Its precedence rules are such that it’ll only do an      assignment if the value is false (‘false’ generally means zero, undefined, or the empty string):
$a ||= 5;

Thursday 13 November 2014

Perl interview questions

  1. -c in perl shebang line
  2. # significance in pelr shebacnk line
  3. use strict usage and definition
  4. diff between chop/chomp
  5. . in regex in perl
  6. is perl greedy ? justify
  7. sort an array
  8. uniq element in array ?
  9. sort hash
  10. Difference between referencing /dereferncing in perl
  11. passing hashes in perl using subroutine
  12. what are hashes of hashes
  13. DB connection statement(fetch data) in perl
  14. difference bw fetchrow_array/fetchrow_arrayref/fetchrow_hashref
  15. <> ?
  16. modes in files handling in perl .

Thursday 22 May 2014

Configuring Tomcat for CGI Perl

Configuring CGI  Perl in Apache Tomcat :

Software Requirement:
  • Apache Tomcat 7.0.11 or above
  • JDK 1.6 or above 
  • Perl 5 or above
  1. Download Tomcat. Install or unzip it to some directory.
  2. Modify <TOMCAT_HOME>/conf/web.xml to uncomment the cgi servlet and its mapping
       uncomment:
 
<servlet>
 <servlet-name>cgi</servlet-name>
 <servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class>
 <init-param>
 <param-name>debug</param-name>
 <param-value>0</param-value>
 </init-param>
 <init-param>
 <param-name>cgiPathPrefix</param-name>
 <param-value>WEB-INF/cgi</param-value>
 </init-param>
 <init-param>
 
add the following:
<init-param>
 <param-name>passShellEnvironment</param-name>
 <param-value>true</param-value>
 </init-param>
 
now the CGI blocks look like:
 
 
<servlet>
 <servlet-name>cgi</servlet-name>
 <servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class>
 <init-param>
 <param-name>debug</param-name>
 <param-value>0</param-value>
 </init-param>
 <init-param>
 <param-name>cgiPathPrefix</param-name>
 <param-value>WEB-INF/cgi</param-value>
 </init-param>
 <init-param>
 <param-name>passShellEnvironment</param-name>
 <param-value>true</param-value>
 </init-param>
 <load-on-startup>5</load-on-startup>
</servlet>
 
3: Modify the servlet-mapping 
 
<servlet-mapping>
 <servlet-name>cgi</servlet-name>
 <url-pattern>/cgi-bin/*</url-pattern>
</servlet-mapping>
 
 
4:Modify <TOMCAT_HOME>\conf\context.xml to add a property on <Context>: 
 
<Context privileged="true">
...
</Context>
 
5.Create a cgi folder under <TOMCAT_HOME>/webapps/ROOT/WEB-INF/
 
mkdir <TOMCAT_HOME>/webapps/ROOT/WEB-INF/cgi
 
6. Create the CGI or Pl file under the same directory 
 
 <TOMCAT_HOME>/webapps/ROOT/WEB-INF/cgi/test.cgi
 
#!C:\Perl\bin\perl.exe
# filename: test1.cgi
print "Content-type: text/html\n\n";
print "Hello, world!\n"
 
7. Restart the Apache server
 
 
  
 
 
 
 
 
 


Thursday 15 May 2014

Installing Cpan Module or installin perl Pakage

How to install perl pakage

There are many methods to install perl module or pakage to use in your program:

1. Using CPAN
Install cpan if not installed
to install a module say "Spreadsheet::Read" run the following command:

sudo cpan install module
Example:
sudo cpan install Spreadsheet::Read


2. With the help of the tar or zip file of the package 
follow the following steps:

download the tar of the package required from cpan directory
example for Spreadsheet::Read
go to cpan.org and search the module required.
write click on the tar of the module on the right side of the page and select coppy link location.
come to the terminal and run

1.wget http://search.cpan.org/CPAN/authors/id/H/HM/HMBRAND/Spreadsheet-Read-0.54.tgz
         this will download the package to the current location
extract the package
2.tar -xvzf pakagename
    tar -xvzf Spreadsheet-Read-0.54.tgz
3.cd Spreadsheet-Read-0.54
 on reaching inside the folder extracted run the following command
4.sudo perl Makefile.pl
5.make
6.sudo make install
and following these major steps you can easily install any pakage required.