Essential Unix (and Linux) for the Oracle DBA. Revision no.: PPT/2K403/02

Similar documents
Std: XI CHAPTER-3 LINUX

Appendix B WORKSHOP. SYS-ED/ Computer Education Techniques, Inc.

5/20/2007. Touring Essential Programs

Introduction to UNIX Part II

Assignment clarifications

Getting Started. Running Utilities. Shells. Special Characters. Special Characters. Chapter 2 Unix Utilities for non-programmers

Unix Introduction to UNIX

EECS 2031E. Software Tools Prof. Mokhtar Aboelaze

Lecture # 2 Introduction to UNIX (Part 2)

Basic File Attributes

5/8/2012. Specifying Instructions to the Shell Chapter 8

h/w m/c Kernel shell Application s/w user

Introduction p. 1 Who Should Read This Book? p. 1 What You Need to Know Before Reading This Book p. 2 How This Book Is Organized p.

Introduction to Linux (Part II) BUPT/QMUL 2018/03/21

Perl and R Scripting for Biologists

Editors in Unix come in two general flavours:

RH033 Red Hat Linux Essentials

Hands-on Keyboard: Cyber Experiments for Strategists and Policy Makers

Unix/Linux Basics. Cpt S 223, Fall 2007 Copyright: Washington State University

12.1 UNDERSTANDING UNIX SHELL PROGRAMMING LANGUAGE: AN INTRODUCTION Writing a Simple Script Executing a Script

UNIX Quick Reference

3/8/2017. Unix/Linux Introduction. In this part, we introduce. What does an OS do? Examples

for more :-

Introduction to UNIX. Logging in. Basic System Architecture 10/7/10. most systems have graphical login on Linux machines

FREEENGINEER.ORG. 1 of 6 11/5/15 8:31 PM. Learn UNIX in 10 minutes. Version 1.3. Preface

GNU/Linux 101. Casey McLaughlin. Research Computing Center Spring Workshop Series 2018

Chapter 1. Getting started with UNIX

Standard. Shells. tcsh. A shell script is a file that contains shell commands that perform a useful function. It is also known as shell program.

Outline. Structure of a UNIX command

Review of Fundamentals

Unix as a Platform Exercises. Course Code: OS-01-UNXPLAT

Week Overview. Unix file system File types and file naming Basic file system commands: pwd,cd,ls,mkdir,rmdir,mv,cp,rm man pages

Software I: Utilities and Internals. What is vi?

Table of contents. Our goal. Notes. Notes. Notes. Summer June 29, Our goal is to see how we can use Unix as a tool for developing programs

EECS2301. Lab 1 Winter 2016

UNIX Essentials Featuring Solaris 10 Op System

Unix Handouts. Shantanu N Kulkarni

IMPORTANT: Logging Off LOGGING IN

Operating Systems, Unix Files and Commands SEEM

System Programming. Unix Shells

CISC 220 fall 2011, set 1: Linux basics

Embedded Linux Systems. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

Operating Systems Lab 1 (Users, Groups, and Security)

Introduction to Linux Workshop 1

Operating Systems. Copyleft 2005, Binnur Kurt

UNIX Basics. UNIX Basics CIS 218 Oakton Community College

Operating Systems 3. Operating Systems. Content. What is an Operating System? What is an Operating System? Resource Abstraction and Sharing

Unix as a Platform Exercises + Solutions. Course Code: OS 01 UNXPLAT

Chapter 9. Shell and Kernel

Introduction to Linux. Woo-Yeong Jeong Computer Systems Laboratory Sungkyunkwan University

Practical Computing-II. Programming in the Linux Environment. 0. An Introduction. B.W.Gore. March 20, 2015

UNIX COMMANDS AND SHELLS. UNIX Programming 2015 Fall by Euiseong Seo

Introduction to Linux Environment. Yun-Wen Chen

CHAPTER 3 SHELL PROGRAMS: SCRIPTS

100 SHELL PROGRAMS IN UNIX

System Programming. Introduction to Unix

Unix File System. Learning command-line navigation of the file system is essential for efficient system usage

S E C T I O N O V E R V I E W

Introduction to the UNIX command line

Lab 3a Using the vi editor

Vi & Shell Scripting

QUESTION BANK ON UNIX & SHELL PROGRAMMING-502 (CORE PAPER-2)

Shell Start-up and Configuration Files

Statistics 202A - vi Tutorial

UNIT V. Dr.T.Logeswari. Unix Shell Programming - Forouzan

Introduction: What is Unix?

BIOINFORMATICS POST-DIPLOMA PROGRAM SUBJECT OUTLINE Subject Title: OPERATING SYSTEMS AND PROJECT MANAGEMENT Subject Code: BIF713 Subject Description:

