Thursday, September 6, 2007

First Lecture OPS435

OPS435 First Lecture

Linux and Unix

We will be able to write scripts and programs in any Linux Shell, to understand how shell scripts and how they work we will be looking at the basics of the shell, oc and grep to search in databases.

The
Kron shell reference - isbn 0-916151-72-7
VI Reference Card, SSC Inc., ISBN: 1-57831-0 05-9
and the bash shell are very similar if you know one you know the other.

We are expected to go through the slides know and understand what it is about because it will be on the quizzes and the test.

A little bit a of Review of what we know about Linux and Unix,
What happens when you start the computer, everything is does it is told, basically you do, minute instructions on what to do before the computer could do anything, when you turn it on the volatile memory contains nothing,

How does the computer know what to do when you turn it on?

It’s a combination of hardware and software, when you turn it on it has to check the everything within the system. The BIOS the program that loads everything into the computer, BIOS is a program it’s a chip which contains the program which is always their, when you turn it on it starts telling the hardware things to do, when it finishes doing that the BIOS passes control to another program, the very first sector of the very first cylinder of the first drive the Master Boot Record, it has 3 sections the first 2bytes are the signature, other wise when the system looks at the MBR it looks at the sector to see if its that data, and the signature will identify this, the other section, 4 max primary partitions, 16 bytes information is provided to the partition, which is 4x16 is 64 bytes which is referred to the partition table, those 64 bytes tell exactly how the database is partitions, how big where to start and all that, 446 is the third and its 512 all together, the last part is the program that tells the computer what to do, this makes use of some data where the loader is located, otherwise where the operating system is actually located, after it is done it will pass control to the boot loader,


Program Partition
Bootloader

After you initiate the bootlaoder it boots into the operating system, its below the spindles, another thing we should know, the processor can only execute instructions from the memory you can never have data go directly to the processor, memory to processor first, once we start booting the operating system otherwise known as the kernel in Linux, once it is loaded in memory then it goes into the processor, then the processor starts running the operating system, once it starts running, theirs a particular utility the first utility initiates all the other utilities, this is called the INIT every command that is dropped into memory to be in the processor there is a PID number and the first one is obviously PID01, this utility will load all utilities you need, print, telnet, everything loaded by the INIT utilities, one of that that is loaded by INIT is called the Getty, any time you see to tty you are referring to terminals, the

Getty utility - almost like a radar that scans all the terminals all the time , it is looking for if anyone is trying to use the terminal, system, as soon as it detects this it allows them to type in,
ex: user name and password you hit the return immediately

At that point the getty utility will pass control to another utility, called the

Logon utility - this utility does the checking you are who you say you are and you have an account on the system this will check into /etc/passwd which contains all the user names and check the password in /etc/shadow.

After the login it goes to the shell, now the shell is brought into the memory which is given a pid number and it starts running, once it starts running, that when you see the cursor on the screen when it produces the cursor on the screen it is ready to do what you want it to do, and the shell will actually take your command and before it runs it, it will interpret you command, (kernel executes the commands), the shell is learn the C language, the language were learning the Shell, you don’t need to know the Kernel, the language we need to know is the Shell language and what it does is it interprets what you type into the terminal and what the kernel understands its an interpreter, once of the advantages of the shell, it automatically interrupts anything you put in, it will interpret a line when it went in, you can actually read what the programmer wrote, the shell does the interpretation itself, it very important to understand the fact that when you execute a program or any command from the terminal the shell will interpret anything you write, the shell interprets EVERY COMMAND before its executed, it is looking for special characters and has a meaning, when you look at a command you should be able to interpret the commands in exactly the same way on how the shell interprets it. How to program and special characters and how exactly it interprets and some other features. Once it starts running, the shell will go through NINE steps, for every command it goes through NINE steps in a sequence and in each step looking for something specific, when its finished with the NINE steps it will then execute the command and will tell the kernel, this is the interpreted version of the command and the kernel will actually execute the command.

Here is an example of interpretation….

Ls a

This is what is typed in the command line, what is passed in the kernel looks like the exact same thing, because their was no special characters that the shell had to interpret,

Ls a??

The shell takes a look at the command, and it will search to match any files and will find 3 characters that must start with an A, We assumed it found ABC and a23, what is the interpreted version of this command, it will replace the >?< token with BC 23 this is the actual command that is passed=

Ls ABC A23

Copied into the memory then given a pid then executed and run by the processor, the kernel goes and looks for these two files and list the names, SHELL all interpretation.

He lying a little bit because the shell does actually run commands, but they are part of the shell and in memory and can be executed directly, but most of the commands must go through memory and go the kernel to execute.

Shell understands & interprets

Special characters we know about,
• ? --
• ---it says to shell zero or more of any character 0 >
• [ ….] -- 1-3or5square bracket one character, list of character inside the bracket > *?, < loose their special meaning. ! is not.
Understand the ? * ! []

More Examples:

Sort ?[!0-9,a-z]?[A-z]*

We are going to sort a number of files, and the number of files are going to match in that particular directory, it will be finding four or more characters.
First character is the name of any character
Second cannot be a number comma or a lower case letters
Third can be anything
Fourth it can be any letter to capital to lower case A LETTER
Fifth

^ this called file name expansion which the shell does all the time

All capitals are first then small, you can say 1-9 and not 9-1 goes through sequential sequence.

Variables to store data, global or shell variables that are assigned to every user, you are assigned those variables immediately, all shell variables have capital letters, that is one type of variable, another variable it a locally created variable, one u create.

BASH is the name of the shell you are using, and you look at the etc password file and locate the account on their the last item of the line you will see what shell if assigned to you, in matrix the BASH shell is the default shell that is assigned to all users, BASH=/bin/bash is exactly where it is located, var = variable .

What is the path variable used for, the kernel doesn’t know where the utility on the database it is relying on the shell where it is to execute and where it is located on the database it will go and search this particular variable for where its located, it goes into the PATH=/home/unx122/bin: colon is delimiter between directories, it will pass the directory name to the command. The PATH uses it to search where the command where it is located.

You prompt is located in PS1 this is what it looks like, tty =terminal, terminal logged is pts/4 and pts is via the communication network. If its tty/4 then its direct.


See the commands its going to be echo $variable, the $ says the following text is a name of a variable, the text following the dollar sign is the name of the variable when the shell looks atr this what it will do to interpret this it will go an replace the name of the variable with the contents of the variable, the shell interprets the command and comes up with a difference command.
The shell interprets $SHELL to $/bin/bash replacing the name of the variable with the contents of the variable.

You have to have the current directory in ur path or u cant run the program.

/etc/profile

Cal with no arguments tells you current month calander

If not sure use MAN cal [ ]option

The cat command comes from an old English word called concatenate means to join together

No comments: