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 1 comment 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 3 comments READ FULL POST
  • RSS
  • Delicious
  • Digg
  • Facebook
  • Twitter
  • Linkedin
  • Youtube

    Chitika Ads 2

    Histat

    About

    Enter your email address:

    Delivered by FeedBurner