Thursday, December 27, 2012

Linux Boot Loader                                                           Features of Bash Shell

It is very easy to learn bash shell scripting. There are different Unix shells like bash, ksh, zsh, sh etc. Please make sure that which shell do you want to use while running the script, because syntax of each shell might be different. Before going to develop shell script, your logic or flow of the script should be clear then only you can develop shell script very easily. It is very important to have clear understanding of when or where not to use shell script

 

For Fibonacci series shell script, need to know the exact number series. It will be as :

1              1              2              3              5              8              13           21            34          etc.

Please see below is the script to get desired output. 

######################Fibonacci.sh###############################

echo "How many numbers do you want of Fibonacci series ?"

  read total

  x=0

  y=1

  i=2

  echo "Fibonacci Series up to $total terms :: "

  echo "$x"

  echo "$y"

  while [ $i -lt $total ]

  do

      i=`expr $i + 1 `

      z=`expr $x + $y `

      echo "$z"

      x=$y

      y=$z

  done

Click to  know more about: Difference of Linux and Unix

#####################################################################

Now just save it as Fibonacci.sh and give the input as how many numbers you want of . Your output will be as follows: 

#####################################################################

root@hello:~/ctier/test/JBoss#

root@hello:~/ctier/test/JBoss# ./Fibnonacci.sh

How many numbers do you want of Fibonacci series ?

10

Fibonacci Series up to 10 terms ::

0

1

1

2

3

5

8

13

21

34

root@hello:~/ctier/test/JBoss#

#####################################################################

Before developing this script you should have clear understandings of while loop in shell script  and addition of numbers i.e. mathematical calculations in shell script.


mpstat command in Linux                                                        Ubuntu 12.10 features
Posted by Machindra Dharmadhikari On 12/27/2012 04:53:00 PM No comments READ FULL POST

Wednesday, December 26, 2012

Difference of Unix and Linux                                   Unix Shells

If you are already familiar with C or C++ coding then it is very easy to understand while loop in shell scripting. The Shell script while loop is same as other languages but different with syntax only. In bash shell scripting, while loop helps to run loop till the criteria fails. It is very useful when you want to run same command multiple times with change of some of the commands or its input.
The basic syntax of while loop in linux as follows:

while [ condition ]
do

                Our command 1;
                Command 2
                Command3
done

 Above while loop works as : if condition is satisfied then control comes inside the while loop and it will execute the command1, command then command3. And finally loop will exit.

While loop example in Linux:

root@hello:~/hello/test/test1# i=1;
root@hello:~/hello/test/test1#  while [ $i -lt 5 ]
> do
> echo $i;
> (( i++ ));
> done
1
2
3
4
root@hello:~/ctier/test/test1#

There are some changes in syntax of while loop as shell changes. In bash scripting, above syntax will work but in ksh it will not.
For KSH, you need to run the while as follows:

while [[ condition ]] ;
do
command 1 ;
command 2;
done

while loop with multiple conditions as follows:
while [ "$var1" != "$var2" || "$var1" == "$var3" || "$var2" != "$var4" ]
do
                commands here;
done
You can use counter inside the while loop as :
let counter=counter+1;

or

(( i++))
Posted by Machindra Dharmadhikari On 12/26/2012 07:18:00 PM 1 comment READ FULL POST

Wednesday, December 19, 2012

Recover deleted files in Linux                                    10 steps to create Logical Volume


Cygwin is the best application which creates unix like environment in Windows OS. We can run almost all commands on Cygwin. Processing of files in windows will be easy if we use unix commands to process.

You can use openssh server in cygwin and create password less connection as well. There are many features of Cygwin that we will discuss in other article.

Please see below  for  brief information about installation of cygwin.

How to install cygwin ?
1.        It is very easy step. Go to this link Download Cygwin
2.       Download setup.exe only.
3.       Run the setup.exe and you can see first pop up as follows:
 


Click here to know more about: Jstat Command in Linux


4.       Select Install from Local directory, if you have already downloaded all packages otherwise select first option i.e. Install from Internet and click next.
 
5.       After that you will get next window where setup is asking for root directory if you have selected the Install from local directory. Otherwise give the path where you want to keep all cygwin related files and then click on next.
 

