Unix Training COE Academy

Post on 04-Jun-2018

227 views 0 download

transcript

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 1/81

UNIX Training

C3: Protected

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 2/81

Welcome

C3: Protected

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 3/81

© 2008, Cognizant Technology Solutions Confidential

Who am I?

ABILASH KARUTHETHIL >> AB

Electronics and Comm. Engineering

Sun Certified System Administrator for Solaris OS Version 9

4 years Experience in IT and Solaris

Previously Worked for INFOSYS & EDS

Joined CTS on Sept2010

Associate Id : 253309 Here for sharing the UNIX Knowledge what I learnt from my

experience.

3

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 4/81

© 2008, Cognizant Technology Solutions Confidential

May I Know you?

Name

Experience

Project

Knowledge about UNIX

4

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 5/81

© 2008, Cognizant Technology Solutions Confidential

Course Map –  Day 1

What is OS

UNIX History and Overview

Advantages of UNIX OS

File System Concepts

How to connect Unix Machine

File Manipulation commands

Directory Manipulation commands

More commands related to File system

Permission

User Account

5

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 6/81

© 2008, Cognizant Technology Solutions Confidential

Course Map –  Day 2

Shell

Controlling System Process

Scheduling the Jobs

Basic Networking

Useful commands

Important File Systems and Log Locations

6

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 7/81

Day - 1

C3: Protected

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 8/81

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 9/81

© 2008, Cognizant Technology Solutions Confidential

UNIX History and Overview

UNIX was developed by AT & T researchers namely KenThompson and Dennies Ritchie for internal use. Later manyUnix flavor emerged named AIX from IBM, HP-UX from HP,Sun OS (Solaris) from Sun and so on.

Finnish college student LINUS TORVALDS developed Linux in1991. (Linus created Linux Kernal)

9

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 10/81

© 2008, Cognizant Technology Solutions Confidential

 Advantages of UNIX

Full multitasking with protected memory. Multiple users can run multipleprograms each at the same time without interfering with each other orcrashing the system.

Very efficient virtual memory, so many programs can run with a modest

amount of physical memory.

Access controls and security. All users must be authenticated by a validaccount and password to use the system at all. All files are owned byparticular accounts. The owner can decide whether others have read or

write access to his files.

A rich set of small commands and utilities that do specific tasks well -- notcluttered up with lots of special options.

10

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 11/81

© 2008, Cognizant Technology Solutions Confidential

 Advantages of UNIX

Ability to string commands and utilities together in unlimited ways toaccomplish more complicated tasks -- not limited to preconfiguredcombinations or menus, as in personal computer systems.

A powerfully unified file system. Everything is a file: data, programs, and allphysical devices. Entire file system appears as a single large tree of nesteddirectories, regardless of how many different physical devices (disks) areincluded.

Available on a wide variety of machines - the most truly portable operatingsystem.

11

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 12/81

File system Concept

C3: Protected

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 13/81

© 2008, Cognizant Technology Solutions Confidential

File System, File & Directory

Unix is managed by File system.

File system - Hierarchical arrangement of files and directories

File – Collection of data items stored on the disk. It is may beraw data, Music file etc.

Directory – Contains the group of files.

In Unix everything is a file,(including H/W, Configuration data)

13

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 14/81

© 2008, Cognizant Technology Solutions Confidential

File System, File & Directory

Files are grouped in the directory structure. The file-system is arrangedlike hierarchical tree (inverted)structure.

The top of the tree is called “root” which usually contains several sub-

directories. In UNIX “/”(forward slash) is used to present the “root”.

/root

lib bin

Name are case-sensitive, Delimited by the / (forward slash)

14

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 15/81

© 2008, Cognizant Technology Solutions Confidential

File Components

File has three components

File Name – is a object must often used to access and manipulate the file

Inode  - is a object of the Unix OS used to record the information about thefile

Data block - Unit of the dsik space that are used to store the data

Filename associated with inode and it give access to the data block

Filename --> Inode --> Datablock

