Tuesday 27 December 2011

" Screen " command in linux


The following shows Multi Screen in GUI .

similarly "Screen" command Helps us to have multiple screens for the same shell in linux.



To Enter into different screens :

Execute the screen command once .
$screen

now it goes to screen 0

now in this new screen , type $screen  , it goes to screen 1 ......this goes on and on ...

To come out of a screen :

To exit screens one by one from the latest present screen , type
$exit
Now if you are in "i" th  screen , you are pushed to "i-1" th screen...

To detach all the screen at once ,
press ctrl +A D

Top View of what screens are and where it is  ....



We are in a terminal(parent) .
In which we can have a number of sockets . Each socket has a number of screens .

Each time we come to the terminal(parent) and type $screen we open a new socket
In this socket at first, screen 0 is displayed . then in this if we type
$screen
we are attaching another screen to same socket , and named as screen 1,, and so on

And now if we come to terminal by ctrl +A D , and type $ screen , we open a new socket ..
Outline is as follows ,

                                                                            -------------screen 1              
                                                                           |
                                     ------- ------ ------socket 1 ------------screen 2
                                    |
Terminal (parent)  -----
                                    |                                      
                                     ------- ----- -------socket 2 --------------screen 1
                                                                           |
                                                                           -------------- screen 2
                                                                           |
                                                                           L--------------screen 3

(sorry for the dirty diagram , I just tried to do with keyboard , due to time constraints )
In short , screens are like grand children of terminal.

so when ever we type ctrl +A D , we come to parent , from here we select a socket and from socket we select screens there.)
say if, the socket id is 12899.pts-0.cu147

This is done by
$ screen -r 12899.pts-0.cu147

so we selected the socket .

press enter

We have now entered into socket 12899.pts-0.cu147

here we can select the screens .

Uses of having the concept of screens .................

When there is process which is known to take a lot of time (say 10 hrs) . Then we cannot wait for 10 hrs for the process to get completed (some of my friends used to do this , to show that they have no work for 10 hours).But my Educator did not want to allow this. So he suggested this idea,that we can have a different screen for the new process we are to be engaged  with.

Now , say we have a process running in a screen and we have switched to a new screen .How to go to that old screen in which our process is running ( screen 0 or screen 1 or screen2 ....  ), when we have already detached from that screen .

Ctrl + A  '
and then type the screen number of the screen to which you want to navigate to.

(Note : dont try this from parent screen(It is foolish because as i told before , the parent only has sockets and sockets inturn have screens) we have to enter into socket and try selecting screens )

Giving Names for screens and accessing screens using it

As I cannot remember screen numbers  , I started searching for methods to give names to screens , instead of having names like screen 0 : bash , screen 1 : bash ...........

Ya , I found a solution ,,,, they have command .....

If you are in a particular screen say screen 1, then press

ctrl + A shift + A
then delete the word bash in the prompt saying "Set window's title to : bash" appearing at the bottom of the screen and type the name of the running process (or anything of your wish , so that you can make out later)
And press enter

Now how to get this screen back after navigating to some other ....????????

First get the list of screens attached by pressing

Ctrl + A "

The list appears ,, from this list select the process by using navigation keys and press enter , you will be dragged to that screen .

This is What I Know about SCREEN command .



Monday 26 December 2011

ltrace and strace

Kernel
The kernel of UNIX is the hub of the operating system: it allocates time and memory to programs and handles the filestore and communications in response to system calls.
As an illustration of the way that the shell and the kernel work together, suppose a user types sleep 10 (which has the effect of sleeping without returning unix prompt ,for 10 seconds). The shell searches the filestore for the file containing the program sleep, and then requests the kernel, through system calls, to execute the program sleep on myfile. When the process sleep myfile has finished running, the shell then returns the UNIX prompt % to the user, indicating that it is waiting for further commands.


Shell :
The shell acts as an interface between the user and the kernel. When a user logs in, the login program checks the username and password, and then starts another program called the shell. The shell is a command line interpreter (CLI). It interprets the commands the user types in and arranges for them to be carried out. The commands are themselves programs: when they terminate, the shell gives the user another prompt ($ on our systems).


the diagram shows how a kernel and shell are related :



