Saturday, August 31, 2013

Shell Programming : 8 | Conditional statements

Hello.... Friends today we are going to discus about the conditional statements in the shell scripting . like in other languages the Shell Programming too have conditionals statements . Conditional executions means executing code when certain conditions met and during conditional executions we just simply executes our multiple commands one after the other.

Conditional statements are basically

  • if/then
  • else
  • elif
Let's understand who & where we can use them. these are pretty Simple to use. So Let's understand them one by one.

  • if/then 
 Syntax :

               if  [ condition ]   # when the condition is true then statement is executed or else it return.
                then  
                     statements
                fi


      Major things we have to remember the space after starting & before closing the Brackets. & closing of if statement with fi command. 


  • else
Syntax :
                           if  [ condition ]           #  if the condition is true
                           then
                                 true statements    # statement is executed
                           else
                                false  statements   # statement is executed
                           fi


But if we want to make some more sense of the same script then we need to use else conditional statement too.
i e as we put false condition then it simply returns. but as we put else condition too then let's check what happened



  • elif
Syntax :
                   if  [ condition ]                # if  condition is true
                   then
                          true  statement 
                  elif  [ either condition ]    # either different but true conditions
                          true  statement
                  else
                          false statement      # if all the conditions are false
                  fi


i think you will understand by this syntax where the elif statement is used so elif statement is generally for multiple true statements but we don't know the write one so to test the condition that which condition is meeting to our condition then we can use this elif  conditional statement. it will avoid the multiple if statement in our script.
let's clear it with our script 


if you have different OS then try this script in your shell. I hope it will provide you the write result as per your OS. 

thanks friends , Please leave your comments & like Tutorials it will help me in improving my quality.

Thursday, August 29, 2013

Shell Programming : 7 | Variables

hello... Friends, Today we are going to discus about the variables in the shell programming variables have most important part in the shell programming. or we can say we can't count ,loop,or read input from the user or the environment.
Basically what is a variable ?
A variable is a memory chunks to which you can store arbitrary data, and retrieve it again, just by Referencing its name as we discus in previous post we use $ symbol in front of name of the variable.
How to assign Value to variables ?
Basically there are there ways of assigning the variables.

  1. Explicit definition : VAR=value
  2. Read : read VAR
  3. Command substitution : VAR=`date`,VAR=$(date)

Explicit definition 

Read variable

Command substitution
what if we Don't define the variable ?
when we are not defining the variable and want to check the value the as shown in the exp. here we want to check the variable $undefine_var then it shows us a blank line. but if we define the value in the variable here nullport is a variable and it's value is Govind then as we click Enter then the value is store in the memory in the background & as we ask for the value of the variable by echo $nullport then it Display result as Govind which is the value we store in the variable.


Thanks for Reading . Please Leave your comments & Likes so that i can improve my quality.

Wednesday, August 28, 2013

Shell Programming : 6 | special Symbols

hello.... Friends, Today we are going to discus few Basic Symbols which are vary important in the shell scripting. this is an important symbols which have some special meaning in the shell scripting.

few of them we are going to study today like :

#     $    \    "   '   `   <   >   |    ;    (    )    [    ]    ?    &   *    =    < Space >    < Tab >    <Newline >


# this symbol is used for comment or if we don't want the output in the script then we can use # symbol in our script.

$ this symbol is basically proceeds the name of a variable to be explained in the shell scripting.

\    "    '    `  these all symboles are used for quots in the script.

<  > these both symboles are used for input and output from one file to other.

| this is a pipes symbole it is used to bind two files that means output of file from left side of | will be send to as the input of the file in the right side of this symbole.

; this is the symboles which is used to seprate the multiple commands in a single line.

(  ) these symboles are  used to seprate the shells or we can say for subshells.

[  ] these symboles are used to launch the grup of commands by the shell basically the space is required after opening & closing .

& this symbole causes the preceding command to execute in the background so that next command can work without waiting.

* this command is used for matching filenames . but not from hidden files i e excepting files starting with dots in the directory.

? this symbole is used as * but just difference is to match the single charecter while * for file filename.

= when we assign the vales in a variable then we used this symbole mostly.

< Space > and < Tab > both are used to seprate the two commands.

<Newline > or \n is used to complete a command & start in the next line.


these are the few symboles which is mostly used in the shell. when we prectically design a scripts then i will try to explain them at that time.


Monday, August 26, 2013

Shell Programming : 5

Hello .... Friends , in the last tutorial we discus about the creating text files , creating directories, Deleting files & Deleting Directories . now in this tutorial we are going to discuss about the file permissions. we knows well the Linux or the Unix is a multi-programming  as well as multi-user Operating system. then who can access the files & how the Remote user can use any file that means read, write, and execute the file. & how to become a super user temporarily.
so in this tut we are going to discus about these of following commands.

  • chmod
  • su
  • chown
  • chgrp