15

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 16/81

© 2008, Cognizant Technology Solutions Confidential

File Types

Regular File - All files are regular file. Ex : Text file, Binary file etc.

Directory  - Contains any kind of files

Device file – It is provide the access to the device. There are two types indevice file. Block special file : communicate with h/w with block of data atime. Character file : Communicate with h/w one char a time.

Symbolic Link – It is point to another file. It contains the pathname of thefile to which it point. The size of the file is always matches the number ofthe characters in the path name it contains. It can be point any file,directory or other symbolic link.

 16

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 17/81

© 2008, Cognizant Technology Solutions Confidential

Home Directory

A Home directory is a file system directory on a multi-user operatingsystem containing files for a given user of the system.

Home directory will be created, when user created on the system

Separating user data from system-wide data avoids redundancy

A user will be automatically placed into their home directory upon login

The ~ (tilde character) shorthand command refers to that particular users

home directory

Example : /export/home/shandy – is the home directory of the usershandy.

17

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 18/81

© 2008, Cognizant Technology Solutions Confidential

Pathnames

Absolute Pathnames

In the previous tree/users/usern/file1 isan absolute

pathname. 

Relative pathnames

If you are already inthe users directory,the relative pathname

for file1 is usern/file1. 

18

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 19/81

How to Connect the Unix

Machine

C3: Protected

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 20/81

© 2008, Cognizant Technology Solutions Confidential

Connect the Unix Machine

We connect the Unix machine using putty exe, if machine is located inremote. It is open source software we can get it from internet.

If you run the putty.exe, It will ask the details like below

20

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 21/81

© 2008, Cognizant Technology Solutions Confidential

Connect Unix Machine

Enter IP Address of the machine or name into the filed Host Name andselect respective protocol to connect the server. Normally we choose SSH.Then click open, It will ask the login name Like below window

21

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 22/81

© 2008, Cognizant Technology Solutions Confidential

Connect Unix Machine

Once Login name entered, It will ask password for the user entered in thelogin prompt. Once you entered the password. It will logon the machine.

22

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 23/81

File Manipulation Commands

C3: Protected

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 24/81

© 2008, Cognizant Technology Solutions Confidential

File Manipulation Commands

Create the file – cat & viEx :

$$ cat > hi

Red

Blue

<control-D>

List the the file – ls command

Ex :$$ ls –l hi

-rw-r--r-- 1 191278 staff 9 Oct 13 02:21 hi

$$

24

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 25/81

© 2008, Cognizant Technology Solutions Confidential

File Manipulation Commands

View the file – cat, more, less, head, tailEx :

$$ cat hi

Red

Blue

$$

Copy the the file – cp command

Ex :$$ cp hi hello

$$

25

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 26/81

© 2008, Cognizant Technology Solutions Confidential

File Manipulation Commands

Rename the file – mv commandEx :

$$ mv hi hello

$$

Delete the the file – rm command

Ex :

$$ rm hi

$$

Modify the file – vi command

Ex :

$$vi hi

$$ 26

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 27/81

© 2008, Cognizant Technology Solutions Confidential

Vi Editor

Vi : the “Visual editor”, Standard Linux and Unix editor 

To Create new file or opening the existing file

 $vi {option} file name

If the file exists, the file is opened and content are displayed

If the file doesn’t exists, vi creates it when the edits are saved for the first time 

Options : -m file is not modifiable, -x encrypt file when saving and decrypt filewhen editing, and so on.

Entering insert mode

a append mode, i insert before cursor

To exit insert mode, hit <Esc> key

27

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 28/81

© 2008, Cognizant Technology Solutions Confidential

Vi Editor

Manipulation in vi editor

<esc> +yy – To copy the content of current cursor line

<esc> +3yy – To copy the content of 3 line below current cursor line

<esc> +p – To paste the single line

<esc> +dd – To delete the current cursor line <esc> +5dd – To delete five lines

<esc> +cc – To cut current cursor line

