Oct
10
Posted on 10-10-2008
Filed Under (Linux commands, UNIX/Linux) by Arun Bagul

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

      (0) Comments    Read More   
      May
      27
      Posted on 27-05-2008
      Filed Under (Linux commands) by Arun Bagul

      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

      (0) Comments    Read More   
      Mar
      17
      Posted on 17-03-2008
      Filed Under (Linux commands) by Ravi Bhure

      The write command enables you to write an actual message on the other terminal online. You have to issue the write command with the login ID of the user with whom you want to communicate. The write command informs the user at the other end that there is a message from another user. write pastes that message onto the other user’s terminal if their terminal’s write permissions are set. Even if they are in the middle of an edit session, write overwrites whatever is on the screen. The edit session contents are not corrupted; you can restore the original screen on most editors with Ctrl-L.

      write is mostly used for one-way communication, but you can have an actual conversation as well.

      example: write user [ttyname]

      With Regards,

      Ravi Bhure

      (1) Comment    Read More   
      Feb
      26

      Introduction- Since long time, I was thinking to write post on expect!!. and finally I start writing this post.. I am using expect tool for automation, scheduling and running commands on remote machine by using ssh in non-interactive mode. It’s very useful and handy tool for System admin specially Unix and Linux admin.

      What is Expect ?

      Expect is a Unix automation and testing tool, written by Don Libes. Expect has regular expression pattern matching and general program capabilities, allowing simple scripts to intelligently control programs such as telnet, ftp, and ssh, all of which lack a programming language, macros, or any other program mechanism. The result is that Expect scripts provide old tools with significantly new power, and flexibility.

      Example (1) non interactive SSH login -

      root@arunbagul:/home/arun# cat non-interactive.sh
      #!/usr/bin/expect -f
      spawn ssh arun@192.168.0.1
      expect “password:”
      sleep 1
      send “mypassword\r”
      interact

      root@arunbagul:/home/arun#

      root@arunbagul:/home/arun# ./non-interactive.sh
      spawn ssh arun@192.168.0.1
      arun@192.168.0.1’s password:
      Linux arunbagul.com 2.6.22-14-generic #1 SMP Tue Feb 12 07:42:25 UTC 2008 i686

      The programs included with the Ubuntu system are free software;
      You have new mail.
      Last login: Sat Mar 1 15:15:05 2008 from arunbagul.com
      arun@arunbagul:~$ id=1200(arun) gid=1200(arun)

      arun@arunbagul:~$

      Example (2) non interactive SCP copy -

      root@arunbagul:/home/arun# cat scp.sh
      #!/usr/bin/expect -f

      # set Variables
      set source [lrange $argv 0 0]
      set dest [lrange $argv 1 1]
      set timeout -1

      # connect via scp…
      spawn scp $source $dest

      #wait for the password to ask…
      expect “password:”
      sleep 1

      #provide password after askinng

      send “mypassword\r”

      interact
      #done
      root@arunbagul:/home/arun#

      * Now copy data to 192.168.0.1 system -

      root@arunbagul:/home/arun# ./scp.sh /tmp/myfile.txt arun@192.168.0.1:/tmp/arun/
      spawn scp /tmp/myfile.txt arun@192.168.0.1:/tmp/arun/
      arun@192.168.0.1’s password:
      myfile.txt 100% 8 0.0KB/s 00:00
      root@arunbagul:/home/arun#

      * Now copy data from 192.168.0.1 system to your system -

      root@arunbagul:/home/arun#./scp.sh arun@192.168.0.1:/tmp/arun/myfile.txt /tmp/
      spawn scp arun@192.168.0.1:/tmp/arun/myfile.txt /tmp/
      arun@192.168.0.1’s password:
      myfile.txt 100% 8 0.0KB/s 00:00
      root@arunbagul:/home/arun#
      Now you know, how this tool is powerful !!.. You can use this tool for automation purpose and where you don’t want to interact with system now and then use it…

      Note:- In above two example script is non interactive means it will not ask you to inter password …. expect will do it for you…!!

      Thank you,
      Arun

      (4) Comments    Read More   
      Jan
      20
      Posted on 20-01-2008
      Filed Under (Linux commands) by Arun Bagul

      SSH provides wounder facility to run linux command on remote machine, provided that you have SSH access to that machine…

      • We can use this feature of SSH for troubleshooting purpose… for example suppose there is “logout” command in your “.bashrc” file of remote user. In this case you will not get ssh access until you remove this “logout” command from “.bashrc” file of remote user. This can be done remotely by using SSH..

      1] I am login on machine ‘IndianGNU.org’ and trying to login to ‘192.168.0.1′ ie ‘Remote’ machine.. but it immediately logout. see below….

      root@IndianGNU.org:/home/arun.bagul# ssh arun.bagul@192.168.0.1
      arun.bagul@192.168.0.1’s password:
      Last login: Sun Jan 20 18:49:29 2008 from 192.168.0.5
      Connection to 192.168.0.1 closed.
      root@IndianGNU.org:/home/arun.bagul#

      2] This is happening because there is ‘logout’ command added in ‘.bashrc’ file of arun.bagul’s profile on ‘192.168.0.1′

      3] How to check this ‘.bashrc’ file on ‘192.168.0.1′ -

      root@IndianGNU.org:/home/arun.bagul# ssh arun.bagul@192.168.0.1 ‘tail /home/arun.bagul/.bashrc’
      arun.bagul@192.168.0.1’s password:
      if [ -f /etc/bash_completion ]; then
      . /etc/bash_completion
      fi

      ######

      ## ‘logout’ command which will terminate your session just after login.
      #You will not get any access via SSH
      logout

      root@IndianGNU.org:/home/arun.bagul#

      4] How to remove this ‘logout’ command from remote file by ssh -

      root@IndianGNU.org:/home/arun.bagul# ssh arun.bagul@192.168.0.1 ’sed -i “s/logout/#welcome/g” /home/arun.bagul/.bashrc’
      arun.bagul@192.168.0.1’s password:
      root@IndianGNU.org:/home/arun.bagul#

      5] Check now -

      root@IndianGNU.org:/# ssh arun.bagul@192.168.0.1 ‘tail /home/arun.bagul/.bashrc’
      arun.bagul@192.168.0.1’s password:
      if [ -f /etc/bash_completion ]; then
      . /etc/bash_completion
      fi

      ######

      ## ‘#welcome’ command which will terminate your session just after #login.
      #You will not get any access via SSH
      #welcome

      root@IndianGNU.org:/home/arun.bagul#

      6] Now try to login on 192.168.0.1′ with user name ‘arun.bagul’ -

      root@IndianGNU.org:/home/arun.bagul# ssh arun.bagul@192.168.0.1
      arun.bagul@192.168.0.1’s password:
      Last login: Sun Jan 20 18:39:15 2008 from 192.168.0.5
      arun.bagul@Remote:~$

      7] Other uses of ssh for running remote command -

      root@IndianGNU.org:/home/arun.bagul# ssh arun.bagul@192.168.0.1 ‘df -h’
      arun.bagul@192.168.0.1’s password:
      Filesystem Size Used Avail Use% Mounted on
      /dev/hda2 79G 26G 50G 34% /
      varrun 1009M 108K 1009M 1% /var/run
      varlock 1009M 8.0K 1009M 1% /var/lock
      udev 1009M 104K 1009M 1% /dev
      devshm 1009M 0 1009M 0% /dev/shm
      /dev/hda5 56G 42G 11G 81% /backup
      /dev/hda1 361M 27M 315M 8% /boot
      /dev/hda6 9.2G 8.6G 180M 98% /var
      root@IndianGNU.org:/home/arun.bagul#
      ** List mounted partion -

      root@IndianGNU.org:/home/arun.bagul# ssh root@192.168.0.8 ‘mount’
      root@192.168.0.8’s password:
      /dev/hda3 on / type ext3 (rw)
      proc on /proc type proc (rw)
      sysfs on /sys type sysfs (rw)
      devpts on /dev/pts type devpts (rw,gid=5,mode=620)
      /dev/hda2 on /boot type ext3 (rw)
      tmpfs on /dev/shm type tmpfs (rw)
      /dev/hda7 on /usr type ext3 (rw)
      /dev/hda6 on /var type ext3 (rw)
      none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
      /usr/tmpDSK on /tmp type ext3 (rw,noexec,nosuid,loop=/dev/loop0)
      /tmp on /var/tmp type none (rw,noexec,nosuid,bind)
      sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)

      root@IndianGNU.org:/home/arun.bagul#
      Regards,

      Arun Bagul

      (0) Comments    Read More   
      Jan
      17
      Posted on 17-01-2008
      Filed Under (Linux commands) by Ravi Bhure

      One of the best methods to capture a Unix terminal session is to use the `script` command.

      In this example we start a script session, run a couple of commands, and then use the `exit` command to stop capturing the terminal session:

      $ script
      Script started, output file is typescript
      $ pwd
      /home/will
      $ ps
        PID  TT  STAT      TIME COMMAND
      11909  p0  Ss     0:00.05 -bash (bash)
      25622  p0  S+     0:00.01 script
      25623  p1  Ss     0:00.01 /usr/local/bin/bash -i
      25624  p1  R+     0:00.00 ps
      $ exit
       
      Script done, output file is typescript

      We have now captured our terminal session into the file “typescript”.

      We can use the `cat` command to view the contents of the “typescript” file:

      $ cat typescript
      Script started on Tue Jul 26 21:28:50 2005
      $ pwd
      /home/will
      $ ps
        PID  TT  STAT      TIME COMMAND
      11909  p0  Ss     0:00.05 -bash (bash)
      25622  p0  S+     0:00.01 script
      25623  p1  Ss     0:00.01 /usr/local/bin/bash -i
      25624  p1  R+     0:00.00 ps
      $ exit
       
      Script done on Tue Jul 26 21:29:13 2005
       

      If you’re new to UNIX, this concise book will tell you just what you need to get started and no more. This fifth edition is the most effective introduction to UNIX in print, covering Internet usage for email, file transfers, and web browsing. It’s an ideal primer for Mac and PC users who need to know a little about UNIX on the systems they visit. The new edition also contains many major and minor updates to help the reader navigate UNIX’s ever-expanding capabilities. In response to the popularity of Linux, the book now focuses on the popular bash shell preferred by most Linux users. A new chapter explains how to use ftp, pine for mail, and offers useful knowledge on how to surf the web. And the author has included tips throughout the text on security basics, especially in the Internet and networking sections. The book includes a completely updated quick reference card to make it easier for the reader to access the key functions of the command line.

      Thanks & Regards

      Ravi Bhure

      (0) Comments    Read More   
      Jan
      07
      Posted on 07-01-2008
      Filed Under (Linux commands) by Arun Bagul

      1] cat the file arun.txt which has several blank lines

      root@indianGNU.org:/home# cat arun.txt
      This is first line of file

      this is second line

      ok this script will help you to delete all blank links from file
      How to start shell scripting

      make sure that you will win

      arun bagul

      end of file

      root@indianGNU.org:/home#

      2] Run command for removing lines

      root@indianGNU.org:/home# grep -v “^$” arun.txt > no_blank_lines.txt

      3] Chcek new file -

      root@indianGNU.org:/home# cat no_blank_lines.txt
      This is first line of file
      this is second line
      ok this script will help you to delete all blank links from file
      How to start shell scripting
      make sure that you will win
      arun bagul
      end of file
      root@indianGNU.org:/home#

      (1) Comment    Read More   
      Jan
      03
      Posted on 03-01-2008
      Filed Under (Linux commands) by Arun Bagul

      In my  case I am  using apache server  for reloading configuration file etc.

      *Check  apache is runnig on 80 port or  not ?

      root@indiangnu.org:/home/arun# netstat -nlp |  grep  80
      tcp6       0      0 :::80                   :::*                    LISTEN     5562/apache2

      root@indiangnu.org:/home/arun# vi /etc/apache2/
      apache2.conf     envvars          magic            mods-enabled/    README           sites-enabled/
      conf.d/          httpd.conf       mods-available/  ports.conf       sites-available/ ssl/

      2]  Modify  configuration files..

      root@indiangnu.org:/home/arun# cat  /etc/apache2/ports.conf
      Listen 80

      root@indiangnu.org:/home/arun#  vi  /etc/apache2/ports.conf

      root@indiangnu.org:/home/arun#  cat  /etc/apache2/ports.conf
      Listen 80
      Listen 8080

      root@indiangnu.org:/home/arun#

      root@indiangnu.org:/home/arun# netstat -nlp |  grep  80
      root@indiangnu.org:/home/arun# netstat -nlp |  grep  80
      tcp6       0      0 :::80                   :::*                    LISTEN     5562/apache2

      3]  Reload service ie configuration files etc.

      root@indiangnu.org:/home/arun# kill -HUP 5562

      4]  Check apache is using 80 and 8080 port or not ?

      root@indiangnu.org:/home/arun# netstat -nlp |  grep  80
      tcp6       0      0 :::8080                 :::*                    LISTEN     5562/apache2
      tcp6       0      0 :::80                   :::*                    LISTEN     5562/apache2
      root@indiangnu.org:/home/arun#

      (0) Comments    Read More   
      Jan
      01
      Posted on 01-01-2008
      Filed Under (Linux commands) by Ravi Bhure

      Sometimes when you try to execute a long command, it scrolls beyond the screen. Then if you want to modify the command and re-execute it, there is an easy way for it. Just type “fc” which will load the command in your default editor; in my case vi. Now you can modify the command in the editor and exit the editor, and your modified command is executed automatically.

      For example try typing the following command in the bash shell and type “fc“.

      $ find /etc -iname '*.conf' -exec grep -H 'log' {} \;
      
      $ fc

      “fc” will bring the last command typed into an editor, “vi” if that’s the default editor. Of course you can specify a different editor by using the -e switch as follows:

      $ fc -e emacs

      To list last few commands, type:

      $ fc -l

      For the last 10 commands it will be:

      $ fc -l -10

      To seach for a command, type “CTRL+r” at the shell prompt for starting a search as you type prompt. Once you found your command, press enter to execute it.

      If you want to transpose two characters say you typed ’sl’ instead of ‘ls’. Then move the cursor between ’sl’ and type “CTRL+t“.

      Thank you,

      Ravi Bhure

      (0) Comments    Read More   
      Dec
      29
      Posted on 29-12-2007
      Filed Under (Linux commands) by Ravi Bhure

      UMASK is a UNIX environment variable which automatically sets file permissions on newly created files.

      The UMASK variable can be confusing to use, because it does work as a mask. In other words, you set the permissions that you do not want in the UMASK.

      To calculate permissions which will result from specific UMASK values, subtract the UMASK from 666 for files and from 777 for directories.

      If you want all files created with permissions of 666, set your UMASK to 000. Alternatively, if you want all files created with permissions of 000, set your UMASK to 666.

      A reasonable value for UMASK is 022, which will cause files to be created with permissions of 644 (rw-r–r–) and directories to be created with permissions of 755 (rwxr-xr-x).

      A more secure value for UMASK is 066, which will cause files to be created with permissions of 600 (rw——-) and directories to be created with permissions of 700 (rwx——).

      UMASK is nomally defined in the .profile or .login user startup files.

      Thank you,

      Ravi Bhure

      (2) Comments    Read More   

      www.flickr.com
      arunbagul's photos More of arunbagul's photos