Now let's understand the permissions . how to check the permissions & how to change them.
to check the permissions of a file we can check  ls -l file_name

if we want to check the permissions of Null3 then these are the permission as shown in the image.

-rw-r--r-- 1 nullport nullport 0 Aug 26 12:10 Null3

these are the permissions 644 for this file here 644 means the user here nullport only the person how can write this file & other users only can read the file . this is the Default permissions for any file we create.
& Now if we want to check the permissions for all the files & directory then we can use the options ls -l  without giving the name of any file. 
here in my home directory i create various files & try to change there permissions to understand the basic 


Now if we try to cover this in more deep then understand about this 644 & 777 etc.
rwx rwx rwx = 111 111 111
rw- rw- rw- = 110 110 110
rwx --- ---   = 111 000 000

(Note: if you do not knows how 111 is 7 then use my shot cut 8421. method of binary to desimal conversion.)
if we check the binary of 111 stand for 7 and as well 110 for 6 for a particular user let's clear more
rwx = 111 in binary = 7 
rw- = 110 in binary = 6
r-w = 101 in binary = 5
r-- = 100 in binary  = 4

so can we makes the permissions for any particular files for any particular user 
we are discussing some here 
777 = (rwxrwxrwx) that means no restrictions for anyone or we can say anyone can do anything. here the security challenges. if we need to secure any file in the system need to change such type of settings.
755 = (rwx-xr-x) that means only the file user can change ,read,write or execute the file . and all other may read and execute the file. they have no permissions to change it.
700 = (rwx------) that means the file owner may read,write, and execute the file. and nobody else has any rights.this is the best permissions for the file which only the owner want to see. & must be kept private from others.
666 = (rw-rw-rw-) that means all users can read and write the file. 
644 = (rw-r--r--) that means owner may read and write the file while other may only read the file. only the owner can change the file.
600 = (rw-------) that means owner may read and write the file. all other users have no writes to do anything with file.

Now i think this all makes all clear about file permissions. 

so if we want to change the permissions of any file in Linux or Unix operating system then we can simple use the chmod command as chmod 700 file_name 

try to change permissions of any directory with this chmod method.

  • su : change user ID or become superuser
su command is used for changing or become the super user for any user temporarily . sometime we need to become superuser to perform some important system administrator tasks. and we should not stay logged on as superuser. this command gives us the superuser privileges.

 now nullport is a superuser. & here i am in other shell with administrator privileges.
and if we want to go in the previous user stage then we just need to type exit command.

  • chown : change file owner and group

if we want to change the ownership of a file or dir. then we use this command  chmod user file_name
but before that we need to have superuser privileges and after that we have to exit . let's check it in our Sabayon linux for any file. here we are creating a file with touch command and try to change the ownership from nullport to root user.


-rw-r--r-- 1 nullport nullport    0 Aug 26 14:52 simple (before)
-rw-r--r-- 1 root     nullport    0 Aug 26 14:52 simple (after )

  • chgrp : change group ownership
if we want to change the ownership of a group then we need to have super user privileges and then just need to type chgrp grup_name file_name . i just create a file here with name admin with admin privileges. and now we need to change the grup from root to nullport . so let's check it 


-rw-r--r-- 1 root     root        0 Aug 26 15:21 admin
-rw-r--r-- 1 root     nullport    0 Aug 26 15:21 admin

here we changed the file admin from root to nullport.

here we are not disusing this all for directories that was the same try it your self for more better understanding. 

i think you can easily understand it . plz leave comments behind i will try to improve my tutorials. thank you.

Sunday, August 25, 2013

Shell Programming : 4

Hello.. Friends , In this Basic tutorials i am going to explains some other commands like creating files & Directory & Removing or Deleting them.

  • cat
cat : concatenate files and print on the standard output
Syntax : cat [OPTION]... [FILE]...

cat commands is basically use to create a text file by the terminals.as we type cat  > filename & hit enter then it allows us to type anything you want in the file on the terminal and for saving this file we have to press ctrl+d . and if we want to read this file then we need to just change the operator from > to < .
to combine two files we just need to type cat file1 file2 > output 
we can create files by using touch  command too. this  is an empty file.

  • mkdir : make directories
Syntax : mkdir [OPTION]... DIRECTORY...
mkdir command is used to create a directory . we just need to type mkdir and directory name .



& if we want to remove these files & dir then we can use rm commands . 
  • rm : remove files or directories
if we just simply use rm filename then it remove just a file & if we want to remove the directory then we just need to type rm -r dirname .

