Вы находитесь на странице: 1из 9

Learning UNIX (in very less time) is a mammoth task.

Its learning curve is steep, but once you learn it, it would help you throughout your life, even in the fields beyond the scope of this course. UNIX is quiet fun too. You merely have to follow a policy just do it. So without any delay lets start off.

Before starting the real deal with command line (shell), we will first learn ways to use UNIX in our system. Installing UNIX is very easy now a days. Here are the steps by which you can use UNIX in your system.

Installing Linux You can install Linux on your computer using many different ways. Some of the simplest methods are:
o

Installing cygwin in windows:




Go to http://cygwin.com/ install.html and follow the steps. Install all the required packages. Once you are done, you can use cygwin as Unix inside windows.

OR
o

Using Pubuntu inside windows




Download Portable Ubuntu from http://sourcefor ge.net/projects/porta bleubuntu/ Downloading and starting the software (even installation is not required)

OR
o

Using cb.vu


You can use online command line interface using this link http://cb.vu/

OR
o

Using Live CD

Download any Linux which supports Live System.


For example you can download http://www .ubuntu.com/deskto p (700 Mb) orhttp://puppylinux.o rg/main/Download% 20Latest%20Releas e.htm (128 Mb)

You can create Live USB simply using this software http://unetb

ootin.sourceforge.ne t/

10 June - 16 June

Activity 2:
Unix Assignment 1 Unix Assignment2 Try out these quizzes. 1. http://networking.ringofsaturn.com/Tools/quizzes.cgi? Action=Take&Quizid=3 2. http://www.ch.embnet.org/CoursEMBnet/Exercises/Q uiz/quix1.html Try out the questions available in the below given sites to improve your understanding of Basic UNIX. 1. "Exams" section in http://www.cs.wichita.edu/~chang/lecture/cs497c/ 2. http://courses.cs.vt.edu/~cs2204/fall2001/quizzes.htm l **************************************************************** ******************************

Activity 3:

The Unix philosophy: The Unix philosophy is philosophical approaches to developing software based on the experience of leading developers of the Unix operating system. (Source: http://bash.cyberciti.biz/guide/Main_Page)
o

Do one thing and do it well - Write programs

o o o

o o

that do one thing and do it well. Write programs to work together. Write programs to handle text streams, because that is a universal interface. Everything is file - Ease of use and security is offered by treating hardware as a file. Small is beautiful- Smaller the code the better it is. N text files - Text file is a universal interface. Easy to create, backup and move to another system. Use shell scripts to increase leverage and portability - Use shell script to automate common tasks across various UNIX / Linux installations. Chain programs together to complete complex task - Use shell pipes and filters to chain small utilities that perform one task at time. Choose portability over efficiency. Keep it Simple, Stupid (KISS).

What is a Shell Script or shell scripting? Normally shells are interactive. It means the shell will accept command from you (via keyboard) and execute them. However, if you store a sequence of commands to a text file and tell the shell to execute the text file instead of entering the commands, that is known as a shell program or shell script. A Shell script can be defined as - "a series of command(s) stored in a plain text file". A shell script is similar to a batch file in MS-DOS, but it is much more powerful compared to a batch file. Shell scripts are a fundamental part of the UNIX and Linux programming environment.

Why shell scripting?


o

Shell scripts can take input from a user or file and output them to the screen.

Whenever you find yourself doing the same task over and over again you should use shell scripting, i.e., repetitive task automation.  Creating your own power tools/utilities.  Automating command input or entry.  Customizing administrative tasks.  Creating simple applications.  Since scripts are well tested, the chances of errors are reduced while configuring services or system administration tasks such as adding new users.

Practical examples where shell scripting actively used


o o o o o o o o

o o

Monitoring your UNIX system. Data backup and creating snapshots. Dumping Oracle or MySQL database for backup. Creating email based alert system. Find out what processes are eating up your system resources. Find out available and free memory. Find out all logged in users and what they are doing. Find out all failed login attempt, if login attempt are continue repeatedly from same network IP automatically block all those IPs accessing your network/service via firewall. User administration as per your own security policies. Find out information about local or remote servers.

Shell scripting is fun. It is useful to create nice (perhaps ugly) things in shell scripting. Here are a few examples of scripts you might use everyday:
o o

Find out today's weather (useful when you are busy in a chat room). Find out what that site is running (just like

o o o

netcraft). Download RSS feeds and display them as you login or in your email. Find out the name of the MP3 file you are listening to. Monitor your domain expiry date every day.

Advantages
o o o o o

Easy to use. Quick start, and interactive debugging. Time Saving. Sys Admin task automation. Shell scripts can execute without any additional effort on nearly any modern UNIX / Linux / BSD / Mac OS X operating system as they are written an interpreted language.

Disadvantages
o o o

Compatibility problems between different platforms. Slow execution speed. A new process launched for almost every shell command executed.

With this much information, let's start off with shell scripting. The shell used for explaining the concepts here is the "Bash" shell. Bash is the shell, or command language interpreter, for the Linux operating system. So lets start, to create a shell script: 34. Use a text editor such as vi. Write

required UNIX commands and logic in the file. 35. Save and close the file (exit from vi). 36. Make the script executable. 37. You should then of course test the script, and once satisfied with the output, move it to the production environment. 38. The simplest program in Bash consists of a line that tells the computer a command.

Start up your favorite text editor (such as vi): vi hello.sh Essential Vi Commands
Open a file: vi filename

To go into edit mode: press ESC and type I To go into command mode: press ESC To save a file press ESC and type :w fileName To save a file and quit: press ESC and type :wq OR press ESC and type :x To jump to a line: press ESC and type :the line number To Search for a string: Press ESC and type /wordToSearch To quit vi: Press ESC and type :q Save the following into a file called hello.sh: #!/bin/bash echo "Hello, World!" echo "Knowledge is power."

Save and close the file. You can run the script as follows: ./hello.sh Sample outputs: bash: ./hello.sh: Permission denied Saving and Running Your Script The command ./hello.sh displayed an error message on the screen. It will not run script since you've not set execute permission for your script hello.sh. To execute this program, type the following command: Username~$ chmod +x hello.sh Username~$ ./hello.sh Sample Outputs: Hello, World! Knowledge is power. To learn more about SHELL SCRIPTING, check out 1. https://supportweb.cs.bham.ac.uk/documentation/tuto rials/docsystem/build/tutorials/unixscripting/unixscripting. pdf 2. http://www.freeos.com/guides/lsst/index.html Chapter 2 3. http://bash.cyberciti.biz/guide/Main_Page . What is a Shell script or shell scripting? . Why Shell scripting? . Chapter 2 : Getting started with Shell Programming 4. http://docs.cafephilo.net/private/(ebook%20pdf)%20Teach%20Yourself %20Shell%20Programming%20for%20UNIX%20in%20 24%20Hours.pdf ****************************************************************

******************************

Week 2 - Activity Tracker for UnixFeedback

Вам также может понравиться