Thursday, February 24, 2011

How to enable PHP in Apache per user directory configuration on Ubuntu 10.10

   If you want to  do web application development on Ubuntu systems,  enabling per user directory configuration on Apache web server is a good idea.  You can  make a  directory on your home folder visible  to the web server and  view it via web browser.
   Let us start with  apache installation

$ sudo apt-get install apache2

  By default apache serves pages from  /var/www/
If you  invoke on a browser, you can view web pages stored in
/var/www . However , if you want to put a new  html page at /var/www , you need  root access.   You can make a directory in your home folder visible to the server and access this directory via  ( Substitute username with your actual login name.) . For achieving this, do the following steps.
  $ sudo a2enmod userdir
        Enabling module userdir.
        Run '/etc/init.d/apache2 restart' to activate new configuration!

Now restart  apache
$ sudo /etc/init.d/apache2 restart

 Userdir   mod  will  make public_html  folder   in your home directory available on  web server.  You can create public_html   folder in your home folder and develop  your web applications.
    If you are developing  PHP applications , you have to enable php support  for per user directory configuration.
For enabling php,
sudo vi /etc/apache2/mods-available/php5.conf

Look for the lines that look like

and change them to look like:

 then restart apache.
sudo /etc/init.d/apache2 restart


Wednesday, February 16, 2011

System backup with TimeVault

Time vault is a GUI application that can assist  users in taking incremental back up.  Its functionality is similar  to Time/Machine available on Apple MACs

  TimeVault  makes automated  snapshots of (selected parts of) the file system. You can roll back to a previous version  of a file or directory, or just view it the way it was when the snapshot was taken. Snapshots are protected from accidental deletion or modification since they are read-only by default. The super-user can delete intermediate snapshots to save space, but files and directories that existed before or after the deletion will still be accessible

It's also integrates into Nautilus, so you can go the properties page for a snapshot'ed file (right-click in Nautilus and choose properties), and see a 'Previous Versions' tab with a calendar on it.

TimeVault Features include:
 * Automatically saves and recovers data
 * Actively monitors selected folders
 * Automated snapshots
 * Tight integration with Nautilus, the GNOME file manager
 * File-system agnostic
 * Highly configurable
 * Intuitive interface
 * Archive browser

TimeVault Installation and Configuration:
Download the .deb file from here, doubleclick on this file to install TimeVault.
After installing the .deb file, there are two steps required to complete installation:

You must configure TimeVault, the backend will start automatically but the notifier needs to be started: To get the notifier app to start in your systray whenever you log in you can add it to your startup programs in System > Preferences > Startup Applications, you should have an option to add a program click that, name it TimeVault and put:
in the a terminal , you can put whatever you like in the comments box. After you have done this if you log out and back in again you should magically have the TimeVault notifier app sitting in your systray. Right click on it and go to preferences to configure TimeVault as you wish.

Using TimeVault:
There are three tabs: General, Include and Exclude.

Enable Automated Snapshots: By default, TimeVault will not automatically take snapshots of your system. Checking this box will tell it to automatically take daily snapshots.

Show snapshot notifications: This switch toggles on and off whether snapshot notifications are to be shown or not.

Snapshot Root Directory: Where to store the snapshots. Ideally, you should pick a directory that is mounted onto another physical drive from the data you are backing up. This is so that, in the case of a hard-disk failure, the backups will remain intact (unless the drive containing the backups fails, in which case the current version of the data remains).

Make sure you change the settings under Advance to include your largest file, currently it is only set for 32mb. This is not large enough if you have videos as part of a back up. You may consider to back up to a network drive, in the case of total hard drive failure your data will be safe.

Backup paths are listed here. Every directory that you want snapshot should be added to this list.

Paths or patterns to exclude from the snapshots should be listed here.

When you have finished making the necessary changes click the save button and TimeVault should pop up a message saying. You have included new directories in the TimeVault. File signatures will now be computed. Click ok in this box and TimeVault should be active and will start watching your files.

Tuesday, February 15, 2011

Advanced IP subnet calculator sipcalc

      Sipcalc is an advanced console-based IP subnet calculator. It can take multiple forms of input (IPv4/IPv6/interface/hostname) and output a multitude of information about a given subnet.
 On ubuntu,  you can install it from  software center or from the command line.