Saving and Exiting : ex mode

<esc> : wq – Save and quit the file

<esc> : wq! – Forcing to change and quit

<esc> : w! –  Don’t exit, forcible save the file

<esc> :x – Save and exit the file

<esc> :q! – Forcible exit witout save the file28

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 29/81

Directory Manipulation

Commands

C3: Protected

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 30/81

© 2008, Cognizant Technology Solutions Confidential

Directory Manipulation Commands

Create the Directory – mkdir command

Ex :

$$ mkdir test

$$

Change the Directory – cd command ( You can use both absolute andrelative path name for changing the directory)

Ex :$$ cd /export/home/shandy/test

$$

30

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 31/81

© 2008, Cognizant Technology Solutions Confidential

Directory Manipulation Commands

Delete the Directory – rmdir (if only directory is empy) & rm -f commandEx :

$$ rmdir test

$$

$$ rm –f test

Rename the Directory – mv command ( You can use both absolute andrelative path name for changing the directory)

Ex :

$$ mv test test1$$

Present work Directory – pwd command

31

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 32/81

More Commands 

d

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 33/81

© 2008, Cognizant Technology Solutions Confidential

More Commands

Command to check inode number for the file

$ ls -i hi

6219 hi

$

6219 – is a inode number

Command to create a symbolic link

$ ln -s hi hello

$ ls –ltr

-rw-r--r-- 1 w142922 staff 9 Oct 13 02:21 hi

lrwxrwxrwx 1 w142922 staff 2 Oct 14 04:06 hello -> hi

$

33

d

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 34/81

© 2008, Cognizant Technology Solutions Confidential

More Commands

Command to check file system usage

$ df -k /

Filesystem kbytes used avail capacity Mounted on

rtpool/ROOT/s10s_u6wos_07b

30449664 10074647 11687398 47% /

$ du -h /export/home/191278

7K /export/home/191278

$

Command to find the file$find <dir> {condition} {action}

$ find /export/home/191278 -name hi

/export/home/191278/hi

$34

d

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 35/81

© 2008, Cognizant Technology Solutions Confidential

More Commands

Archiving the files : - Placing Many file into one target file

Creating the tar

tar –cvf tar_file_name file

Ex :

$tar –cvf shans.tar hi hello

Inspecting the tar

$ tar –tvf shans.tar

Above command display list of all files in the archive

Extracting the archive

The archive will be extracted in the current directory

$tar –xvf shans.tar 

35

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 36/81

Permission 

i i

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 37/81

© 2008, Cognizant Technology Solutions Confidential

Permissions

There are three types of file access supported by UNIX.

r – read, view the contents of a file or a directory

w –write, edit file/directory contents

x –execute, run executable file

Here’s an example 

Suppose you type in ls -l and the result is

- rwx r-x r--  1 hans doc 858 Aug 22 22:28 hw1

What do all these symbols mean?

37

i i

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 38/81

© 2008, Cognizant Technology Solutions Confidential

Permissions

-rwx r-x r--  1 hans doc 858 Aug 22 22:28 hw1 

typeowner

groupsize Modification

date/time

File name

User

permissions

Group

permissions

Other

Permissions

links

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 39/81

P i i

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 40/81

© 2008, Cognizant Technology Solutions Confidential

Permissions

read=4;write= 2;execute=1rwx r-x  r-- 

4 + 2 + 1

7 5 4 

4 + 0 + 1 4 + 0 + 0

P i i

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 41/81

© 2008, Cognizant Technology Solutions Confidential

Permission

rwx r-x r-- is a symbolic way to specify file modes, while 754 isa numeric way (remember 7 111, 5101, 4100 ? ). Howwould you represent this file mode numerically?

--x --x –wx

How would you represent this bit string symbolically?6 1 4

41

P i i Ch i d

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 42/81

© 2008, Cognizant Technology Solutions Confidential

Permission Changing command

chmod - command to change the access mode of a file

Ex :

Before :

