Author: Arun Bagul

How to create, copy and burn or write ISO image

How to create, copy and burn or write ISO image

Introduction –

An ISO 9660 is file system for CD-ROM media. Which is published (defined) by the International Organization for Standardization (ISO). ISO image is an archive file (disk image) of an optical disc (like CD) using a conventional ISO 9660 format that is widely supported by many OS and software.

1] How copy  data from ISO image –

I just downloaded opensolaris ISO  image. and wanted copy data from iso image.

step 1) I downloaded the image in /opensolaris  directory

root@arun:/opensolaris# ls -l
total 700768
-rw-r–r– 1 root root 716881920 2008-08-26 06:21 opensolaris-200805.iso
root@arun:/opensolaris#

step 2) mount the ISO image  as  shown below –

root@arun:/opensolaris# mount -o  loop  /opensolaris/opensolaris-200805.iso   /mnt/
root@arun:/opensolaris#

* Check mount point…

root@arun:/mnt# mount  | grep iso
/opensolaris/opensolaris-200805.iso on /mnt type iso9660 (rw,loop=/dev/loop0)
root@arun:/mnt#

step 3) Go to  mounted directory ie /mnt (in my case) –

root@arun:/opensolaris# cd /mnt/
root@arun:/mnt# ls
bin     boot  bootcd_microroot  COPYRIGHT  dev  devices  jack  LICENSE  mnt  platform  proc
reconfigure  root  solarismisc.zlib  solaris.zlib  system  tmp
root@arun:/mnt#

2] How to create ISO image –

a) using dd command  we can create iso image of CD

dd if=/dev/cdrom  of=/tmp/mycdimgage.iso

b) using mkisofs command we can create iso image of our data in any directories