If you want to calculate the netmask details of, here we go

$  sipcalc
-[ipv4 :] - 0

Host address        -
Host address (decimal)    - 2071690107
Host address (hex)    - 7B7B7B7B
Network address        -
Network mask        -
Network mask (bits)    - 28
Network mask (hex)    - FFFFFFF0
Broadcast address    -
Cisco wildcard        -
Addresses in network    - 16
Network range        - -
Usable range        - -

Any net admin would love this gem.

You can use it on your existing interfaces too.
Here is the sample ipcalc output from my wlan interface

  # sipcalc -d -bcix -n 4 -e -r -t  wlan0

Host address        -
Host address (decimal)    - 3232235778
Host address (hex)    - C0A80102
Network address        -
Network class        - C
Network mask        -
Network mask (hex)    - FFFFFF00
Broadcast address    -

Host address        -
Host address (decimal)    - 3232235778
Host address (hex)    - C0A80102
Network address        -
Network mask        -
Network mask (bits)    - 24
Network mask (hex)    - FFFFFF00
Broadcast address    -
Cisco wildcard        -
Addresses in network    - 256
Network range        - -
Usable range        - -
[Classfull bitmaps]
Network address        - 11000000.10101000.00000001.00000000
Network mask        - 11111111.11111111.11111111.00000000

[CIDR bitmaps]
Host address             - 11000000.10101000.00000001.00000010
Network address        - 11000000.10101000.00000001.00000000
Network mask              - 11111111.11111111.11111111.00000000
Broadcast address    - 11000000.10101000.00000001.11111111
Cisco wildcard        - 00000000.00000000.00000000.11111111
Network range        - 11000000.10101000.00000001.00000000 -
Usable range        - 11000000.10101000.00000001.00000001 -

Network            -     - (current)
Network            -     -
Network            -     -
Network            -     -

Reading E Books with FBReader

  If you are an avid E-book fan FBreader is a cool app for you. FBreader is available  on several platforms.Its main features are,

*  supports several open e-book formats: fb2, html, chm, plucker, palmdoc, ztxt, tcr (psion text), rtf, oeb, openreader, non-DRM'ed mobipocket, plain text, epub

*  reads directly from tar, zip, gzip, bzip2 archives (you can have several books in one archive)

*  supports a structured view of your e-book collection  automatically determines encodings

*  automatically generates a table of contents

*keeps the last open book and the last read positions for all open books between runs

*  automatic hyphenation (patterns for several languages are included)
*  searching and downloading books from and