Now lets look at the commands that are used to record library calls and system calls .

ltrace : is a program that simply runs the specified command until it exits. It intercepts and records the dynamic library calls which are called by the executed process and the signals which are received by that process

strace: runs the specified commanduntil it exits. It intercepts and records the system calls which are called by a process and the signals which are received by a process. The name of each system call, its arguments and its return value are printed on standard error or to the file specified with the -o option.programmers will find that since system calls and signals are events that happen at the user/kernel interface, a close examination of this boundary is very useful for bug isolation.

Tuesday 20 December 2011

Simple Mail Transfer Protocol


What is SMTP ? 

This appears to be a gobbledygook , right ?????
Yes , for me too ...... but only till 19th December 2011..  the day on which my educator taught me this ....
First we shall see what is the expansion of this abbreviation ,,,,it is  “Simple Mail Transfer Protocol”
Protocol  is nothing but like the ethics or rules  which has to be followed while carrying the information from  sender to receiver  ....
OK , to start with, view the diagram below .

SMTP is the protocol governing the transfer of mail from sender to the sender’s  mail server and from sender’s mail server to receiver’s mail server ...
The transfer from receiver’s mail server to the receiver, it is governed by ACCESS PROTOCOLS ....
Here we concentrate only on SMTP .........
By the way, mail server is  nothing but the server where the mails are stored ......
To put in a simple form, where SMTP plays a role, lets look at the example my educator gave ,,,

Steps  1 , 2 ,3,4 are taken care by SMTP protocol,
Step 5 taken care by access protocol (IMAP , POP)

General Architecture Of Mail Transfer :


MUA –Mail User Agent....
The MUA is the program which the user uses to read and send e-mail. It reads incoming messages that have been delivered to the user's mailbox, and passes outgoing messages to an MTA for sending.
MSA  -  Mail Submission Agent
A mail submission agent (MSA) is a computer program or software agent that receives electronic mail messages from a mail user agent(MUA) and cooperates with a mail transfer agent (MTA) for delivery of the mail. 
MTA – Mail Transfer Agent 
The MTA basically  is a software that acts as a "mail router". It accepts a message passed to it by either an MUA or another MTA, and then passes the message to the appropriate MDA for final delivery .
MDA : Mail Delivery Agent
The MDA is a software accepts a piece of mail from an MTA and performs the actual delivery.



Underlying Process :

The User types the  Email and then the send process is triggered . The Mailclient  or Mail User Agent(namely Microsoft OutLook, ThunderBird) submits the message to the MSA (Mail Submission Agent ). The MSA then transfers the message to the internal MTA(Mail Transfer Agent). You should take cognisance of the fact that all these transfer was done using SMTP protocol.
The internal MTA has the message now. Now it has to transfer the message from this internal MTA to the Mail Exchanger,because it is the one in the domain, that is incharge of the mails to be sent to the destination domain.. Where will this poor Mail exchanger get the information of the destination domain ?????????



Yes ,  the software developers are giving us another carrot . This is the facility provided to the MTA ,to  refer the MX record and find the destination domain ., For example , if it is harish@gmail.com ., the domain is gmail.com.This information is found in the MX record . So the message is transferred to gmail.com domain . Now the message is within the gmail.com domain MTA .Then this MTA , transfers the message to the MDA(Mail Delivery Agent) which performs the actual mail delivery to the mail client at the receiving end.
You should again note that , except the final part where the message  is being delivered by  MDA to the mail client  , everywhere else the  interaction takes place using SMTP.
Now lets explore the SMTP  by ourself, by trying to do what the SMTP does , using the commands.

Execute and Explore:
  1.        Get into the linux enviroinment .
  2.        Type nslookup and click enter.

What is nslookup ????????
We will come to that in a short while....For the time being remember it as name server lookup ....... Now first we shall try this....
$nslookup
The following is witnessed.



What is the > symbol ?   what has happened to the unix $ prompt ??????
This is because  nslookup is a network administration command line tool ,and  when used, we enter into the so called nslookup prompt (>) .
This is used to ask the DNS server , some questions ( QUERYING)  and getting answer from it.
If you now type the domain name collab.net . It gives the IP address of local MTA and also the IP address of the collab.net domain, which falls within this MTA . ......
 Let us now bombard it with questions ....