6.       Now it will ask for Internet settings if you have i.e. for proxy settings if you have. Otherwise select Direct Connection option.
 
7.       Now you will get mirror list. Select any mirror and click on next.
 
8.       It is the last step and most important step about Cygwin installation. Please be careful while selecting the packages which you need with cygwin. If you have not selected respective package then you will not get the commands of that package in your cygwin and you will get error message like "Command not found". If you are going to select all packages then Cygwin will take too much time to complete and you will install unnecessary packages as well.
 

After selection of packages, installation process will start. click on next and then finish. 
and then you will get the desktop icon for Cygwin Launch. Double click on this and Cygwin will start  and start to run unix commands on Windows
 

If you need any help regarding Cygwin then you can reach me on linuxconcepts@gmail.com.


FTP server Concept                  Bash Shell features                      File System in Linux


Posted by Machindra Dharmadhikari On 12/19/2012 06:38:00 PM 4 comments READ FULL POST

Thursday, November 1, 2012

Logical Volume Manager in Linux                                      Check CPU usage in Linux




Recently, ubuntu 12.10 Quantal Quetzal released and users are ready to use new features of ubuntu 12.10. This version is available for Desktop, Server, cloud and core products. It introduced new innovation that bring together desktop and cloud based experiences. In this release, new Web apps features also introduced.
Features of Ubuntu 12.10:
·         Ubuntu 12.10 web apps
If you are using web apps like Facebook, Twitter, You tube, Gmail, Flickr then no need to open it every time from Firefox or any browser.  Install the web app for respective site and put it on desktop.
·         Online Search –
The Dash always searches the files, folders, photos of your computer. Now, it searches your online account also.
·         Compatible –
Most important compatibility is with Windows. Now, you can open, edit, share Microsoft office documents easily.
·         Speed –
Ubuntu 12.10 is very fast while booting. It loads quickly as compared to other OS.
·         Automatic Security updates—
In Ubuntu 12.10, automation of security updates provided.

There are many features like File encryption, Password Protection has been provided in this release.
·         LibreOffice –
This office has been updated to 3.6.2. There is no need of separate plugin.
·         Firefox –
Firefox updated up to its latest version i.e. 16.
·         Secure Boot support—
Used Grub2 boot loader.

There are more ubuntu 12.10 features, you can read on ubnutu's authorized site.


4 steps to extend the logical volume                             Difference between $* and $@ in scripting
Posted by Machindra Dharmadhikari On 11/01/2012 05:16:00 PM No comments READ FULL POST

Monday, October 29, 2012

                                 The mpstat command is used for checking the cpu usage in Linux or monitor the Linux system performance. It gives the processor statistics. If your system has multiple processor cores, you can use the mpstat command to monitor each individual core. The mpstat command provides the same CPU utilization statistics as vmstat, but mpstat gives the statistics out on a per processor basis.
You can see example as below for CPU performance monitoring linux:
{desktop002:root} mpstat
CPU minf mjf xcal  intr ithr  csw icsw migr smtx  srw syscl  usr sys  wt idl
  0  319   0    5   340  101  121    0   15    4    0   339    1   1   0  99
  1  113   0    2    94   16   81    0    7    4    0   113    0   1   0  99
  2  156   0    2    74   18   61    0    5    3    0   123    0   0   0 100
  3  154   0    2    66   22   61    0    3    3    0   169    0   0   0 100
  4 2156   0    3    51   32   73    0   28    5    0   962    1   2   0  97
  5   31   0    2    18    1   16    0    4    3    0    47    0   0   0 100
  6   11   0    2    19    2   14    0    4    2    0    24    0   0   0 100
  7    9   0    2    18    2   14    0    4    2    0    24    0   0   0 100
  8  265   0    1    40   11   42    0    4    2    0   153    0   0   0 100
  9  115   0    2    36    8   31    0    3    2    0    81    0   0   0 100
 10   72   0    1    37    7   40    0    2    2    0   118    0   0   0 100
 11  235   0    1    29    6   35    0    3    2    0   163    0   0   0 100
 12    8   0    2    18    3   12    0    4    2    0    16    0   0   0 100
 13    6   0    2    16    1   12    0    4    2    0    13    0   0   0 100
 14    6   0    2    17    1   13    0    4    2    0    19    0   0   0 100
 15    6   0    2    16    1   12    0    4    2    0    14    0   0   0 100
{desktop002:root}