-rw-r--r-- 1 191278 staff 0 Oct 15 02:42 script.sh

Run the command :

$chmod 755 script.sh or $chmod u=rwx,g=rx,o=rx script.sh

After :

-rwxr-xr-x 1 191278 staff 0 Oct 15 02:42 script.sh

42

Sti k bit P i i

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 43/81

© 2008, Cognizant Technology Solutions Confidential

Sticky bit Permission

The Sticky Bit is a special permission that protects the files within apublicly writable directory.

If the directory permissions have the Sticky Bit set, a file can be deletedonly by the owner of the file, the owner of the directory, or by the root user.

This prevents a user from deleting other users’ files from publicly writabledirectories.

Use the ls command to determine if a directory has the Sticky Bitpermission set.

$ ls -ld /tmp

drwxrwxrwt  6 root sys 719 May 31 03:30 /tmp

The Sticky Bit displays as the letter “t” in the execute field for other. 

43

U k

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 44/81

© 2008, Cognizant Technology Solutions Confidential

Umask

The umask  (UNIX shorthand for "user file-creation mode mask") is a four-digit octal number that UNIX uses to determine the file permission fornewly created files

Default umask is 022 and it is defined in /etc/profile file.

If umask value is 022, File will be created with permission of 666-022 =644

If umask value is 022, Directory will be created with permission of 777 – 022 = 755

44

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 45/81

User Account 

U r A t

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 46/81

© 2008, Cognizant Technology Solutions Confidential

User Account

Whoever required Unix server access, they should have the user id or login

id.

Main Components of a User Account

User name – A unique name that a user enters to log in to a system.The

user name is also called the login name.

Password – A combination of up to 256 letters, numbers, or specialcharacters that a user enters with the login name to gain access to asystem.

UID number – A user account’s unique numerical identification within

the system.

46

U A t

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 47/81

© 2008, Cognizant Technology Solutions Confidential

User Account

Group identification (GID) number – A unique numerical identificationof the group to which the user belongs.

Comment  – Information that identifies the user

User’s home directory – A directory into which the user is placed afterlogin. The directory is provided to the user to store and create

User’s login shell – The user’s work environment is set up by the

initialization files that are defined by the user’s login shell. 

47

S t Fil Th t St U A t I f ti

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 48/81

© 2008, Cognizant Technology Solutions Confidential

System Files That Store User Account Information

/etc/passwd - Authorized system users have login account entries

/etc/shadow - contains the encrypted passwords.

/etc/group - Defines the default system group entries

Root User : has complete control over the system.

48

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 49/81

Day-2 

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 50/81

Unix Shell 

Sh ll

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 51/81

© 2008, Cognizant Technology Solutions Confidential

Shell

The shell  is a command programming language that provides an interfaceto the UNIX operating system

Unix has many shells, they are Bourne shell (sh) - This is the original Unix shell written by Steve Bourne of Bell Labs. It is

available on all UNIX systems. This shell does not have the interactive facilites provided by modernshells such as the C shell and Korn shell.

C shell (csh) - This shell was written at the University of California, Berkeley. It provides a C-likelanguage with which to write shell scripts - hence its name

TC shell (tcsh) - This shell is available in the public domain. It provides all the features of the C shelltogether with emacs style editing of the command line

Korn shell (ksh) - This shell was written by David Korn of Bell labs. It is now provided as thestandard shell on Unix systems. It provides all the features of the C and TC shells together with a shellprogramming language similar to that of the original Bourne shell. It is the most efficient shell.Consider using this as your standard interactive shell.

Bourne Again SHell (bash) - bash provides all the interactive features of the C shell (csh) and the

Korn shell (ksh). Its programming language is compatible with the Bourne shell (sh). If you use theBourne shell (sh) for shell programming consider using bash as your complete shell environment.

51

Unix Kernel

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 52/81

© 2008, Cognizant Technology Solutions Confidential

Unix Kernel

A Unix kernel— the core or key components of the operating system — consists of many kernel subsystems like process management, memorymanagement, file management, device management and networkmanagement.