AC109/AT109 UNIX & SHELL PROGRAMMING DEC 2014

The Online Unix Manual

Introduction to Linux

Using LINUX a BCMB/CHEM 8190 Tutorial Updated (1/17/12)

CHE3935. Lecture 1. Introduction to Linux

UNIX Commands. Ex: $ pwd $/tmp $cd/home/sales, this will change the directory from /tmp to /home/sales.

5/8/2012. Encryption-based Protection. Protection based on Access Permission (Contd) File Security, Setting and Using Permissions Chapter 9

Unix Basics. UNIX Introduction. Lecture 14

Basic Unix Command. It is used to see the manual of the various command. It helps in selecting the correct options

Examples: Directory pathname: File pathname: /home/username/ics124/assignments/ /home/username/ops224/assignments/assn1.txt

Creating a Shell or Command Interperter Program CSCI411 Lab

CST Algonquin College 2

1Z Oracle Linux Fundamentals (Oracle Partner Network) Exam Summary Syllabus Questions

UNIX System Programming Lecture 3: BASH Programming

Computer Systems and Architecture

Qedit 5.7 for HP-UX. Change Notice. by Robelle Solutions Technology Inc.

Review of Fundamentals. Todd Kelley CST8207 Todd Kelley 1

Welcome to Linux. Lecture 1.1

Implementation of a simple shell, xssh

Unix Internal Assessment-2 solution. Ans:There are two ways of starting a job in the background with the shell s & operator and the nohup command.

Introduction to Linux

CS4350 Unix Programming. Outline

Qedit 5.6 for HP-UX. Change Notice. by Robelle Solutions Technology Inc.

Appendix A GLOSSARY. SYS-ED/ Computer Education Techniques, Inc.

Linux Operating System Environment Computadors Grau en Ciència i Enginyeria de Dades Q2

Introduction to Linux (Part I) BUPT/QMUL 2018/03/14

UNIX ASSIGNMENT 1 TYBCA (Sem:V)

Introduction to UNIX Command Line

Using the Vi Text Editor

Linux & Shell Programming 2014

Unix System Architecture, File System, and Shell Commands

Review of Fundamentals. Todd Kelley CST8207 Todd Kelley 1

Linux Shell Script. J. K. Mandal

Transcription:

Essential Unix (and Linux) for the Oracle DBA Revision no.: PPT/2K403/02

Architecture of UNIX Systems 2

UNIX System Structure 3 Operating system interacts directly with Hardware Provides common services to programs Insulating from Hardware Kernel is treated as an operating system Programs are independent of the Hardware Easy to move on different processing environment Programs should be independent of Hardware

UNIX System Structure (contd.) 4 Programs in the upper layer communicate with Kernel using defined set of system calls System calls instruct the Kernel to do various operations System calls also exchange the data between Kernel and program Some Standard programs also fall in this layer i.e. executable files by C compiler Top most layer is used for other application programs eg. C compiler (CC)