mpstat command's general format to get output:
$ mpstat <interval> <count>

You can see the columns and its meaning as follows:
minf                          minor faults.
mjf                          major faults.
Xcal                         inter-processor cross calls
Intr                          interrupts
ithr                          interrupts as threads  (not  counting  clock interrupt)
csw                         context switches
icsw                        involuntary context switches
migr                        thread migrations (to another processor)
smtx                       spins on mutexes (lock not acquired on first try)
srw                          spins  on  readers/writer  locks  (lock  not acquired on first try)
syscl                        system calls
usr                           percent user time
sys                           percent system time
wt                            the I/O wait time is no longer calculated as a percentage of CPU time, and this statistic will always return zero.
idl                            percent idle time

mpstat command examples:
If you want to get 7 reports at interval of 60 seconds (1 minute) then use following command:
{desktop004:root} mpstat 60 7

You will get CPU usage 7 reports on every 1 minute interval. Run this background, and redirect its output to one file.
Posted by Machindra Dharmadhikari On 10/29/2012 08:54:00 PM No comments READ FULL POST

Saturday, October 27, 2012

Jmap Command                                                            Check java process performance statistics

Vmstat command collects and reports data about system's memory, paging, block IO, kernel threads, swap and processor utilization in real time. It is used to determine the root cause of linux system performance and memory use related issues. It reports virtual memory statistics.
[machindra@desktop03]~% vmstat
procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in    cs us sy id wa
 0  0    208  83508 253692 2206428    0    0     0    14    0     1  8  3 89  0
[machindra@desktop03]~%

Difference between top and vmstat command:

 Field descriptions of vmstat command's output:
 Procs
       r: The number of processes waiting for run time.
       b: The number of processes in uninterruptible sleep.
   Memory
       swpd: The amount of virtual memory used.
       free: The amount of idle memory.
       buff: The amount of memory used as buffers.
       cache: The amount of memory used as cache.
       inact: The amount of inactive memory. (-a option)
       active: The amount of active memory. (-a option)


Click to  know more about: when and where not to use shell script
   Swap
       si: Amount of memory swapped in from disk (/s).
       so: Amount of memory swapped to disk (/s).
   IO
       bi: Blocks received from a block device (blocks/s).
       bo: Blocks sent to a block device (blocks/s).
   System
       in: The number of interrupts per second, including the clock.
       cs: The number of context switches per second.
   CPU
       These are percentages of total CPU time.
       us: Time spent running non-kernel code. (user time, including nice time)
       sy: Time spent running kernel code. (system time)
       id: Time spent idle. Prior to Linux 2.5.41, this includes IO-wait time.
       wa: Time spent waiting for IO. Prior to Linux 2.5.41, shown as zero.

Vmstat command examples:
·         Get vmstat five reports after 2 seconds interval as follows:
[machindra@desktop03]~% vmstat 2 5
procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in    cs us sy id wa
 0  0    208  83308 253692 2206428    0    0     0    14    0     1  8  3 89  0
 0  0    208  83308 253692 2206428    0    0     0     0 1017    36  0  0 100  0
 0  0    208  83308 253692 2206428    0    0     0     6 1017    43  0  0 100  0
 0  0    208  83372 253692 2206428    0    0     0    22 1018    43  0  0 100  0
 0  0    208  83372 253692 2206428    0    0     0     0 1024    40  0  0 100  0
[machindra@desktop03]~%

·         Get size in kilobytes. Use –S for unit size and 1 1 for getting 1 report after 1 second. You can use  M instead of k, to get size in Mega Bytes.
[machindra@desktop03]~% vmstat -S k 1 1
procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in    cs us sy id wa
 0  0    212  85315 259780 2259382    0    0     0    14    0     1  8  3 89  0
[machindra@desktop03]~%


Check CPU usage in Linux                                                     Recover deleted files in Linux
Posted by Machindra Dharmadhikari On 10/27/2012 05:51:00 PM No comments READ FULL POST
  • RSS
  • Delicious
  • Digg
  • Facebook
  • Twitter
  • Linkedin
  • Youtube

    Chitika Ads 2

    Histat

    About

    Enter your email address:

    Delivered by FeedBurner