The kernel provides these and other basic services: separation betweenuser and system space, system calls, scheduling, timer and clock handling,.

As an illustration of the way that the shell and the kernel work together,suppose a user types rm myfile (which has the effect of removing the file

myfile). The shell searches the file store for the file containing the programrm, and then requests the kernel, through system calls, to execute theprogram rm on myfile. When the process rm myfile has finished running,the shell then returns the UNIX prompt % to the user, indicating that it iswaiting for further commands.

52

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 53/81

Controlling the System Process 

What is the Process

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 54/81

© 2008, Cognizant Technology Solutions Confidential

What is the Process

A process is any program that is running on the system.

All processes are assigned a unique process identification(PID) number, which is used by the kernel to track andmanage the process.

The PID numbers are used by the root and regular users toidentify and control their processes.

54

Viewing System Processes

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 55/81

© 2008, Cognizant Technology Solutions Confidential

Viewing System Processes

The prstat or ps command examines and displays information about activeprocesses on the system.

Ex :

# prstat

PID USERNAME SIZE RSS STATE PRI NICE TIME CPU PROCESS/NLWP

1641 root 4864K 4520K cpu0 59 0 0:00:00 0.5% prstat/1

1635 root 1504K 1168K sleep 59 0 0:00:00 0.3% ksh/1

9 root 6096K 4072K sleep 59 0 0:00:29 0.1% svc.configd/11566 root 82M 30M sleep 29 10 0:00:36 0.1% java/14

1633 root 2232K 1520K sleep 59 0 0:00:00 0.1% in.rlogind/1

531 root 8200K 2928K sleep 59 0 0:00:12 0.1% dtgreet/1

55

The state of the process

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 56/81

© 2008, Cognizant Technology Solutions Confidential

The state of the process

cpu – The process is running on the CPU.

sleep – The process is waiting for an event to complete.

run – The process is in the run queue.

zombie – The process terminated, and the parent is not

waiting.

stop – The process is stopped.

56

Killing Frozen Processes

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 57/81

© 2008, Cognizant Technology Solutions Confidential

Killing Frozen Processes

You use the kill command or the pkill command to send a signal to one ormore running processes. You would typically use these commands to killan unwanted process.

The format for the kill command is:

#kill -signal PID

The format for the pkill command is:

#pkill -signal Process

57

Killing Frozen Processes

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 58/81

© 2008, Cognizant Technology Solutions Confidential

Killing Frozen Processes

Before killing the process, we need to findout the PID for process, Usingfollowing command we can find the PID for process

#pgrep -l mail

241 sendmail

240 sendmail or

# ps -e | grep sendmail 

241 ? 0:00 sendmail

240 ? 0:02 sendmailThen you can kill using processname or PID

# pkill sendmail

# kill 241 (Default signal 15 ) 

58

Killing Frozen Processes

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 59/81

© 2008, Cognizant Technology Solutions Confidential

Killing Frozen Processes

To terminate more than one process at the same time, use the following

syntax:

# kill -signal PID PID PID PID

# pkill signal process process

Signal Number --- Signal Name --- Event --- efault Action

1 --- SIGHUP --- Hangup --- Exit

2 --- SIGINT --- Interrupt --- Exit

9 ---SIGKILL --- Kill --- Exit

15 --- SIGTERM --- Terminate --- Exit

Some processes can be written to ignore Signal 15. Processes that do not respondto a Signal 15 can be terminated by force by using Signal 9 with the kill or pkillcommands. You use the following syntax:

# kill -9 PID or # pkill -9 process

59

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 60/81

Scheduling the Jobs 

Scheduling an Automatic One-Time Execution of a

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 61/81

© 2008, Cognizant Technology Solutions Confidential

Command

Use the at command to automatically execute a job only once at a specified time.

The format for the at command is:

#at -m -q queuename time date

#at -r job#at –l

-m - Sends mail to the user after the job has finished

-r job - Removes a scheduled at job from the queue