i think it is important to discus these Basic topics before to start the scripting tutorials. Because the shell scripting is just a combinations of these all commands & if we Don't know about them then we can never move forwards. 

Shell Programming : 3

Hello ... Friends , in the beginning we have to study some of the commands separately then we are going to combine these all commands for a meaningful scripts & then we moves on so let's try to understand some of the Basics commands


  • pwd
  • cal
  • date

before going ahead we are going to Discus about the Terminal
nullport is user name on this kernel this is the name you provide during the installation of linux kernel. $ symbole tells about the shell that we are working on shell. So now we can start with commands in the shell
here i want to tell you it is very Important when you are working on shell then must remember shell takes commands in lower case letter if you are tring to execute the caps letter commands then it is notexecuting or give you an error massage with command not found error.

------------------------------------------------------------------------

  • pwd - print current/working directory
Syntax: pwd [OPTION]...

nullport@localhost ~ $ pwd
/home/nullport

here pwd is stand for the command print name of the current/working directory . in the above commands it will gives us this shell is working directory /home/nullport that's mean we loged in as user nullport & it's shell working in home directory.

--------------------------------------------------------------------------
  • cal - display a calender 
Syntax : cal [options] [[[day] month] year]

this is a important command if we want to see the calender of the current month then we just need simply to write cal in the terminal but when we want to see the particular Date in past or in the future then we need to write complete Syntax as i mention above 

---------------------------------------------------------------------------


  • date : print or set the system date and time
Syntax : date [OPTION]... [+FORMAT]
       date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]

this is pretty simple command as  we want to see the current date then we can just use date command & if we want to see the date in different format then we can use the syntex as in above. here i want to explain we can use %m, for month,%y for year & %H for hrs %M for min & %S for sec. 

Saturday, August 24, 2013

Shell Programming : 2

In My Previous tut we discus about kernel so in this tut we are going to learn about shell . where shell stand in Linux & what is the Importance of Shell & allot of things ....

So What is a Shell :  Basically shell is a user program or we can say program between users and Kernels . It is a command language interpreter that executes commands providing by user to perform the action on kernel. But it is not a part of kernel.

we knows computer can understand just only binary language - in the form of 0's & 1's so it is not easy to Remembers all things in binary language , This work is become easy due to shell . shell accepts users commands in simple English codes ( not all but mostly) & send it to kernel to manipulate instructions in working instructions.

There are various shell available with Linux some are :

  • BASH (Bourne-Again SHell)
  • CSH (C SHell )
  • KSH (Korn SHell )
  • TCSH etc
so here i have a que. how to check all shells in your Linux ?
we can check just by typing   cat /etc/shells in the terminals .. here cat is a shell command i will discus it later & etc/shells is a directory in the kernel. if i show you in my Sabayon terminal then we can check there are allot of shells.



Do not puzzles these all shells perform the same jobs but just they have there different commands syntex & having different built-in functions. In our windows there is similar MS-DOS with name shell COMMAND.COM it is used for same purposes , but not Powerful like our Linux Shells.


Shell Programming :1

Hello ... Friends Today we are going to discuss about the shell programming just from the Basic to Little Advance `:||:`

So in my tuts i am going to use Sabayon Linux 
OS family : Unix-like
Basic Hardware Requirements :
512 MB of RAM
12 GB of free hard disk

So Ist of all we need to familiar with Linux Kernels : 
what is kernel : Basically we can say the Heart of Linux OS. or we can say that it is the Basic Manager of Linux which manage the Facilities available in the Linux when user put his Request to the shell then these Request are send to the Linux Kernel & Linux Kernel Decides who will use this resources & how long etc or we can say it runs it runs programs. Linux kernel is working between shell & hardware. & all the applications are Running on Linux kernels .

So Linux Kernel is Manager ,which manages :||:
  • I/O
  • Process
  • Devices
  • Files
  • Memories etc. 

Thursday, August 1, 2013

Few Important commands after installation of Backtrack

Friends it's necessary to have up-2-Date in the security field either you are a Black Hat of you are a white Hat , so update in the field is most necessary so today we are going to discuss about some of the Basic commands  for the Backtrack which makes you more secure & more powerful so let's start : )
  
so first of all after just installation of your Backtrack just type these commands 

1. apt-get update & apt-get upgrade 

This is vary important & this command update your D3vil M4chin3 : )

2. apt-get install update-manager 

This command is used for update manager this update manager find the broken package of the Backtrack & you can patch them easily if you have installed update-manager , the update manager will be located in the system > administration >update manager 

3.  apt-get install software-center 

This command also just work as above command & having some extra features like update instruction for check for updates & download them in the background etc.

so friends these are few Basic commands which are most necessary to install & update your Machine