>set q=mx
>collab.net
We will see the following....


What does set q= mx command mean  ????????????
q -----à  query
mx ---à Mail eXchanger
So it means it is asking to get the MX record information of the collab.net domain.
This provides the information about the mail exchangers available in this domain .

What is the value 10 ????
It is the pref field . The pref (Preference) field is relative to any other MX record for the zone (value 0 to 65535). Low values are more preferred. The pref value 10 you see all over the place is just a convention you can use any number(s) you wish. The pref field is used by the SMTP (Mail) Agent to select the most preferred (lowest pref) mail server. If this mail server is unavailable (down or too busy) then if a lower preference mail server is defined (has a higher pref value) it is tried. When all defined mail servers have been tried the mail agent will then fall back to its error recovery strategy - typically an increasing time back-off algorithm over a period of 24 to 48 hours.
What is the “cylon1.sjc.collab.net” and "cylon2.sjc.collab.net" ?
These are the names of the mail exchange servers associated with Collab.net DNS.


Now select a mail exchanger from this  list and connect using telnet protocol....
>telnet cylon1.sjc.collab.net 25

By the way ,What is telnet ?
Telnet is a network protocol used on the Internet or local area networks to provide a bidirectional interactive text-oriented communications.
Where ,25 is the port number , for SMTP.
Then type

helo abc.com
mail from : <abcd.com>
rcpt to: <harish.pmprk@gmail.com
data
.
from: polaris.com
subject: testmailkamesh
kamesh data
.
Note : the period (.) in the end indicates the end of the message .Then we receive an acknowledgement .




…Now click enter , and check the mail account harish.pmprk@gmail.com …we can find the mail received there in the mailbox........


So our experiment is successful ................
Note: The content in green circles is what we want the mail to reflect .It has nothing to do with the sender and receiver. You can put any Tom ,Dick and Harry 's name there..............................
Only that in red lines matter ..... rcpt to: must be a valid one ,,,mail from : can be anything...
Ok ,,,, I know what you are thinking ................
Planning to take revenge on some one whom you dont think very much of ??? by putting their name in the from address????????? .......Hmmm...I know....Ha Ha ......
Now a days people are much smarter than what we think........ So I think you will get caught........
Ok....

Now Its time for us to explore  what a name server is .......
For this, we shall execute the commands
>set q=ns
>google.com



This query is to retrieve the ns record . Where  NS –>Name server
Name server is a program or computer server that implements a name-service protocol. It maps a human readable identifier to a system-internal, often numeric, identification or addressing component.
So it means the domain name google.com is under a number of name servers . So a single domain has number of name servers . The requirement of multiple name servers aims to make the domain still functional even if one name server becomes inaccessible or inoperable.
Name server has the information about the mapping of human readable domain names to numeric (or less comprehensible) IP address .
So as we query the DNS , the DNS , passes this question to the name servers and tries to get the information. 
Let me quote to you the next area of concern ….
What happens if the name servers associated with the local DNS , does not know information about the domain name we gave  ???????????





Now if you observe, the set q=ns for google.com and collab.net….
The first one gives two sections Non authoritative answer and Authoritative answer ,, whereas in the second ,, it doesn’t do so ………..Why ??????????
Because Collabnet  is internal to our network , whereas Google is external to our network.
The fact is that , as we query ,the DNS, first query’s the internal name servers ,in a hope that the domain it is searching  for can be found there itself. As Google is not found in the interior , it query’s the external DNS server to resolve the query and gets the name servers which are capable of resolving the domain name we gave.  But our immediate local DNS does not have authority over external name server’s , So it gives the so called “UN AUTHORITATIVE answers “ indicating that our local DNS , does not have authority over the mentioned external name servers.
And so , It flings a message saying AUTHORITATIVE answers can be got from
ns1.google.com  internet address = 216.239.32.10
ns2.google.com  internet address = 216.239.34.10
ns3.google.com  internet address = 216.239.36.10
ns4.google.com  internet address = 216.239.38.10

This is what I know about SMTP ...


By ,


Harish . K