-q queuename - Specifies a specific queuetime - Specifies a time for the command to execute

-l - Reports all jobs scheduled for the invoking user

date - Specifies an optional date for the command to execute, which is either a monthname followed by a day number or a day of the week  

61

Scheduling an Automatic One-Time Execution of a

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 62/81

© 2008, Cognizant Technology Solutions Confidential

Command

Ex :

# at 9:00 pm

at> find /export/home -name core -exec file {} \; >> /var/tmp/corelog

at> <EOT>

commands will be executed using /sbin/sh

job 1098648000.a at Mon Oct 25 21:00:00 2004

To display information about the execution times of jobs, perform the command:

# at -l 1098648000.a

1098648000.a Mon Oct 25 21:00:00 2004

For example, to remove job 1098648000.a from the at queue, perform thecommand:

# at -r 1098648000.a 

62

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 63/81

Scheduling an Automatic Recurring Execution of a

d

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 64/81

© 2008, Cognizant Technology Solutions Confidential

Command

You can use the cron facility to schedule regularly recurring commands.Users can submit a command to the cron facility by modifying their crontabfile.

All crontab files are maintained in the /var/spool/cron/crontabs directory

and are stored as the login name of the user that created the cron job.

The cron daemon is responsible for scheduling and running these jobs.

crontab File Format :

A crontab file consists of lines of six fields each. The fields are separated byspaces or tabs. The first five fields provide the date and time the commandis to be scheduled. The last field is the full path to the command.

64

Scheduling an Automatic Recurring Execution of a

d

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 65/81

© 2008, Cognizant Technology Solutions Confidential

Command

Ex :

10 3 * * 0 /usr/sbin/log/adm

10 - The minute field can hold values between 0 and 59.

3  - The hour field can hold values between 0 and 23.

*  - The day-of-month field can hold values between 1 and 31.

*  - The month field can hold values between 1 and 12, January toDecember.

0  - The day-of-week field can hold values between 0 and 6. Sunday is 0. /usr/sbin/log/adm - The command field contains the full path name to the

command to be run by the cron utility.

65

Crontab Command

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 66/81

© 2008, Cognizant Technology Solutions Confidential

Crontab Command

The crontab command enables the user to view, edit, or remove a crontabfile.

Viewing a crontab File

To view the contents of the root crontab file, run the crontab –l command as theroot user.

Editing a crontab File

To Edit the content of the crontab using crontab –e command. Before executingthis command you have to set the editor as vi.

Removing a crontab File The correct way to remove a crontab file is to invoke the command:

# crontab -r username

Typical users can remove only their own crontab file. The root user candeleteany user’s crontab file.

66

Controlling Access to the crontab Command

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 67/81

© 2008, Cognizant Technology Solutions Confidential

Controlling Access to the crontab Command

You can control access to the crontab command with two files in the/etc/cron.d directory—the cron.deny file and the cron.allow file.

These files permit only specified users to perform crontab tasks, such ascreating, editing, displaying, or removing their own crontab files.

/etc/cron.d/cron.deny - The Solaris OS provides a default cron.deny file.The file consists of a list of user names of the users who are not allowed touse cron.

/etc/cron.d/cron.allow - The /etc/cron.d/cron.allow file does not exist bydefault, so all users (except those listed in the cron.deny file) can accesstheir crontab file. By creating a cron.allow file, you can list only those userswho can access crontab commands. 

67

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 68/81

Basic Networking 

ftp Commands

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 69/81

© 2008, Cognizant Technology Solutions Confidential

 ftp Commands

The FTP (File Transfer Protocol) utility program is commonly used forcopying files to and from other computers. These computers may be at thesame site or at different sites thousands of miles apart. FTP is a generalprotocol that works on UNIX systems as well as a variety of other (non-UNIX) systems.

To connect your local machine to the remote machine, type

ftp machinename ( Ip address or machine name)

It will ask user name and password for login. Once you gave those details.,