SHELL 5 It is a program that interprets the commands. If the command is valid then the shell directs the kernel to carry out the request If invalid then an error message is displayed. Shell starts when an user logs in, and terminates when the user logs out. Presence of shell is indicated by a special symbol known as the shell prompt ( $ or # ).

SHELL (contd.) 6 Several shells are available to handle the same hardware in different ways. Redirection of data : the shell facilitates chaining or "pipelining" of commands, i.e. the output of one program flows down the pipe and becomes an input to the next program.

SHELL (contd.) 7 Program execution Interpretive programming language File name substitutio n SHELL Environment control Pipeline hookup I/O Redirectio n

Different shells 8 Bourne shell or Standard shell (sh) : Introduced in 1978 and is widely used in AT&T Unix. Gives "$" as the prompt to the user and " # " to the superuser (root). One disadvantage is that it does not provide command history.

Different shells (contd.) 9 C shell (csh) : Gives "%" as the prompt to user. It is different from the sh. Syntax is similar to the C language programming. It is quite popular among the programmers. Provides aliasing of the command i.e. the ability to customize the command names.

Different shells (contd.) 10 Restricted shell (rsh) : Basically designed to restrict the rights of normal users It cannot execute cd command path variable command containing "/ redirect outputs

Different shells (contd.) 11 The Korn Shell The Korn shell is a product of AT&T Bell labs & was developed by David Korn. It has many novel features like the facility to edit the command line,the history mechanism, aliases & job control. Moreover the Korn shell also lets you handle computations awk-like formatted printing & simplified menu routines.

Accessing the Unix System 12 Directly from the server hosting the database itself Via a UNIX workstation Through a Windows NT Server front end.

Basic Unix Commands 13 cd date echo grep history passwd pwd uname Change directories Display time & date Display text on your screen Is a pattern-recognition command. Gives you the commands entered previously by users. $ history 3 To change users password Display present working directory Display the machines symbolic name

Basic Unix Commands 14 whereis As the name of this command indicates, whereis will give you the exact location of the executable file for the utility in question. $ whereis who: /usr/bin/who /usr/share/man1.z/who.1$ which Enables you to find out which version of a command the shell is using. $ /bin/cat$$ which cat who whoami Display list of all the users currently logged into the system. Indicates who you are logged in as.

Linux Environment 15 /etc/profile file owned and managed by the system administrator. It is used to automatically set the environment variables for users at login time. The shell looks in users home directory as an alternative location for environment information in the.profile file. env command is used to display the entire set of environment variables. Use export command to set any environment variable. Eg export ORACLE_SID=prod2

Input & output in Unix 16 Command < > >> << 2> Eg. Description Redirects standard input Redirects standard output Appends standard output to a file Appends standard input to a file Redirects standard error $ date > file1.txt $ file1 < file2.txt $ date file2

Files in the Unix system 17 Ordinary files These files can contain text, data, or programs. Directories Directories contain files & directories. Special files These files are use for input/output devices such as printers and terminals. Linking Files A symbolic link is a pointer to another file. $ ln clear cls

File Permission 18 ls l command list the details of file along with its permission. -rwx-x r 1 oracle dba Apr 11 2004 test.ksh chmod go+x test.ksh

File Permission (contd.) 19 SYMBOLIC PRIVILIGE --- --x rw- -w- -wx r-- r-x rwx OCTAL NUMBER PRIVILEGE 0 1 2 3 4 5 6 7 DESCRIPTION No privileges Execute only Write only Write & execute Read only Read & execute Read & write Read, write & execute

File Permission (contd.) 20 All files come with read & write privileges assigned Directories come with read, write, and execute privileges turned on. UNIX provides a feature called umask Umask changes the default permissions on new files An unmask with the value 022 means all new files will by default have the write permission denied to the group and others in the system.

Important Unix Directories 21 Directory /etc /dev /tmp /home root Description The /etc directory is where the system administrator keeps the system configuration file. Eg etc/passwd file The /dev directory has device files for example printer configuration files. The /tmp directory is where the system keeps temporary files. The home directory is the directory assigned to you by your UNIX administrator when he or she creates your initial account. The root directory, denoted simple by a forward slash (/), is owned by the system administrator 7 is the very top level of the treelike directory structure

VI EDITOR 22 Visual Editor is Unix system default editor. It allows you to move the cursor around in the edit buffer window easily. The cursor may be moved forward or backward a character, a word, a sentence or a paragraph at a time. Vi editor has three modes : Mode 1 command mode Mode 2 input mode Mode 3 ex mode

Modes in Visual editor 23 : prompt mode Press : Press Esc Key Command Mode Press Esc Key Press i or a key Editing mode

Set showmode 24 Till you can get familiar in working with vi, it is advisable that to use a command set showmode at the prompt, before you start editing. This command sets any of the parameters of the vi environment & displays a message at the bottom right of your screen, whenever the input mode is invoked. To set this mode enter a: ( the ex prompt) Then at the colon prompt type: :set showmode This is command in ex mode.

Command For Insertion 25 Command i I a A o O Operation Insert before cursor Insert at beginning of line Append after cursor Append at the end of the line Insert a blank line below cursor position Insert a blank line above cursor position

Command For Cursor Movements 26 Command h l j k 0 ^ Shift-G Shift-:1 Operation From current position one char towards left From current position one char towards right From current position one line towards down From current position one line towards down Takes cursor from any position of current line to the BOF current line. Go to start of the current line Go to the end of the file Go to the top of the file

Command For Cursor Movements 27 Command ^E ^Y ^U ^D ^F Operation Scroll down one line Scroll up one line Scroll up half a window Scroll down half a window Move window forward through the file.

Command For Cursor Movements (contd.) 28 ^b w e b :n :$ Move window backward through the file. Move forward to beginning of word End of the current word Move backward to the beginning of word To go to particular line (:10) To go to the last line of the file

Command For Deleting Text 29 Command x X dd dw D ndd ndw Operation Delete a char at the cursor position and line shift towards left (like del key) Delete a char at the previous cursor position and line shift towards left (like backspace key) Delete the current line Delete the current word Delete upto end of line from cursor position Delete n lines from current line Delete n words from current word

Command For Changing Text 30 Command r R ns C cw Operation Replace current character by later Replace more than one character (Press Esc key to terminate) Substitute n characters by any no. Of characters (Press Esc key to terminate) Change to end of line from cursor position (Press Esc key to terminate) Change word (Press Esc key to terminate)

Yanking (Copy & Paste) & Undo 31 Command yy Y p P nyy ny yw u U Operation From any position of current line yanks the current line Paste below the current line Paste above the current line Yanks n lines from current line yanks the current word Undo the last change (toggle between the current & last change) Cancels all the changes done on the current line.

Colon Prompt commands 32 Command w wq w <new file> q q! w! <new file> e <filename> e# rew n Operation Save Save & quit vi editor Save as new file Quit (provided file has been saved) Quit without saving Overwrite existing file To open another file Toggle between current & previous file To go the first file To move to the next file

Shell script 33 A shell programming is nothing but a series of Unix commands. Instead of doing one job at a time, u can give the shell a to-do list that carries out the entire procedure. Shell programs can be used for variety of tasks from customizing your environment to automating your daily tasks. Eg your.profile file

Defining variables $ displaying on the Screen 34 wish= Hello Everybody echo $wish Hello Everybody so to print the value of the variable use $ echo `who` will print output of the who command. Here ` (back quote) is used to print output of the command

Local & Global variables 35 Ordinarily shell variables is a local variable, means known only to the shell that created it. In order to make the old shell s variable available we use the export command. Eg export ME ME= cms echo $ME (prints cms) sh (defines new child shell) echo $ME (prints cms) ME= cms institute echo $ME (prints cms institute) press control D (to return to parent shell) echo $ME (prints cms)

Understanding the.profile file 36 When u log in to a UNIX system, the system looks into your directory for a file called.profile. This file contains startup instructions for your account. This file contains definitions for several shell variables, and it exports them to make global. Since your.profile file belongs to you, you modify it. Oracle also require.profile file to add some of its parameters.

Interactive shell scripts 37 Interactive shell scripts are based on using Unix shell commands read & echo, & on using shell variables. For example echo Dear user, what is your name\? read name echo Glad to meet you, $name In the above example we use the backslash to remove the special pattern-matching property of the question mark character

Command Substitution 38 What makes the set command useful in assigning positional parameter values is that its arguments need not be fixed in advance. When a command is enclosed in back-quotes, the command is replaced by the output it produces. This process is called command substitution Eg echo `who`

Script,Pipes& Redirection 39 A script can use pipes & redirection both internally & externally. For eg:- suppose we want a command that joins a list of files,passes the resulting file thro pr to format the file, & sends that output to lpr. This can be done by cat $* pr lpr

Loops in Shell script 40 A while-do-done loop while condition do commands done A for-do-done loop for var in list do commands done An until-do-done loop until condition do commands done

Conditional Branching 41 The if-then-else Control Structure If condition then action a else action b fi The case statement Case var in pattern1) commands ;; pattern2) commands ;; patternn) commands ;; esac

Unix Processes 42 When a shell program is executed, unix creates an active instance of your program called the process. Unix assign a unique identification number called the process ID (PID). A DBA should know how to track the processes that pertain to your programs and the database instance that you are managing. The ps command is used to find the processes running. The ps ef command will let you know the process ID, the user, the program the user is executing, and the length of the program s execution.

Terminating Processes with the kill command 43 Kill [ signal ] PID will kill the processes Kill 9 233456 will kill the processes running with the PID above.

Unix Backup and Restore Utilities 44 Tar and cpio commands are use to perform backups in unix. $ tar cvf /dev/rmt/0m /u10/oradata/data/data01.dbf will compress the file data01.dbf and copy it to a tape named /dev/rmt/0m. -cvf create a new archive. The following command will extract the backed up files from the tape to the specified directory: $ tar xvf /dev/rmt/0m /u20/oradata/data/data01.dbf

Unix Backup and Restore Utilities (contd.) 45 ls cpio 0 > /dev/rmt/0m Will copy the contents of the entire directory to the tape name /dev/rmt/0m cpio i < /dev/rmt/0m The cpio command with the i option restores all the contents of the tape named /dev/rmt/0m to the current directory

The Crontab and Automation of Scripts 46 DBAs will have to schedule their shell programs and other data loading programs for regular execution by the Unix administrator Unix provides the cron table to schedule database tasks. One can invoke the crontab by crontab 1. To add programs to the schedule or make scheduling changes, the command is crontab e. #----------------------------------------------------------------------- minute hour date month day of week command 30 18 * * 1-6 analyze.ksh #-------------------------------------------------------------------------------------- The preceding code indicates that the program analyze.ksh will be run Monday through Saturday at 6:30 P.M.

The Crontab and Automation of Scripts 47

48 Design & Published by: CMS Institute, Design & Development Centre, CMS House, Plot No. 91, Street No.7, MIDC, Marol, Andheri (E), Mumbai 400093, Tel: 91-22-28216511, 28329198 Email: courseware.inst@cmail.cms.co.in www.cmsinstitute.co.in