* partial CSS support for epub files

  FBReader can be downloaded from its website for several platforms. Some of  the supported platforms include

  • Linux

  • Windowa

  • SmartQ 5/7 MID.

  • Nokia 770/N800/N810) Internet Tablet.

  • Sharp Zaurus with Qtopia-based ROindoiM (e.g., original Sharp, Cacko) installed.

  • Sharp Zaurus with pdaXrom installed.

  • Sharp Zaurus with OpenZaurus installed.

  • Siemens Simpad with OpenSimpad 0.9.0.

  • Archos PMA430.

  • PepperPad.

  • Motorola A1200 smartphone.

  • Google Android.

        FBReader   can be installed on  ubuntu from softeware center or from the command line.
    $ su apt-get install fbreader

     Here are some screen shots of FBReader

    Monday, February 7, 2011

    Monitoring performance with time

           The time command is an excellent  tool  for analyzing the performance of a shell script or command. Simply type time followed by the command that you wish to time. Three results are printed when the program or script finishes executing: the actual length of time (real-world time spent on the program), the total time spent in the program, and the total time spent on CPU overhead. The first figure is perhaps the most useful, but the third figure will tell you how busy your CPU is.

    Let us create a small shell script. Type in the following  lines to a text file named

       echo "Welcome to Unixlab "
    Save the file and make it executable.

     $ chmod u+x

    Now run it  using time  
    $ time
    real 0m0.008s
    user 0m0.004s
    sys 0m0.000s
    My machine is too fast to show any perceptible time.
    Now try to expand the  by adding  a for loop as below 
    for i in 1 2 3 4 5 
       echo "Welcome to Unixlab "
    Run it 
    $ time
     Welcome to Unixlab 
    Welcome to Unixlab 
    Welcome to Unixlab 
    Welcome to Unixlab 
    Welcome to Unixlab 
    real 0m0.008s
    user 0m0.004s
    sys 0m0.004s
    Still the real time is shown as 0.00.  Let us build a loop that takes a long
    time to finish and see the difference.
    while [ $x -le 100 ]
      echo "Welcome to Unixlab"
      x=$(( $x + 1 ))
    Again run it.  I am getting the following  timings.
    real 0m0.016s
    user 0m0.012s
    sys 0m0.004s 
       Please read the time man page regarding accuracy of  results and  other 
    useful options.

    Sunday, February 6, 2011

    Searching filesystem from command line

     There are several commands available on the command line to locate files and folders on the file system. This article reviews three of them, viz whereis ,locate. find.

    1) whereis
    This command can search for  the binary, source, and manual page files for a comand

             $ whereis  whereis
                whereis: /usr/bin/whereis /usr/share/man/man1/whereis.1.gz

    2) locate:   locate uses a database created by an updatedb to efficiently locate files. Works great, assuming your database is updated often enough to be reasonable upto date. Most boxes using locate have the updatedb occuring in cron.  On my ubuntu box, I got a long list of files when I tried to locate  command.   RTFM locate

    $locate locate

    3)  find:      find is perhaps one of the most powerful commands there is.   However, find is slow compared to locate as it  recursively search the paths supplied to  it. 

        The syntax of find is specified like this.      
    find path-list expression
    It may look rather cryptic. 
    Even though the man page lists only three  parts for the command as above, 
    for simplicity  we can imagine  that  find  syntax  is havng  four fields.               
    1 2 3 4
    find starting point find which files action on result
    You can formulate your find command based on the above table. For example,
      if you want to find all  avi files in a folder named movies  

    1 2 3 4
    find  movies -name "*.avi"  -print
          $find  movies   -name "*.avi"  -print
    Here are some examples you can try

    a) to find all directories on the system whose permissions of 777

         $   find / \( -type d -a -perm -777 \) -print

    b) find all core files in home directories and remove them

         $    find /home -name core -exec rm {} \;

    c) find all files owned by a particular user no matter whose home directory they are in:

        $  find /home -user -print

    d) find all files that have been modified (or had their modification time changed) in the last 30 days:

           $ find / -mtime -30 -print

    e) find all tmp files older than 30 days and remove:

          $ find /dirpath \( -name \*.tmp -a -mtime +30 \) -exec rm {} \;

    The man page of find has several other option that you can try.

    Saturday, February 5, 2011

    Watch your BIOS settings with dmdeicode and biosdecode

        The Desktop Management Interface (DMI) generates a standard framework  for managing and tracking components in a desktop, notebook or server components , by abstracting these components from the software that manages them. Modern mother boards are compatible with this standard. For a lay user it means that the BIOS settings can be watched from your OS. DMI standards are published by Distributed Management Task Force (DMTF) into desktop-management standards. They also provide a related standard named
     SMBIOS (System Management BIOS ).

      On linux systems , you can watch various system parameters using dmidecode command. You  have to be superuser to display dmi information.


        As you run it, dmidecode will try to locate the DMI table.  It will print a long list of information. A sample entry is shown below.

      Base Board Information
        Manufacturer: Intel Corporation
        Product Name: DG35EC
        Version: AAE29266-205
        Serial Number: BTEC8270055Y
        Asset Tag: Base Board Asset Tag
            Board is a hosting board
            Board is replaceable
        Location In Chassis: Base Board Chassis Location
        Chassis Handle: 0x0007
        Type: Unknown
        Contained Object Handles: 0

    If you look closely , each record has 

           · A handle. This is a unique identifier, which allows records to reference each other. For example, processor records usually reference cache mem‐
             ory records using their handles.

           · A type. The SMBIOS specification defines different types of elements a computer can be made of. In this example, the type is 2, which means that
             the record contains "Base Board Information".

           · A  size.  Each  record  has  a 4-byte header (2 for the handle, 1 for the type, 1 for the size), the rest is used by the record data. This value
             doesn’t take text strings into account (these are placed at the end of the record), so the actual length of the record may  be  (and  is  often)
             greater than the displayed value.

           · Decoded values. The information presented of course depends on the type of record. Here, we learn about the board’s manufacturer, model, version
             and serial number.

      There is also a related command named biosdecode which prints  a shorter description. On my desktop , biosdecode provided

    # biosdecode
    ACPI 1.0 present.
        OEM Identifier: INTEL
        RSD Table 32-bit Address: 0x7F6FD038
    PNP BIOS 1.0 present.
        Event Notification: Not Supported
        Real Mode 16-bit Code Address: F000:AF46
        Real Mode 16-bit Data Address: 0040:0000
        16-bit Protected Mode Code Address: 0x000FAF51
        16-bit Protected Mode Data Address: 0x00000400
        OEM Device Identifier: SST2400
    SMBIOS 2.4 present.
        Structure Table Length: 1551 bytes
        Structure Table Address: 0x000E33F0
        Number Of Structures: 33
        Maximum Structure Size: 152 bytes

    Friday, February 4, 2011

    What is your favorite command on terminal ?

      I  am an avid terminal user and try to work directly on $ prompt as far as possible.  If you are a command line geek, the following command can display  the 10 commands that you use most often.

      $  history | awk '{print $2}' | sort | uniq -c | sort -rn | head -10

    Here is my output.

       73 sudo
         56 ls
         46 cd
         23 ifconfig
         20 dmesg
         11 ps
         10 ssh
         10 lsusb
          9 vi
          8 wget
     If you like this , please post your  list of commands.

    Thursday, February 3, 2011

    Manipulate images with ImageMagick

    Images can be easily manipulated from terminal with image magic package.  On ubuntu systems , imagemagick  can be installed as below.

     sudo apt-get install imagemagick  

    Here are some tricks that I   use with imagemagick.

       1)  Create a thumb nail.

                $ convert screenshot.png   -resize 64x64  resized_sceenshot.png

              if you want to preserve the aspect ratio   put a !  after the size.

                $ convert screenshot.png   -resize 64x64\!  resized_sceenshot.png

          2) Add a border to an image 

                 $ convert screenshot.png  -bordercolor SkyBlue    -border 10x10   screenshot_border.png      

        You can try different  colors and border size
         3)  Convert an image to black & white

              $ convert -type Grayscale screenshot.png  screenshot_bw.png

         4)  Add a label over the image.

               $ convert screenshot.png -gravity south  -stroke '#000C' -strokewidth 2 -annotate 0 ''  -stroke none  -fill white  -annotate 0 ''    screenshot_labelled.png
           5)  Generate labels from text
          $ convert -background lightblue -fill blue \
              -font Candice -pointsize 72 label:Unixlab \

    Imagemagick offers lot of other possibilities . See  this site  for more examples. 


    Wednesday, February 2, 2011

    Head and Tail Commands

    Today we will discuss two commands that we be very helpful when working with large files based on text.   These are the commands head and tail. 
    Sometimes we have to open text files with a considerable size when in fact we see a few lines. 
    For example, a case would be to check a log or an XML file. For example, a case Would Be to check a log or an XML file.
    The head command displays only the first lines of the file. By default show the first 10 lines  We use it like this: We use it like this:
    head file.txt
    Or want to see that many lines, 15 in this example: 
    head -15 file.txt
    To perform the opposite action there is the tail command. What makes the tail is to show the last lines of a file. 
     It is ideal for example to see the latest changes file in a log. By default, like head, display 10 lines:  tail file.txt
    If you wish to view the last 15 lines:  tail -15 file.txt
     Combined with the grep command (to find words in files) head and tail are a great team. 

    How to eject a stuck CD/DVD

      Some times  CD/DVD drives get stuck and will not eject even if  you press the eject button on the front panel.  The is especially true when any application that was  using the CD drive has gone astray.  You can try the following  steps to get out of the situation.

       Open a terminal  and become  root. 

      $ sudo  su

      Try eject  command.

        # eject

      If some application of  is using cdrom you will get a message like

          umount: /media/cdrom: device is busy

     To eject the CD you may have to stop the application.  First,  let us find out who  is using the CD drive.

         #fuser  /media/cdrom
             /media/cdrom:         5929c  6018c  6020c
     You can kill all processes  accessing  using /media/cdrom
            # fuser -km /media/cdrom 
     Then try