It will allow to access the to the system, should have access on the requiredmachine for ftp access.

69

 ftp Commands

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 70/81

© 2008, Cognizant Technology Solutions Confidential

ftp Commands

? - to request help or information about the FTP commands 

ascii - to set the mode of file transfer to ASCII

binary - to set the mode of file transfer to binary

bye - to exit the FTP environment (same as quit) 

cd - to change directory on the remote machine 

delete - to delete (remove) a file in the current remote directory  

get - to copy one file from the remote machine to the local machine 

lcd - to change directory on your local machine (same as UNIX cd) 

mget - to copy multiple files from the remote machine to the local

machine; you are prompted for a y/n answer before transferring each file mput - to copy multiple files from the local machine to the remote

machine; you are prompted for a y/n answer before transferring each file.

put - to copy one file from the local machine to the remote machine

70

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 71/81

Other Useful Commands 

Other Commands

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 72/81

© 2008, Cognizant Technology Solutions Confidential

C

grep  - looks for the string in the files. Ex : grep ‘string’ filname 

diff   - Compare the files and shows where they differ. Ex : diff filename1

 filename2 

wc  - tells you how many lines, words, and characters there are in a file. Ex :wc filename

pwd  - tells you where you currently are.

w- tells you who's logged in, and what they're doing. Especially useful: the'idle' part. This allows you to see whether they're actually sitting theretyping away at their keyboards right at the moment.

72

Other Commands

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 73/81

© 2008, Cognizant Technology Solutions Confidential

C

who --- tells you who's logged on, and where they're coming from.

finger username - gives you lots of information about that user.

last -1 username - tells you when the user last logged on and off and from

where.

talk username - lets you have a (typed) conversation with another user.

write username - lets you exchange one-line messages with another user

passwd - lets you change your password

73

Other Commands

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 74/81

© 2008, Cognizant Technology Solutions Confidential

C

Date - shows the current date and time.

cal - shows a calendar of the current month.

man commandname - shows you the manual page for the command.

Hostname – shows server information.

sort – used to sort content the file. Ex: sort filename. It only display outputin the screen.

tail filename – display last part of the file.

head filename – display first part of the file. 74

Other Commands

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 75/81

© 2008, Cognizant Technology Solutions Confidential

history - list previously issued commands.

uptime - show system load, how long system has been up.

bg - put suspended process into background.

fg - bring process into foreground.

jobs - list processes.

^z - suspend current process

clear - clear terminal screen

75

Other Commands

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 76/81

© 2008, Cognizant Technology Solutions Confidential

exit  - terminate a shell

logout  - sign off; end session

man - find manual information about commands.

psrinfo - displays information about processors.

bc - a simple calculator

su - username – used to switch the user

format  – Display the hard disk available on the system.

76

Special commands and characters

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 77/81

© 2008, Cognizant Technology Solutions Confidential

Redirection

  <  Routes input to command from file

 >  Routes output from command to file

>>  Appends output to existing file

  |  Routes output between commands

Wildcards used in filenames

  *  Matches any number of characters

  ?  Matches one character

77

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 78/81

Important File system and Log

locations 

Important File Systems

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 79/81

© 2008, Cognizant Technology Solutions Confidential

p y

/ - Root file system contains the OS images

/var – File system contains variable data, like log etc

/usr/bin & /usr/sbin – contains the commands and executable

/export/home – Contains the user data

/opt – Contains the additional softwares

/swap – Virtual memory used for system process and programs

/usr/lib – Library files are stored

79

Important Log Locations

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 80/81

© 2008, Cognizant Technology Solutions Confidential

p g

/var/adm/messages – Contains all messages logged by OS.

/var/adm/lastlog - captures or record the last user and host info that login

to the server.

/var/adm/sulog - record of all attempts by users on the system to executethe su command.

/var/adm/loginlog - that logs unsuccessful attempts to access the system

80

8/13/2019 Unix Training COE Academy

http://slidepdf.com/reader/full/unix-training-coe-academy 81/81