** mkisofs command –

    -R, -rock                               Generate Rock Ridge directory information
    -o FILE, -output FILE             Set output ISO file name
    -l, -full-iso9660-filenames    Allow full 31 character filenames for ISO9660 names
    -max-iso9660-filenames      Allow 37 character filenames for ISO9660 names (violates ISO9660)
    -input-charset CHARSET      Local input character for file name conversion
    -output-charset CHARSET   Output character set for file name conversion

    root@arun:~# mkisofs  -input-charset utf-8  -R -o  /tmp/mycdimage.iso  /mnt/
    1.43% done, estimate finish Sun Oct 10 17:53:05 2008
    2.86% done, estimate finish Sun Oct 10 17:52:30 2008

    ….
    98.56% done, estimate finish Sun Oct 10 17:52:25 2008
    Total translation table size: 0
    Total rockridge attributes bytes: 22651
    Total directory bytes: 159744
    Path table size(bytes): 1024
    Max brk space used 21000
    350039 extents written (683 MB)
    root@arun:~#

    * checking the Size of ISO image of /mnt directory

    root@arun:~# du -sh /tmp/mycdimage.iso
    685M    /tmp/mycdimage.iso
    root@arun:~#

    3] How Burn (copy) ISO image to CD –

    cdrecord is the command line tool to burn or write  iso image file to CD

    ** cdrecord command –

      -v                       Verbose i.e show info while burning the disk
      -dev=0,0,0        Device number
      -multi                 Start multi session disk
      -data                  This option required for HP and Sony CD Writer only.
      -scanbus            scan the SCSI and IDE buses and exit
      -dummy             do everything with laser turned off
      -eject                  Ejects the CD when Done
      -speed=12                  Writing speed (12x )
      -msinfo                        retrieve multi-session info for genisoimage
      timeout=                     set the default SCSI command timeout to
      /tmp/mycdimage.iso   Name of iso image  which to be burned

      * How  to  get Device number ?

      root@arun:~# cdrecord -scanbus
      scsibus3:
      3,0,0   300) ‘MATSHITA’ ‘UJDA775 DVD/CDRW’ ‘1.00’ Removable CD-ROM
      ….
      root@arun:~#

      root@arun:~# cdrecord -dev=3,0,0 -multi -data -v -eject -speed=4 /tmp/mycdimage.iso

      NOTE – above device naming convention doesn’t work in Ubuntu use device  file directly…

      root@arun:~# cdrecord  -dev=/dev/cdrom  -multi -data -v -eject -speed=4 /tmp/mycdimage.iso

      TOC Type: 1 = CD-ROM
      scsidev: ‘/dev/cdrom’
      devname: ‘/dev/cdrom’
      scsibus: -2 target: -2 lun: -2
      Linux sg driver version: 3.5.27
      Wodim version: 1.1.6

      ….
      communication breaks or freezes immediately after that.
      FIFO size      : 12582912 = 12288 KB
      Track 01: data     0 MB         padsize:  242 KB
      Total size:        0 MB (00:04.02) = 302 sectors
      Lout start:        1 MB (00:06/02) = 302 sectors

      root@arun:~#

      ** Hey, just mount the CD and see

      NOTE – Brasero CD burning (http://www.gnome.org/projects/brasero/) – GNOME tool for writing/burning CD is included in Ubuntu 8.04!!

      Thank you,
      Arun Bagul

      How to read MBR (Master Boot Record)

      How to read MBR (Master Boot Record)

      1] What is MBR ?

      Master Boot Record (MBR) is the 512-byte  boot sector (first sector) of a your a Hard Disk Drive (HDD). MBR contains –
      1) Primary Partition table
      2) Boot Loader (GRUB/LILO etc)

      *** Total Size of MBR is 512 byte and which is divided as shown below…

      1) Boot Loader (code) – 446 byte
      2) Primary partion table – 64 byte (16 byte * 4)
      3) Disk signature & others – 6 byte
      4) MBR signature – 2 byte

      2] Disk Partitioning – There are two methods/schemes of Disk partitioning

      a) MBR Partition Table
      b) GUID Partition Table

      When a Hard Disk is partitioned with the MBR Partition Table scheme – MBR contains the primary partition entries. Maximum four (4) primary partition or three (3) primary partition and one extended partition can be created. The partition table entries for other secondary partitions are stored in Extended Partition Table. In extended partition, we can create 128 logical partitions.

      When a Hard Disk is partitioned with the GUID Partition Table scheme – the Master Boot Record will still contain a partition table, but its only purpose is to indicate the existence of the GUID Table

      3] How to read  MBR (Master Boot Record)

      root@indiangnu:/home/arun# dd if=/dev/sda  of=/home/arun/MBR.details bs=512 count=1
      1+0 records in
      1+0 records out
      512 bytes (512 B) copied, 0.00014018 s, 3.7 MB/s
      root@indiangnu:/home/arun#

      root@indiangnu:/home/arun# ls -shl   /home/arun/MBR.details
      4.0K -rw-r–r– 1 root root 512 2008-09-28 17:57 /home/arun/MBR.details
      root@indiangnu:/home/arun#

      ** The size of file is 512 byte and it is in binary format

      command(1) – od

      od command dump files in octal or other format
      # od [options] file_name

      Options
      -a  select named characters, ignoring high-order bit
      -b  select octal bytes
      -c  select ASCII characters or backslash escapes
      -i  select decimal ints
      -x  select hexadecimal 2-byte units

      ** How to convert Binary MBR file data in other format like Hexadecimal format –

      arun@indiangnu:~$ od -x /home/arun/MBR.details
      0000000 48eb d090 00bc fb7c 0750 1f50 befc 7c1b
      0000020 1bbf 5006 b957 01e5 a4f3 bdcb 07be 04b1
      0000040 6e38 7c00 7509 8313 10c5 f4e2 18cd f58b
      0000060 c683 4910 1974 2c38 f674 b5a0 b407 0203
      0000100 00ff 2000 0001 0000 0200 90fa f690 80c2
      0000120 0275 80b2 59ea 007c 3100 8ec0 8ed8 bcd0
      0000140 2000 a0fb 7c40 ff3c 0274 c288 be52 7d7f
      0000160 34e8 f601 80c2 5474 41b4 aabb cd55 5a13
      0000200 7252 8149 55fb 75aa a043 7c41 c084 0575
      0000220 e183 7401 6637 4c8b be10 7c05 44c6 01ff
      0000240 8b66 441e c77c 1004 c700 0244 0001 8966
      0000260 085c 44c7 0006 6670 c031 4489 6604 4489
      0000300 b40c cd42 7213 bb05 7000 7deb 08b4 13cd
      0000320 0a73 c2f6 0f80 ea84 e900 008d 05be c67c
      0000340 ff44 6600 c031 f088 6640 4489 3104 88d2
      0000360 c1ca 02e2 e888 f488 8940 0844 c031 d088
      0000400 e8c0 6602 0489 a166 7c44 3166 66d2 34f7
      0000420 5488 660a d231 f766 0474 5488 890b 0c44
      0000440 443b 7d08 8a3c 0d54 e2c0 8a06 0a4c c1fe
      0000460 d108 6c8a 5a0c 748a bb0b 7000 c38e db31
      0000500 01b8 cd02 7213 8c2a 8ec3 4806 607c b91e
      0000520 0100 db8e f631 ff31 f3fc 1fa5 ff61 4226
      0000540 be7c 7d85 40e8 eb00 be0e 7d8a 38e8 eb00
      0000560 be06 7d94 30e8 be00 7d99 2ae8 eb00 47fe
      0000600 5552 2042 4700 6f65 006d 6148 6472 4420
      0000620 7369 006b 6552 6461 2000 7245 6f72 0072
      0000640 01bb b400 cd0e ac10 003c f475 00c3 0000
      0000660 0000 0000 0000 0000 a328 228b 0000 0180
      0000700 0001 fe07 ffff 003f 0000 1637 0271 0000
      0000720 ffc1 fe07 ffff 1676 0271 0d7a 0177 fe00
      0000740 ffff fe83 ffff 23f0 03e8 f10c 0002 0000
      0000760 ffc1 fe05 ffff 14fc 03eb cfc5 0565 aa55
      0001000
      arun@indiangnu:~$

      ** you can also use following command

      arun@indiangnu:~$ od -ax /home/arun/MBR.details

      Thank you,
      Arun Bagul

      TATA Indicom datacard (Huawei cdma) on Linux/Ubuntu!!

      TATA Indicom datacard (Huawei cdma) on Linux/Ubuntu!!

      Introduction –  Two days back I brought TATA Indicom datacard! As I am Ubuntu user. I wanted to use this datacard on Ubuntu Linux!  PPP is the Point to Point protocol used for establishing internet links over dial-up modems, DSL connections, and many other types of point-to-point links. The pppd daemon works together with the kernel PPP driver to establish and maintain a PPP link with another system (called the peer) and to  negotiate Internet Protocol (IP) addresses for each end of the link. pppd daemon can also authenticate the peer and/or supply authentication information to the peer.

      What you need to use Tataindicom datacard on Ubuntu Linux ?

      make sure that two kernel module ie ‘usbserial‘ and ‘usbcore‘ are loaded!

      root@arun:~# modinfo usbserial
      filename:       /lib/modules/2.6.24-16-generic/kernel/drivers/usb/serial/usbserial.ko
      license:        GPL
      description:    USB Serial Driver core
      author:         Greg Kroah-Hartman, greg@kroah.com, http://www.kroah.com/linux/
      srcversion:     FE4A4FC2C18B17DDD77E8C6
      depends:        usbcore
      vermagic:       2.6.24-16-generic SMP mod_unload 586
      parm:           vendor:User specified USB idVendor (ushort)
      parm:           product:User specified USB idProduct (ushort)
      parm:           debug:Debug enabled or not (bool)
      root@arun:~#

      root@arun:~# modinfo usbcore
      filename:       /lib/modules/2.6.24-16-generic/kernel/drivers/usb/core/usbcore.ko
      license:        GPL
      srcversion:     E8DACA0029626C336D1A513
      alias:          usb:v*p*d*dc*dsc*dp*ic09isc*ip*
      alias:          usb:v*p*d*dc09dsc*dp*ic*isc*ip*
      depends:
      vermagic:       2.6.24-16-generic SMP mod_unload 586
      parm:           usbfs_snoop:true to log all usbfs traffic (bool)
      parm:           blinkenlights:true to cycle leds on hubs (bool)
      parm:           old_scheme_first:start with the old device initialization scheme (bool)
      parm:           use_both_schemes:try the other device initialization scheme if the first one fails (bool)
      parm:           autosuspend:default autosuspend delay (int)
      root@arun:~#

      * To use datacard (which is ppp link) you need to install two packages ie ppp daemon and wvdial as dialer!

      root@arun:~# dpkg -l | grep  wvdial
      ii  wvdial                                     1.60.1                             PPP dialer with built-in intelligence
      root@arun:~# dpkg -l | grep  ppp
      ii  ppp                                        2.4.4rel-9ubuntu2                  Point-to-Point Protocol (PPP) daemon
      ii  pppconfig                                  2.3.17ubuntu1                      A text menu based utility for configuring pp
      ii  pppoeconf                                  1.17ubuntu1                        configures PPPoE/ADSL connections
      root@arun:~#

      on Ubuntu you need to install above packages

      How to configure ? –

      ” wvdialconf ” command is available on Ubuntu, which will  detect you modem and it’s related stuff  and  this command will generate or updates the configuration file “/etc/wvdial.conf

      root@arun:~# wvdialconf
      root@arun:~#

      * After running above command just update user name and password in “/etc/wvdial.conf” configuration file

      root@arun:~# cat /etc/wvdial.conf

      [Dialer Defaults]
      Init1 = ATZ
      Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
      Modem Type = Analog Modem
      Phone = Phone_number like (#xxx)
      ISDN = 0
      Username = USERNAME
      Password = PASSWORD
      New PPPD = yes
      Modem = /dev/ttyUSB0
      Baud = 9600
      root@arun:~#

      ** you can also edit this file manually just refer the man pages for more details!

      root@arun:~# man wvdialconf
      root@arun:~# man wvdial.conf

      arun@arun:~$ man wvdial

      root@arun:~# cat /etc/wvdial.conf

      [Dialer TataIndicom]
      Stupid Mode = 1
      Inherits = Modem0
      New PPPD = yes
      Phone = Phone_number like (#xxx)
      Username = USERNAME
      Password = PASSWORD

      [Modem0]
      Init1 = ATZ
      SetVolume = 0
      Modem Type = Analog Modem
      Modem = /dev/ttyUSB0
      Dial Command = ATDT
      Baud = 115200 or 9600 (depends on support)
      FlowControl = Hardware (CRTSCTS)

      root@arun:~#

      ** How to use it or dial!!

      1) Now it’s time to check your luck! If you are using default conf file created by ” wvdialconf ” command just use below command…

      root@arun:~#  wvdial > /var/log/tataindicom.log  2>&1  &

      OR
      root@arun:~# wvdial

      …..
      root@arun:~#

      root@arun:~# tail -f /var/log/tataindicom.log
      OK
      –> Sending: ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
      ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
      OK
      –> Modem initialized.
      –> Sending: ATDT#***
      –> Waiting for carrier.
      ATDT#777
      CONNECT 230400
      –> Carrier detected.  Waiting for prompt.

      –> Don’t know what to do!  Starting pppd and hoping for the best.
      –> Starting pppd at Sat Jun 20 21:56:51 2008
      –> Pid of pppd: 7152
      –> Using interface ppp0
      –> pppd: X�[06][08]��[06][08]
      –> local  IP address 219.80.X.X
      –> pppd: X�[06][08]��[06][08]
      –> remote IP address 173.B.C.D
      ….
      …..
      root@arun:~#

      2) If you have manually edited your conf file as shown above then use below command

      root@arun:~#  wvdial TataIndicom
      ..
      ….
      root@arun:~#

      ** Now check ppp0 interface is available

      root@arun:~# ifconfig
      eth0      Link encap:Ethernet  HWaddr XX:XX:XX:XX:XX:XX
      UP BROADCAST MULTICAST  MTU:1500  Metric:1
      RX packets:4 errors:0 dropped:0 overruns:0 frame:0
      TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000
      RX bytes:256 (256.0 B)  TX bytes:492 (492.0 B)
      Base address:0x4020 Memory:e4600000-e4620000

      ppp0      Link encap:Point-to-Point Protocol
      inet addr:219.80.X.X  P-t-P:173.B.C.D  Mask:255.255.255.255
      UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1400  Metric:1
      RX packets:1574 errors:1 dropped:0 overruns:0 frame:0
      TX packets:1644 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:3
      RX bytes:556116 (543.0 KB)  TX bytes:179325 (175.1 KB)

      lo        Link encap:Local Loopback
      inet addr:127.0.0.1  Mask:255.0.0.0

      …..

      root@arun:~#

      root@arun:~# route
      Kernel IP routing table
      Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
      173.B.C.D       *               255.255.255.255 UH    0      0        0 ppp0
      default         *               0.0.0.0         U     0      0        0 ppp0
      root@arun:~#

      ** Check pppd daemon and how to start/stop/status the connection ?

      root@arun:~# /etc/init.d/tataindicom 
      Usage: /etc/init.d/tataindicom {start|stop|status}
      root@arun:~#

      root@arun:~# /etc/init.d/tataindicom   start
      Starting the TATA Indicom datacard service..
      log file is /var/log/tataindicom.log

      Done.
      root@arun:~#

      root@arun:~# /etc/init.d/tataindicom   status
      TATA Indicom datacard –
      Dailer :: 7144    /usr/bin/wvdial
      pppd daemon :: 7152   /usr/sbin/pppd  9600 modem crtscts defaultroute usehostname -detach user internet noipdefault call wvdial usepeerdns idle 0 logfd 6
      root@arun:~#

      root@arun:~# /etc/init.d/tataindicom  stop
      killing pppd daemon and dailer…

      Done.
      root@arun:~#

      command(1) pppd  – point to point daemon

      Frequently used options –
      ttyname
      Use the serial port called ttyname to communicate with the peer.  If ttyname does not begin  with  a  slash  (/),  the  string  “/dev/”  is
      prepended  to  ttyname to form the name of the device to open.  If no device name is given, or if the name of the terminal connected to the
      standard input is given, pppd will use that terminal, and will not fork to put itself in the background.

      speed  An  option  that  is  a  decimal number is taken as the desired baud rate for the serial device.

      crtscts
      Specifies that pppd should set the serial port to use hardware flow control using the RTS and CTS signals in the RS-232 interface.  If nei‐
      ther  the  crtscts,  the nocrtscts, the cdtrcts nor the nocdtrcts option is given, the hardware flow control setting for the serial port is
      left unchanged.  Some serial ports (such as Macintosh serial ports) lack a true RTS output. Such serial ports use this  mode  to  implement
      unidirectional  flow control. The serial port will suspend transmission when requested by the modem (via CTS) but will be unable to request
      the modem to stop sending to the computer. This mode retains the ability to use DTR as a modem control line.

      defaultroute
      Add a default route to the system routing tables, using the peer as the gateway, when IPCP negotiation  is  successfully  completed.   This
      entry is removed when the PPP connection is broken.  This option is privileged if the nodefaultroute option has been specified.

      usehostname
      Enforce  the  use  of the hostname (with domain name appended, if given) as the name of the local system for authentication purposes (over‐
      rides the name option).

      call name
      Read additional options from the file /etc/ppp/peers/name.  This file may contain privileged options, such as noauth, even if pppd  is  not
      being  run  by  root.   The  name  string  may  not  begin with / or include .. as a pathname component

      noipdefault
      Disables the default behaviour when no local IP address is specified, which is to determine (if possible) the local  IP  address  from  the
      hostname.   With  this option, the peer will have to supply the local IP address during IPCP negotiation (unless it specified explicitly on
      the command line or in an options file).

      nodetach
      Don’t detach from the controlling terminal.  Without this option, if a serial device other than the terminal on the standard input is spec‐
      ified, pppd will fork to become a background process.

      usepeerdns
      Ask the peer for up to 2 DNS server addresses.  The addresses supplied by the peer (if any) are passed to the /etc/ppp/ip-up script in  the
      environment  variables  DNS1  and  DNS2,  and  the  environment  variable  USEPEERDNS  will  be set to 1.  In addition, pppd will create an
      /etc/ppp/resolv.conf file containing one or two nameserver lines with the address(es) supplied by the peer.

      user USERNAME
      Sets the name used for authenticating the local system to the peer to name.

      idle N Specifies that pppd should disconnect if the link is idle for N seconds.  The link is idle when no data packets (i.e. IP packets) are being
      sent or received.  Note: it is not advisable to use this option with the persist option without the demand option.

      logfd N
      Send log messages to file descriptor N.  Pppd will send log messages to at most one file or file descriptor (as well  as  sending  the  log
      messages  to syslog), so this option and the logfile option are mutually exclusive.  The default is for pppd to send log messages to stdout
      (file descriptor 1), unless the serial port is already open on stdout.

      root@arun:~# cat  /etc/ppp/peers/wvdial
      noauth
      name wvdial
      usepeerdns
      root@arun:~#

      ** Want to see the code  of “/etc/init.d/tataindicom” ?

      root@arun:~# cat /etc/init.d/tataindicom
      #!/bin/bash

      case “$1” in

      start)
      echo “Starting the TATA Indicom datacard service..”
      /usr/bin/wvdial > /var/log/tataindicom.log 2>&1  &
      echo “log file is /var/log/tataindicom.log”
      echo “…”
      echo “Done.”
      ;;

      stop)
      echo “killing pppd daemon and dailer…”
      kill -9 $(ps auxwww  |  grep “$(which wvdial)”  | grep -v grep | awk  ‘{print $2}’)
      kill -9 $(ps auxwww  |  grep “$(which pppd)”  | grep -v grep | awk  ‘{print $2}’)
      echo “…”
      echo “Done.”
      ;;
      status)
      echo “TATA Indicom datacard -”
      pid_of_dailer=$( ps auxwww  |  grep “$(which wvdial)”  | grep -v grep | awk  ‘{print $2}’)
      pid_of_pppd=$(ps auxwww  |  grep “$(which pppd)”  | grep -v grep | awk  ‘{print $2}’)
      pppd_details=”$(ps auxwww | grep “$(which pppd)” | grep -v grep   | awk -F’pppd’  ‘{print $2}’)”
      echo -e “Dailer :: $pid_of_dailer    $(which wvdial)”
      echo -e “pppd daemon :: $pid_of_pppd   $(which pppd) $pppd_details”
      ;;
      *)
      echo “Usage: /etc/init.d/tataindicom {start|stop|status}”
      exit 1
      esac
      exit 0
      root@arun:~#

      Thank you,
      Arun Bagul

      Array and Bash shell

      Array and Bash shell

      Introduction – Array is one of the best feature of Bash shell and  I am fan of this feature!!. Bash shell provides one-dimensional array. Any variable may be used as an array. There are many ways to declare array. Builtin “declare” command is used to explicitly declare an array. There is no maximum limit on the size of an array, nor any requirement that members be indexed or assigned contiguously. Arrays are indexed using integers and are zero-based. A array is created automatically if any variable is assigned to using the syntax array_name[subscript]=value. The subscript is treated as an arithmetic expression that must evaluate to a number greater than or equal to zero.  To explicitly declare an array, use “declare  -a  name“. “declare -a name[index]” is also accepted and the “index” is ignored here.

      Arrays are assigned to using compound assignments of the form array_name=(value1,value2, … valueN), where each value is of the form [index]=string. Only string  is required. In bash array indexing is same as C language which starts at zero. This syntax is also accepted by the declare builtin.

      * How to assign/declare array variable in Bash shell –

      declare -a myarr[0]=”Arun”
      declare -a  my_array
      my_array=(Arun Bagul Bangalore Mumbai Raju Santhosh Ravi)
      apna_array=([0]=arun [1]=bagul [4]=Santhosh [3]=ravi [5]=1024)
      array[1]=”Bagul”

      * How to refer the array and it’s element –

      Suppose I want to print the above array “apna_array”, the syntax as shown below….

      echo “${apna_array[*]}”
      and
      echo “${apna_array[@]}”

      This syntax is very common in bash shell, ${variable_name} is same as $variable_name. While in array the “[*]” and “[@]” indicate the all element of array.
      NOTE – Remember above two  syntax are not same there is one difference. It’s an assignment for you guys/girls!

      * How to access particular element of array –

      name=(Arun Bagul Bangalore Mumbai Raju Santhosh Ravi)

      here “name” is an array and I want to access the first and second element of the array “name”.

      echo “My name is – ${name[0]}  ${name[1]}”

      * How to find the length of array or element of array –

      ${#my_array[index]} expands to the length of (element of array) ${my_array[index]} . If “index” is “*” or “#” then expansion is the number of elements in the array. Please note – referencing an array variable without a subscript/index is equivalent to referencing element zero.

      Suppose “student” is array then, ${student} is same as ${student[0]}

      #declare and assign elements to array “student_record” –
      student_record=(10 “Ravi Bhure” “1st year of BE” “SSVPS College” Dhule)

      echo ${student_record}
      echo ${student_record[0]}

      echo “Total no of element in array is – ${#student_record[*]}”
      echo “Total no of element in array is – ${#student_record[@]}”

      echo “Length of element is – ${#student_record[1]}”

      * How to delete element of array –

      unset”  builtin command is used to delete element of array.

      unset array_name[index]  – delete the array element at given “index”. If “index” is “*” or “@” then, it will removes the entire array.

      big_city=(Bangalore Pune Nasik Hydrabad Surat)

      Here “big_city” is the array of big cities in India. Suppose I want to delete “Nasik” from above array –

      unset big_city[2]

      * Example – Look below script and it’s output

      root@arun:~# cat  how_to_array.sh
      #!/bin/bash

      #declare and assign element
      declare -a myarr[0]=”Arun”
      declare -a metro_array=(Mumbai Delhi Kolkata Chennai)
      declare -a  my_array
      my_array=(Arun Bagul Bangalore Mumbai Raju Santhosh Ravi)
      name_arr[1]=”Arun Bagul”

      echo “————————–”
      echo “myarr is – ${myarr[0]}”
      echo “Metro cities in India – ${metro_array[*]}”
      echo “My name is – ${my_array[0]}  ${my_array[1]}”

      echo “Name – ${name_arr[1]}”
      echo “Name – ${name_arr[*]}”

      echo “————————–”

      #how to assign element in array
      myarr[1]=”- System Engineer!”
      echo “myarr is – ${myarr[*]}”

      apna_array=([0]=arun [1]=bagul [3]=Santhosh [4]=ravi [5]=1024)

      echo “${apna_array[*]}”
      echo “${apna_array[@]}”

      student_record=(10 “Ravi Bhure” “1st year of BE” “SSVPS College” Dhule)

      echo ${student_record}
      echo ${student_record[0]}

      echo “Total no of element in array is – ${#student_record[*]}”
      echo “Total no of element in array is – ${#student_record[@]}”
      echo “Length of element is – ${#student_record[1]}”

      #how to delete array –
      del_arr=(Arun Bagul)
      echo “del_arr before ‘delete’ is – ${del_arr[*]}”
      #delete
      unset del_arr

      echo “del_arr after ‘delete’ is – ${del_arr[*]}”

      echo “————————–”

      #how to delete one element in array –

      big_city=(Bangalore Pune Nasik Hydrabad Surat)

      #suppose – want to delete “Nasik” from above array –

      echo “Big City before ‘delete’ is – ${big_city[*]}”

      #delete
      unset big_city[2]

      echo “Big city after ‘delete’ is – ${big_city[*]}”

      root@arun:~#

      *** Run above script –

      root@arun:~# ./how_to_array.sh
      ————————–
      myarr is – Arun
      Metro cities in India – Mumbai Delhi Kolkata Chennai
      My name is – Arun  Bagul
      Name – Arun Bagul
      Name – Arun Bagul
      ————————–
      myarr is – Arun – System Engineer!
      arun bagul Santhosh ravi 1024
      arun bagul Santhosh ravi 1024
      10
      10
      Total no of element in array is – 5
      Total no of element in array is – 5
      Length of element is – 10
      del_arr before ‘delete’ is – Arun Bagul
      del_arr after ‘delete’ is –
      ————————–
      Big City before ‘delete’ is – Bangalore Pune Nasik Hydrabad Surat
      Big city after ‘delete’ is – Bangalore Pune Hydrabad Surat
      root@arun:~#

      Thank you,
      Arun Bagul

      How to change password – non interactively in simple way

      How to change password – non interactively in simple way

      Introduction –

      This is the simple way to change password of user on Unix/Linux system non interactively! This script is really helpful for updating password in bulk or adding new users and setting  there password in bulk. Another method is to expect tool please refer article on expect!!

      Let’s see the script now –

      root@arun:~# cat /script/mypasswd.sh
      #! /bin/bash

      if [ $# -eq 2 ]; then
      echo “Script to change password non-interactively”
      echo “——————————————-”
      else
      echo ” * Usage: mypasswd.sh username   password”
      exit 1
      fi
      passwd  $1<<ARUN
      $2
      $2
      <<ARUN
      root@arun:~#

      How to use it ?

      root@arun:~# ./mypasswd.sh
      * Usage: mypasswd.sh username   password
      root@arun:~#

      root@arun:~# ./mypasswd.sh  myuser   mypwd
      Script to change password non-interactively
      ——————————————-
      Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully
      root@arun:~#
      Thank you,
      Arun Bagul

      PHP – Hide user input using batch script (windows)

      PHP – Hide user input using batch script (windows)

      Introduction –  I was looking for a PHP CLI (command line) script through which I can hide the user input details like password etc on windows platform. I didn’t find any script in php, which hide the password details while user giving input through command prompt. Then I got an idea to hide the password script using batch command. I tried to find out the batch script through which I can take the inputs and then pass the php script. Finally I found a wonderful batch script, which takes the input user name and password (hidden).

      ** Batch Script => input.bat

      @echo off
      cls
      SET /P uname=Enter Username:
      echo hP1X500P[PZBBBfh#b##fXf-V@`$fPf]f3/f1/5++u5>in.com
      set /p password=Enter password :<nul
      for /f “tokens=*” %%i in (‘in.com’) do set password=%%i
      del in.com
      echo.
      c:\php\php.exe d:\php\test.php %uname% “%password%”
      Pause

      Execute the batch  file  on window system (DOS prompt) will take the inputs and give the inputs to php script. To execute batch file just double click on input.bat file…

      Thank you,
      Arun Bagul and Santhosh Tirunahari

      MySQL Clustering – configuration and testing

      MySQL Clustering – configuration and testing

      Introduction – MySQL Clustering is simple, easy to setup and reliable solution. That enables clustering of in-memory databases in a shared-nothing system. MySQL supports only NDB storage or table type system in clustering environment. MySQL Cluster integrates the standard MySQL server with an in-memory clustered storage engine called NDB. A MySQL Cluster consists of a set of computers, each running a one or more processes which may include a MySQL Server (API), a Data (Storage) node, a Management server.

      In MySQL Cluster the tables are stored in the Data (Storage) nodes. Due to this tables are directly accessible from all other MySQL servers in the cluster, provided that the Database which contains the table is available (if not need to create database) on all MySQL nodes. The Data stored in the Data nodes for MySQL Cluster can be mirrored. The NDB storage engine can be configured with a range of failover and load balancing options. NDB is an in-memory storage engine offering high-availability and data-persistence features.

      mysql-clustering

      There are three types of cluster nodes, in MySQL Cluster configuration. There will be at least three nodes, one of each of types is require to configure MySQL clustering successfully.

      1) Management (MGM) Node – Manages the other nodes within the MySQL Cluster, performing such functions as providing configuration data, starting and stopping nodes, running backup, and so forth. Because this node type manages the configuration of the other nodes, a node of this type should be started first, before any other node. An MGM node is started with the command ndb_mgmd.

      2) Data node – This node stores cluster data. There are as many data nodes as there are replicas, times the number of fragments. For example, with two replicas, each having two fragments, you will need four data nodes. It is not necessary to have more than one replica. A data node is started with the command ndbd.

      3) SQL node – use to accesses the cluster data. SQL node is a traditional MySQL server that uses the NDB Cluster storage engine. An SQL node is typically started with the command mysqld –ndbcluster or by using mysqld with the ndbcluster option added to my.cnf.

      An SQL node is actually just a specialised type of API node, which designates any application which accesses Cluster data. One example of an API node is the ndb_restore utility that is used to restore a cluster backup. It is possible to write such applications using the NDB API.

      ** Let’s implement MySQL cluster practically –

      In my case there are three(3) Storage Node ie (192.168.0.2 ,192.168.0.3 and 192.168.0.4), four(4) MySQL API server (192.168.0.1, 192.168.0.2, 192.168.0.3 and 192.168.0.4 ) and one Management Node (192.168.0.5)…

      * Please follow these steps carefully you can easily set MySQL clustering.

      1] Login to Management node here IP of MGM node is 192.168.0.5

      * Create directory where data for Mgmd (Management node) is stored –

      root@fileserver:~# mkdir /var/lib/mysql-cluster_MGM
      root@fileserver:~#

      root@fileserver:~# ll -d /var/lib/mysql-cluster_MGM
      drwxr-xr-x 2 root root 4096 2008-01-05 11:22 /var/lib/mysql-cluster_MGM
      root@fileserver:~#

      * Make sure that the owner of data directory is MySQL user ie “mysql” –

      root@fileserver:~# chown mysql:mysql -R /var/lib/mysql-cluster_MGM/
      root@fileserver:~#

      root@fileserver:~# ll -d /var/lib/mysql-cluster_MGM/
      drwxr-xr-x 2 mysql mysql 4096 2008-01-05 11:22 /var/lib/mysql-cluster_MGM/
      root@fileserver:~#

      2] How to start Management Node

      root@fileserver:/var/lib/mysql-cluster_MGM# ndb_mgmd –help
      Usage: ndb_mgmd [OPTIONS]
      MySQL distrib 5.0.21, for pc-linux-gnu (i486)
      -?, –usage Display this help and exit.
      -?, –help Display this help and exit.
      -V, –version Output version information and exit.
      -c, –ndb-connectstring=name
      Set connect string for connecting to ndb_mgmd. Syntax:
      “[nodeid=<id>;][host=]<hostname>[:<port>]”. Overides
      specifying entries in NDB_CONNECTSTRING and Ndb.cfg
      –ndb-mgmd-host=name
      Set host and port for connecting to ndb_mgmd. Syntax:
      <hostname>[:<port>].
      –ndb-nodeid=# Set node id for this node.
      –ndb-shm Allow optimizing using shared memory connections when
      available
      –ndb-optimized-node-selection
      Select nodes for transactions in a more optimal way
      -c, –connect-string=name
      same as –ndb-connectstring
      –core-file Write core on errors.
      –character-sets-dir=name
      Directory where character sets are.
      -f, –config-file=name
      Specify cluster configuration file
      -P, –print-full-config
      Print full config and exit
      -d, –daemon Run ndb_mgmd in daemon mode (default)
      –interactive Run interactive. Not supported but provided for testing
      purposes
      –no-nodeid-checks Do not provide any node id checks
      –nodaemon Don’t run as daemon, but don’t read from stdin
      –mycnf Read cluster config from my.cnf

      Variables (–variable-name=value)
      and boolean options {FALSE|TRUE} Value (after reading options)
      ——————————— —————————–
      ndb-connectstring (No default value)
      ndb-mgmd-host (No default value)
      ndb-nodeid 0
      ndb-shm FALSE
      ndb-optimized-node-selection TRUE
      connect-string (No default value)
      core-file FALSE
      character-sets-dir (No default value)
      config-file (No default value)
      print-full-config FALSE
      daemon TRUE
      interactive FALSE
      no-nodeid-checks FALSE
      nodaemon FALSE
      mycnf FALSE
      root@fileserver:/var/lib/mysql-cluster_MGM#

      root@fileserver:/var/lib/mysql-cluster_MGM# ndb_mgmd -f /var/lib/mysql-cluster_MGM/config.conf
      root@fileserver:/var/lib/mysql-cluster_MGM#

      root@fileserver:/var/lib/mysql-cluster_MGM# netstat -nlp | grep ndb
      tcp 0 0 0.0.0.0:1186 0.0.0.0:* LISTEN 24291/ndb_mgmd

      root@fileserver:/var/lib/mysql-cluster_MGM#
      root@fileserver:/var/lib/mysql-cluster_MGM# /etc/init.d/mysql-ndb
      mysql-ndb mysql-ndb-mgm
      root@fileserver:/var/lib/mysql-cluster_MGM# /etc/init.d/mysql-ndb-mgm

      3] Managment Node command line utility –

      root@fileserver:/var/lib/mysql-cluster_MGM# ndb_mgm
      ndb_mgm ndb_mgmd
      root@fileserver:/var/lib/mysql-cluster_MGM# ndb_mgm
      — NDB Cluster — Management Client —
      ndb_mgm> show
      Connected to Management Server at: localhost:1186
      Cluster Configuration
      ———————
      [ndbd(NDB)] 3 node(s)
      id=2 (not connected, accepting connect from 192.168.0.2)
      id=3 (not connected, accepting connect from 192.168.0.3)
      id=4 (not connected, accepting connect from 192.168.0.4)

      [ndb_mgmd(MGM)] 1 node(s)
      id=1 @192.168.0.5 (Version: 5.0.21)

      [mysqld(API)] 4 node(s)
      id=5 (not connected, accepting connect from 192.168.0.1)
      id=6 (not connected, accepting connect from 192.168.0.2)
      id=7 (not connected, accepting connect from 192.168.0.3)
      id=8 (not connected, accepting connect from 192.168.0.4)

      ndb_mgm>

      4] Login to Storage Node 192.168.0.2 and edit my.cnf file –

      * Make changes to my.cnf file as shown below –

      root@asterisk:/etc/mysql# tail /etc/mysql/my.cnf
      # The following configuration is read by the ndbd storage daemons,
      # not from the ndb_mgmd management daemon.
      #
      #################################
      #Use this MySQL server as NDB storage/Data node
      #MGM node IP is – 192.168.0.5

      [MYSQL_CLUSTER]
      ndb-connectstring=192.168.0.5

      root@asterisk:/etc/mysql#

      root@asterisk:/etc/mysql# /etc/init.d/mysql restart
      Stopping MySQL database server: mysqld.
      Starting MySQL database server: mysqld.
      root@asterisk:/etc/mysql# netstat -nlp | grep 3306
      tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 19518/mysqld
      root@asterisk:/etc/mysql#

      root@asterisk:/etc/mysql# ndbd –help
      Usage: ndbd [OPTIONS]
      MySQL distrib 5.0.22, for pc-linux-gnu (i486)
      -?, –usage Display this help and exit.
      -?, –help Display this help and exit.
      -V, –version Output version information and exit.
      -c, –ndb-connectstring=name
      Set connect string for connecting to ndb_mgmd. Syntax:
      “[nodeid=<id>;][host=]<hostname>[:<port>]”. Overides
      specifying entries in NDB_CONNECTSTRING and Ndb.cfg
      –ndb-mgmd-host=name
      Set host and port for connecting to ndb_mgmd. Syntax:
      <hostname>[:<port>].
      –ndb-nodeid=# Set node id for this node.
      –ndb-shm Allow optimizing using shared memory connections when
      available
      –ndb-optimized-node-selection
      Select nodes for transactions in a more optimal way
      -c, –connect-string=name
      same as –ndb-connectstring
      –core-file Write core on errors.
      –character-sets-dir=name
      Directory where character sets are.
      –initial Perform initial start of ndbd, including cleaning the
      file system. Consult documentation before using this
      -n, –nostart Don’t start ndbd immediately. Ndbd will await command
      from ndb_mgmd
      -d, –daemon Start ndbd as daemon (default)
      –nodaemon Do not start ndbd as daemon, provided for testing
      purposes
      –foreground Run real ndbd in foreground, provided for debugging
      purposes (implies –nodaemon)

      Variables (–variable-name=value)
      and boolean options {FALSE|TRUE} Value (after reading options)
      ——————————— —————————–
      ndb-connectstring 192.168.0.5
      ndb-mgmd-host (No default value)
      ndb-nodeid 0
      ndb-shm FALSE
      ndb-optimized-node-selection TRUE
      connect-string 192.168.0.5
      core-file FALSE
      character-sets-dir (No default value)
      initial FALSE
      nostart FALSE
      daemon TRUE
      nodaemon FALSE
      foreground FALSE
      root@asterisk:/etc/mysql#

      * Data on Storage node is stored in ” /var/lib/mysql-cluster” directory. The MySQL user ie “mysql” need to be owner of this directory.

      root@asterisk:/etc/mysql# ll -d /var/lib/mysql-cluster/
      drwxr-xr-x 2 root root 4096 2006-06-16 17:38 /var/lib/mysql-cluster/
      root@asterisk:/etc/mysql#

      root@asterisk:/etc/mysql# chown mysql:mysql -R /var/lib/mysql-cluster/
      root@asterisk:/etc/mysql# ll -d /var/lib/mysql-cluster/
      drwxr-xr-x 2 mysql mysql 4096 2006-06-16 17:38 /var/lib/mysql-cluster/
      root@asterisk:/etc/mysql#

      ** How to start Storage or Data node first time –

      root@asterisk:/etc/mysql# ndbd –initial

      ….
      root@asterisk:/etc/mysql#

      Note – please use “–initial” while starting storage or data node first time
      root@asterisk:/etc/mysql# netstat -nlp | grep ndb
      tcp 0 0 192.168.0.2:38321 0.0.0.0:* LISTEN 19686/ndbd
      tcp 0 0 192.168.0.2:43001 0.0.0.0:* LISTEN 19686/ndbd
      tcp 0 0 192.168.0.2:41115 0.0.0.0:* LISTEN 19686/ndbd
      tcp 0 0 192.168.0.2:54651 0.0.0.0:* LISTEN 19686/ndbd
      tcp 0 0 192.168.0.2:55003 0.0.0.0:* LISTEN 19686/ndbd
      tcp 0 0 192.168.0.2:59453 0.0.0.0:* LISTEN 19686/ndbd

      root@asterisk:/etc/mysql#

      NOTE :: Please follow the same steps as mention here for other storage node ie 192.168.0.3 and 192.168.0.4.

      5] Goto Managment node and check whether 192.168.0.2 Storage node is activated or not

      root@fileserver:/var/lib/mysql-cluster_MGM# ndb_mgm
      — NDB Cluster — Management Client —
      ndb_mgm> show
      Connected to Management Server at: localhost:1186
      Cluster Configuration
      ———————
      [ndbd(NDB)] 3 node(s)
      id=2 @192.168.0.2 (Version: 5.0.22, starting, Nodegroup: 0)
      id=3 (not connected, accepting connect from 192.168.0.3)
      id=4 (not connected, accepting connect from 192.168.0.4)

      [ndb_mgmd(MGM)] 1 node(s)
      id=1 @192.168.0.5 (Version: 5.0.21)

      [mysqld(API)] 4 node(s)
      id=5 (not connected, accepting connect from 192.168.0.1)
      id=6 (not connected, accepting connect from 192.168.0.2)
      id=7 (not connected, accepting connect from 192.168.0.3)
      id=8 (not connected, accepting connect from 192.168.0.4)

      ndb_mgm>

      6] Now login to server 192.168.0.4 and configure mysql server as MySQL Node (API) –

      root@linserver:~# vi /etc/mysql/my.cnf

      [mysqld]

      #
      #setting for SQL-node of MySQL cluser
      #
      ###########################################
      #Use this MySQL server as NDB storage/Data node
      #MGM node IP is – 192.168.0.5
      #set Table/engine type to NDB
      ndbcluster
      #set MGM IP address
      ndb-connectstring=192.168.0.5

      root@linserver:~#

      7] Goto Managment node and check whether 192.168.0.4 as MySQL node is activated or not –

      root@fileserver:/var/lib/mysql-cluster_MGM# ndb_mgm
      — NDB Cluster — Management Client —
      ndb_mgm> show
      Connected to Management Server at: localhost:1186
      Cluster Configuration
      ———————
      [ndbd(NDB)] 3 node(s)
      id=2 @192.168.0.2 (Version: 5.0.22, starting, Nodegroup: 0)
      id=3 @192.168.0.3 (Version: 5.0.21, starting, Nodegroup: 0)
      id=4 (not connected, accepting connect from 192.168.0.4)

      [ndb_mgmd(MGM)] 1 node(s)
      id=1 (Version: 5.0.21)

      [mysqld(API)] 4 node(s)
      id=5 (not connected, accepting connect from 192.168.0.1)
      id=6 (not connected, accepting connect from 192.168.0.2)
      id=7 (not connected, accepting connect from 192.168.0.3)
      id=8 (not connected, accepting connect from 192.168.0.4)

      ndb_mgm>

      ** Now check that MySQL API node 192.168.0.4 is activated

      ndb_mgm> show
      Cluster Configuration
      ———————
      [ndbd(NDB)] 3 node(s)
      id=2 @192.168.0.2 (Version: 5.0.22, Nodegroup: 0, Master)
      id=3 @192.168.0.3 (Version: 5.0.21, Nodegroup: 0)
      id=4 @192.168.0.4 (Version: 5.0.22, Nodegroup: 0)

      [ndb_mgmd(MGM)] 1 node(s)
      id=1 @192.168.0.5 (Version: 5.0.21)

      [mysqld(API)] 4 node(s)
      id=5 (not connected, accepting connect from 192.168.0.1)
      id=6 (not connected, accepting connect from 192.168.0.2)
      id=7 (not connected, accepting connect from 192.168.0.3)
      id=8 @192.168.0.4 (Version: 5.0.22)

      ndb_mgm>

      NOTE:: Please follow the same steps as mention here for other MySQL API node ie 192.168.0.1, 192.168.0.2 and 192.168.0.3

      ** How to check/use MySQL Clustering –

      8] Login to MySQL server 192.168.0.4 and follow the process

      root@linserver:~# mysql -u root -p
      Enter password:
      Welcome to the MySQL monitor. Commands end with ; or \g.
      Your MySQL connection id is 708 to server version: 5.0.22-Debian_0ubuntu6.06.3-log

      Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

      mysql> create database arunbagul;
      Query OK, 1 row affected (0.00 sec)

      mysql> show databases;
      +——————–+
      | Database |
      +——————–+
      | information_schema |
      | arunbagul |
      +——————–+
      2 rows in set (0.00 sec)

      mysql>

      mysql> use arunbagul;
      Database changed
      mysql> CREATE TABLE cluster_tab (rollno INT NOT NULL , name varchar(255)) ENGINE=’NDBCLUSTER’;
      Query OK, 0 rows affected (0.38 sec)

      mysql>

      mysql> SHOW TABLES;
      +———————+
      | Tables_in_arunbagul |
      +———————+
      | cluster_tab |
      +———————+
      1 row in set (0.00 sec)

      mysql>
      mysql> INSERT INTO cluster_tab VALUES ( 1 , ‘Arun Bagul’ ) ;
      Query OK, 1 row affected (0.10 sec)

      mysql> INSERT INTO cluster_tab VALUES ( 2 , ‘Yogesh Nikam’ );
      Query OK, 1 row affected (0.07 sec)

      mysql> INSERT INTO cluster_tab VALUES ( 3 , ‘Ketan Mayangar’ );
      Query OK, 1 row affected (0.01 sec)

      mysql> select * from cluster_tab;
      +——–+—————-+
      | rollno | name |
      +——–+—————-+
      | 2 | Yogesh Nikam |
      | 3 | Ketan Mayangar |
      | 1 | Arun Bagul |
      +——–+—————-+
      3 rows in set (0.16 sec)

      mysql>

      9] Now login to MySQL server of 192.168.0.3 which is acting as MySQL node (API).

      root@proxy:~# mysql -u root -p
      Enter password:
      Welcome to the MySQL monitor. Commands end with ; or \g.
      Your MySQL connection id is 12 to server version: 5.0.21-Debian_3ubuntu1-log

      Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

      mysql>
      mysql> show databases;
      +——————–+
      | Database |
      +——————–+
      | information_schema |
      | auth |
      | mysql |
      +——————–+
      7 rows in set (0.00 sec)

      mysql>

      NOTE :: See out put of above query. It’s not showning the “arunbagul” DB which is clustered environment. Please Remember that you need to create DB on each MySQL API node, for DB which is in MySQL cluster! Then after the Clustered DB can be accessed from all MySQL API. All the tables etc are also available….

      mysql> create database arunbagul;
      Query OK, 1 row affected (0.07 sec)

      mysql> show databases;
      +——————–+
      | Database |
      +——————–+
      | information_schema |
      | arunbagul |
      | auth |
      | mysql |
      +——————–+
      8 rows in set (0.00 sec)

      mysql> use arunbagul ;
      Reading table information for completion of table and column names
      You can turn off this feature to get a quicker startup with -A

      Database changed
      mysql>
      mysql> show tables;
      +———————+
      | Tables_in_arunbagul |
      +———————+
      | cluster_tab |
      +———————+
      1 row in set (0.01 sec)

      mysql> select * from cluster_tab;
      +——–+—————-+
      | rollno | name |
      +——–+—————-+
      | 1 | Arun Bagul |
      | 3 | Ketan Mayangar |
      | 2 | Yogesh Nikam |
      +——–+—————-+
      3 rows in set (0.04 sec)

      mysql> INSERT INTO cluster_tab VALUES ( 4 , ‘Nishit Shah’ );
      Query OK, 1 row affected (0.10 sec)

      mysql> quit
      Bye
      root@proxy:~#

      10] Now login to MySQL server 192.168.0.4 which is MySQL API node.

      root@linserver:~# mysql -u root -p
      Enter password:
      Welcome to the MySQL monitor. Commands end with ; or \g.
      Your MySQL connection id is 800 to server version: 5.0.22-Debian_0ubuntu6.06.3-log

      Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

      mysql> select * from cluster_tab;
      +——–+—————-+
      | rollno | name |
      +——–+—————-+
      | 2 | Yogesh Nikam |
      | 3 | Ketan Mayangar |
      | 1 | Arun Bagul |
      | 4 | Nishit Shah |
      +——–+—————-+
      4 rows in set (0.12 sec)

      mysql>

      11] Now login to MySQL Managment node.. and check the MySQL Cluster;

      root@fileserver:/home# ndb_mgm
      — NDB Cluster — Management Client —
      ndb_mgm> show
      Connected to Management Server at: localhost:1186
      Cluster Configuration
      ———————
      [ndbd(NDB)] 3 node(s)
      id=2 @192.168.0.2 (Version: 5.0.22, Nodegroup: 0, Master)
      id=3 @192.168.0.3 (Version: 5.0.21, Nodegroup: 0)
      id=4 @192.168.0.4 (Version: 5.0.22, Nodegroup: 0)

      [ndb_mgmd(MGM)] 1 node(s)
      id=1 @192.168.0.5 (Version: 5.0.21)

      [mysqld(API)] 4 node(s)
      id=5 (not connected, accepting connect from 192.168.0.1)
      id=6 (not connected, accepting connect from 192.168.0.2)
      id=7 @192.168.0.3 (Version: 5.0.21)
      id=8 @192.168.0.4 (Version: 5.0.22)

      ndb_mgm>

      12] How to start/stop, restart MySQL Cluster –

      ** Login to MGM node and then start MGMD node as…

      root@fileserver:~# ndb_mgmd -f /var/lib/mysql-cluster_MGM/config.conf
      root@fileserver:~# ndb_mgm
      — NDB Cluster — Management Client —
      ndb_mgm> show
      Connected to Management Server at: localhost:1186
      Cluster Configuration
      ———————
      [ndbd(NDB)] 3 node(s)
      id=2 (not connected, accepting connect from 192.168.0.2)
      id=3 (not connected, accepting connect from 192.168.0.3)
      id=4 (not connected, accepting connect from 192.168.0.4)

      [ndb_mgmd(MGM)] 1 node(s)
      id=1 @192.168.0.5 (Version: 5.0.21)

      [mysqld(API)] 4 node(s)
      id=5 (not connected, accepting connect from 192.168.0.1)
      id=6 (not connected, accepting connect from 192.168.0.2)
      id=7 (not connected, accepting connect from 192.168.0.3)
      id=8 (not connected, accepting connect from 192.168.0.4)

      ndb_mgm>

      *** How to start NDBD Node from MGM interface..

      ndb_mgm> 2 STATUS
      Node 2: not connected

      ndb_mgm> 2 START
      Start failed.
      * 22: Error
      * No contact with the process (dead ?).

      ndb_mgm>

      That’s it!! MySQL clustering is working…

      Thank you,
      Arun Bagul