Sunday, September 4, 2011

BASIC SHELL PROGRAMMING


BASIC SHELL PROGRAMMING

This is a basic shell program which runs on terminal. It shows the basic operations like how to use 'while ,if , switch case' , how to declare variable , how to print on to console , how to accept values from user , how to  use bc , etc .This menu driven program finds the factorial of a number ,fibonacci series and check if the given input is an armstrong number .

a=1
while [ $a -eq 1 ]
do
   echo "Menu"
   echo "1.FACTORIAL"
   echo "2.FIBONACCI"
   echo "3.Armstrong"
   echo "Choice:"
   read ch

   case $ch in
     1)      echo "Enter the num:"
             read num
             fact=1
             i=$num
             while [ $i -gt 0 ]
             do
                  fact=`echo $i \* $fact|bc`
                  i=`echo $i - 1 |bc`
             done
             echo "Factorail :" $fact
          ;; 
      2)      echo "Enter the num"
              read num
              n=0
              m=1
              echo "Fib Series : 0     1 "
              i=2
              while [ $i -lt $num ]
              do
                   c=`echo $m + $n |bc`
                   echo $c
                   n=$m
                   m=$c
                   i=`echo $i + 1 |bc`
              done
            ;;
      3)      echo "Enter the num"
              read num
              temp=$num
              sum=0
              while [ $temp -ne 0 ]
              do
                  k=`echo $temp % 10 |bc`
                  sum=`echo $sum +  $k \* $k \* $k |bc`
                  temp=`echo $temp / 10 |bc`
              done
              if [ $sum -eq $num ]
               then
                  echo "The num is Armstrong Number"
               else
                  echo "The num is not a Armstrong Number"
              fi
            ;;

       *)      echo "WRONG INPUT"

   esac

 echo "do you want to continue (0/1)? :"
 read a

done


Thursday, August 25, 2011

Run a Laptop without harddisk !

I always thought that we need to have a hard disk for any laptop or Computer to function. But later i understood that the thought was completely wrong. Everything started when my own laptop(Lenovo ThinkPad SL400) fell down.The Story goes like this-" One day while i was charging my laptop,I happened to trip the on the wire unknowingly and it fell down. The only application running in the laptop was Google Chrome. I thought that the screen was broken but when i opened the laptop luckily the screen was fine. I had a strange feeling that something else was wrong because my Windows Explorer(OS:Windows 7 Ultimate) kept restarting.

I was left with no other choice rather than reboot my system. After the reboot, the system direclty went into System Recovery. Tried rebooting again but didnt get anything different.


After sometime my hard disk was not passing the BIOS scan. I was getting this error:

Pri Master Hard Disk:831A – S.M.A.R.T. Status BAD ,Backup and Replace”

This is the moment that i decide to ditch Microsoft Windows and move on to Ubuntu 11.04 -”Natty Narwhal”.

All I needed was a HP 8GB pen drive and Ubuntu 11.04 “Natty Narwhal”(Info : Natty Narwhal is the successor to Maverick Meerkat) live CD.

Things I did :

  1. Remove the harddisk from the laptop. (Note: This procedure is complicated for some laptops. So i would advice people who are not experienced in removing a harddisk to please do this experiment at your own risk)

  2. Put the Ubuntu 11.04 -”Natty Narwhal” CD, Go to BIOS and change boot order to CD/DVD

  3. Plug the pen drive and restart the system.

  4. Once the Ubuntu is loaded, Select Install Ubuntu 11.04 -”Natty Narwhal”.

  5. Now the pen drive will be shown in the Menu.(You can also parition your pen drive if needed.)

  6. Select the pen drive, and click next.

  7. Once the installation is over,Restart( Note: now you need to got to the BIOS and set Removable Disk as boot disk)

  8. Now we are ready to use the OS

Its this Simple. Nothing much to do. Now i'm running my laptop without a hard disk. All i'm using is the pen drive. I can remove my pen drive and use it on any other system. Its more or less like a portable OS.

Carry your OS,where ever you go, in your pocket.

Try this experiment. I will help you guys out.

Screenshot of my current workstation :