WINDOWS 1002000 PROFESSIONAL RESOURCE KIT [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

WINDOWS 1002000 PROFESSIONAL RESOURCE KIT [Electronic resources] - نسخه متنی

Chris Aschauer

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید







Tools


Services for UNIX allows for central management of all included components. Services for UNIX also provides UNIX utilities and a Korn shell to automate common processes across Windows NT, Windows 2000, and UNIX platforms using scripts.

Network Management


Because all the Services for UNIX components are integrated into Microsoft Management Console (MMC) as snap-ins, you can centrally manage them from a computer running Windows 2000 Professional.

To access Services for UNIX Components


    Click the Start button, point to Programs, and then click Windows Services for UNIX.

    Click Services for UNIX Administration.

    You can configure all the Services for UNIX components from this window.


UNIX Shell


Services for UNIX 2.0 includes an implementation of the Korn shell. The shell is a command language interpreter that acts as the interface to the UNIX operating system. The shell interprets commands, calls the appropriate program, and returns standard output. Many shells also provide a high-level programming language that you can use to accomplish complex tasks by combining basic utilities and functions provided by the operating system.

The Korn shell, developed by David Korn at AT&T, combines many of the desirable features of the C and Bourne shells. The Bourne shell, developed at AT&T by Steven Bourne, was the first UNIX shell. The Bourne shell provides a powerful programming language. The C shell, another UNIX shell, provides a number of features not available with the Bourne shell, such as command aliases, a command history mechanism, and job control of command processing. Table 25.10 provides a feature summary of these three common shells.

Table 25.10 Shell Feature Summary






































FeaturesBourneCKorn
Command alias XX
Command history XX
Command-line editing X
Job control XX
Shell scriptingXXX

Other shells are available for the UNIX operating system. Bash (Bourne Again shell) is an extension of the Bourne shell that incorporates features of both the Korn and C shells and is common on Linux systems. Tcsh is an extended version of the C shell that includes command completion, a command-line editor, and enhanced history manipulation.

Using the Korn Shell


The implementation of the Korn shell included with Services for UNIX differs from the standard UNIX Korn shell in the following ways:


    Semicolons are used instead of colons to separate entries in the PATH variable.

    Current directory in PATH is referred to as ;; or ;.; instead of period (.).

    Startup file is called Profile.ksh instead of .profile.

    Startup file for systemwide environment variables is called /etc/profile.ksh instead of /etc/profile.

    History file, which stores the command history of a user, is called Sh_histo file instead of Sh_history.

    Partial job control enables running of jobs in the background by using the ampersand (&) on the command line.


If your system administrator sets up the Korn shell as your default shell in Telnet Server, it is the shell you log in to when accessing a Services for UNIX server by means of Telnet. If you want to use the Korn shell without logging on to it, you can access it by using the sh command (ksh in standard UNIX).

Environment Variables

A variable consists of a name and its assigned value. You can define variables and use them in shell scripts. Other variables, called shell variables, are set by the shell. A variable name can contain letters, numbers (but not as the first character), and the underscore. The equal sign with no spaces on either side is used to assign a value to the variable. Once a variable is defined, you must use the export command to make the value of the variable available to other processes running under the shell.

The Korn shell runs the Profile.ksh file when you log on. The Profile.ksh file is used to set user-specific environment variables and terminal modes. (The system administrator can also use /etc/profile.ksh to set variables systemwide for all user accounts on the system.) Some of the variables that you can use in Profile.ksh include PATH, HOME, VISUAL, EDITOR, SHELL, HISTSIZE, HISTFILE, PS1, PS2, CDPATH.

Table 25.11 lists many of the environment variables used by the Services for UNIX Korn shell. For a complete list of the shell variables supported by the Services for UNIX Korn shell, see Services for UNIX Help under the topic sh.

Table 25.11 Korn Shell Environment Variables






















































































































Variable NameDescription
_Expands to the argument of the previously executed command.
CDPATHDefines the search path used by the cd command.
COLUMNSDefines the width of the output display for programs that read the value; for example, the text editor vi.
EDITORSpecifies a default editor for the system to call when no editor is specified.
ENVPerforms parameter substitution on the value if ENV is set. When the shell is invoked, the named file runs first.
ERRNODisplays the value set by the most recently failed subroutine.
FIGNOREContains a pattern that defines which files are ignored during file expansion.
FCEDITDisplays the editor for the fc command.
HISTFILEDisplays the absolute path of the file (default.sh_histo) that contains the command history.
HISTSIZEDisplays the number of commands in the history file.
HOMEContains the absolute path of your home directory, which becomes your current directory when you log on.
IFSContains the characters used as internal field separators.
LINENODisplays the number of the line from standard input that the shell script is currently executing.
LINESDefines the number of output lines used by the select statement when printing its menu. Select writes specific words to standard error.
MAILContains the absolute path of the file where your mail is stored.
MAILCHECKDefines the number of seconds the shell waits before checking for new mail.
MAILPATHContains the mailbox files where new mail notification is sent.
OLDPWDDisplays the path of the previous working directory.
PATHDefines the absolute paths of the directories where the shell searches for executable files.
PPIDDisplays the process ID of the parent of the shell.
PS1Contains the prompt displayed by the shell. The default Korn shell prompt is $. Other options exist.
PS2Contains the secondary shell prompt.
PWDContains the path of the current working directory.
RANDOMGenerates a random number.
REPLYContains user input from the select statement.
SHELLDefines the absolute path of the current shell. Is used by commands to invoke the shell.
TMOUTDefines the number of seconds the shell remains inactive before it terminates.
VISUALSpecifies a default editor that overrides the EDITOR variable.

Metacharacters

The Korn shell recognizes a special meaning for certain characters. When a regular expression contains a metacharacter, the Korn shell interprets the character as shown in Table 25.12.

Table 25.12 Korn Shell Metacharacters






















































































CharacterMeaning
Escape character. When immediately preceding another character, it removes the special meaning from that character.
*Wildcard match for zero or more characters.
?Wildcard match for one character.
[ ]Wildcard match for the characters specified within the brackets.
<Redirects standard input so that it comes from a specified file instead of the terminal.
>Redirects standard output so that it goes to a specified file instead of the terminal.
>>Appends standard output to the end of a specified file.
|Connects the standard output of one command to the standard input of another command.(Called the Pipe.)
&Causes a process to run in the background when it is appended to a command line.
~Represents the path of a user's home directory.
.Current directory.
..Parent to the current directory.
$1 - $9Represents the first nine arguments in a command.
/Root directory.
´Takes a string literally. Variable substitution allowed.
´´Takes a string literally. Variable substitution allowed.
`When back quotes precede and follow a command string, tells the shell to run the command and use the output in place of the string.
( )Groups commands together for execution.
;Separates commands on a command line.
newline

(ENTER)

Starts command execution.

Shell Commands

When you enter a command at the shell prompt, the shell evaluates the command, makes substitutions for variables and aliases, and then runs the command.

The basic structure of a command is as follows:

command-name argument1 argument2 >file-name

Commands can take options, which modify the action of a command. For example, ls lists the contents of a directory but does not include the hidden (.) files. Use ls -a to also see the hidden files.

The shell processes the command after you press ENTER. Commands can also be separated by semicolons and entered on a single line; the commands on the line are not processed, however, until after you press ENTER.

When the shell runs a command, it starts a process. Each process has a process ID (PID), which is used to access the process. Processes can be run in the foreground or the background and can also be suspended or cancelled. Parent processes fork child processes, which are assigned their own PIDs.

A command receives standard input from the terminal and sends standard output and standard error to the terminal.

You can redirect the standard input from the terminal to a file as follows:

command-name < file-name

You can also redirect the standard output from the terminal to a file as follows:

command-name > file-name

You can append it to an existing file as follows:

command-name >> file-name

In addition, you can redirect the standard error to a file as follows:

command-name 1>file-name1 2>file-name2

The standard output is sent to file-name1 and the standard error is sent to file-name2.

You can use pipes to connect the standard output of one command to the standard input of another command as follows:

command-name | command-name >file-name

The Services for UNIX Korn shell is a programmable shell that supports the following structured commands, as shown in Table 25.13. For a complete list of supported shell commands, see Services for UNIX Help under the topic sh.

Table 25.13 Shell Programming Services for UNIX Korn Shell






























CommandUse
caseRuns commands based on a particular setting of another variable.
forRuns a specific list of commands.
ifSpecifies conditions in a script.
selectWrites specified words to standard error.
untilRuns a list of commands until a zero value is returned.
whileRuns a list of commands while a certain condition is true.

The Services for UNIX Korn shell has built-in commands. Built-in commands are run by the shell's own process. Table 25.14 lists the built-in commands that are available with the Services for UNIX Korn shell. For details about each command, see Services for UNIX Help.

Table 25.14 Services for UNIX Korn Shell Built-in Commands


































































































































































CommandDescription
.Runs a shell file in the current environment.
:Expands arguments. Returns an exit status of 0 (success).
aliasAssigns a new name to a command.
breakExits from a for, while, or until loop.
cdChanges the current working directory.
continueResumes with the next iteration of a for, while, or until loop.
echoDisplays its arguments to standard output.
environStandard environmental variables.
evalScans and runs the specified command.
execRuns the specified command without creating a new process.
exitExits the shell.
exportMakes the value of the variable available to child processes.
falseReturns an exit status of 1 (failure).
fcSelects specified commands from command history.
getoptsParses command line options.
jobsDisplays current jobs.
killEnds the specified job.
letEvaluates the expression.
printDisplays arguments from the shell.
pwdDisplays the current working directory.
readReads one line from standard output.
readonlyMakes the value of the variable read-only so it cannot be changed.
returnExits a function.
setSets shell flags or command line argument variables.
sheditInteractive command and history editing in the shell.
shiftPromotes each command line argument (for example, $3 to $2).
shpcFeatures of Korn shell specific to Windows NT.
testChecks for the properties of files, strings, and integers, and returns the results of the test as an exit value.
timeDisplays run time and CPU time.
timesDisplays the user program and system times accumulated by the shell.
trapSpecifies commands to run at a signal.
trueReturns exit status of 0 (success).
typeIdentifies a name as interpreted by the shell.
typesetSets attributes and values for shell parameters.
umaskChanges access permissions.
unaliasRemoves an alias.
unsetRemoves a variable definition from the environment.
waitWaits for a child process to terminate.
whenceDescribes how the shell interprets a command name (as a function, shell keyword, command, alias, or executable file).

Command Aliases

For commands and command-line options, you can assign an alias or name that the shell translates to another name or string. (Be sure to choose an alias that is easy to remember.) The shell substitutes the command and options for the alias you enter. Creating an alias at the command line makes the alias available in the current shell environment. To make the alias a part of the work environment, add the following line to the shell start-up file (.kshrc) that defines the alias and exports it:

alias newname=´command -option´; export newname

The command alias -x exports the alias to the child process only.

To remove an alias, use unalias followed by the alias name:

unalias newname

The Services for UNIX Korn shell provides a set of predefined aliases. For more information about the alias command, see Services for UNIX Help.

Command History

The Services for UNIX Korn shell features a history file, which contains a list of a defined number of executed commands. These commands can be accessed for editing and persist in the file between logon sessions.

You can set the maximum number of commands to be saved in the history file by using the HISTSIZE variable:

HISTSIZE=number; export HISTSIZE

If you do not define this variable, UNIX saves a system-defined number of commands.

You can define the name and location of the history file by using the HISTFILE variable:

HISTFILE=file-name; export HISTFILE

If you do not define this variable, your history file is named .sh_histo and stored in your home directory.

Command Line Editing

You can edit the commands in the history file by using built-in Korn shell editors, such as vi, or the built-in fc command. You can use this feature to correct mistakes or to reuse work you have completed.

To define vi as your default editor:

set -o vi

- Or -

VISUAL=/sfu/shell/vi; export VISUAL

The built-in editor that is provided with the Korn shell offers a subset of the full functionality available with vi. You can access vi to edit a command by entering the command, pressing ENTER, and then typing vi. This allows you to edit a multiline command.

Arithmetic Evaluation

The Services for UNIX Korn shell has a built-in arithmetic expression feature. It supports logical and arithmetic operators. The syntax for arithmetic operators is $((<arithmetic expression>)) or $(<arithmetic expression>). The Korn shell replaces the arithmetic expression with its value, beginning with the innermost nested expression. Table 25.15 lists the operators.

Table 25.15 Arithmetic and Logical Operators






















































































OperatorDescription
+Plus
-Minus
*Multiply
/Divide (with truncation)
%Remainder
<<Bit-shift left
>>Bit-shift right
&Bitwise and
&&Logical and
|Bitwise or
||Logical or
^Bitwise exclusive or
!Logical not
~Bitwise not
<Less than
>Greater than
<=Less than or equal to
>=Greater than or equal to
!=Not equal to
=Equal to

Shell Scripts

A shell script is a file containing a series of commands that together perform a function. You can access a Korn shell script from the command prompt if you are running the Korn shell and have permission to execute the script by typing the file name. You can also run the shell script if the Korn shell is not running by entering the following command:

sh file-name

NOTE


Windows NT does not execute a script when you invoke it from the command prompt with only a file name; UNIX, however, does execute scripts if you specify the path and file name of the shell on the first line of the script, such as in the following:

#!/bin/sh

You must link each file or file name extension to a program. In particular, .sh or .ksh can be associated with the Korn shell.

Job Control

You can use job control to run a command in the foreground or the background, or to temporarily suspend it. In addition, you can see a list of the commands currently running.

When you enter a command, if it is not a built-in command, the shell forks a new process in which to run the command. The kernel schedules the process and gives it a process ID (PID). The shell keeps track of the process and gives it a job number.

Some processes are run in the foreground: they might be interactive or take only a short time to run. Other processes are better run in the background, especially commands that take a long time to run, such as a large sort. You can move a process to the foreground or the background and get a list of the current jobs. You can also temporarily suspend a process or terminate it.

Table 25.16 lists the job control commands that Services for UNIX supports.

Table 25.16 Job Control Commands


















CommandDescription
jobs -lLists the current jobs. Each job is numbered. The -l option displays the PID.
Command & Runs the command in the background. For example, sort file-name newfile &
kill job-numberTerminates the job specified by job-number. The job number is displayed when a job is started by using & or the jobs command.

UNIX Utilities


The following UNIX utilities are available in Services for UNIX 2.0.


    Table 25.17 lists the new utilities that are available in Services for UNIX 2.0.

    Table 25.18 lists the utilities that were previously available in Services for UNIX 1.0 and that are included in Services for UNIX 2.0.


For more information about these commands, see Services for UNIX Help.

Table 25.17 New Utilities in Services for UNIX 2.0





























































































































UNIX CommandDescription
cronSchedules tasks.
crontabLists scheduled tasks and edits them.
cutCuts out bytes, character, or character-delimited fields from each line in one or more files, concatenates them and writes them to standard output.
dateWrites the date and time.
diffCompares two files and displays line-by-line differences.
duPrints the disk usage of a file or directory.
killTerminates or signals processes.
niceInvokes a command with a specified scheduling priority.
odDisplays files in specified formats.
pasteMerges corresponding or subsequent lines of files.
perlRuns Perl programs.
printenvPrints environment variables that are set.
printfWrites formatted output.
psLists processes and their status.
pwdPrints the current working directory.
reniceReprioritizes a running process.
sdiffPrints differences side-by-side.
sleepSuspends execution for a specified interval.
splitSplits a file into pieces.
stringsFinds printable strings in an object or binary file.
suBecomes another user (or administrator).
tarCreates tape archives, and adds or extracts files from an archive.
topShows top processes sorted by CPU usage.
trTranslates characters in input stream.
unamePrints names of the current system.
uudecodeDecodes a text file into a binary file.
uuencodeEncodes a binary file.
waitWaits for process completion.
whichLocates command and print pathname/alias.
xargsConstructs argument lists and invoke a utility.

Table 25.18 Utilities in Services for UNIX 1.0














































































































UNIX CommandDescription
shInvokes the Korn shell.
basenameRemoves the path, leaving only the file name. Deletes any prefix ending in / and any suffix from string and prints the result to standard output.
catConcatenates and displays a file.
chmodChanges or assigns the permissions mode of a file.
chownChanges the owner of a file.
cpCopies files.
dirnameDelivers all but the last level of the path in a string. See basename.
findRecursively searches a directory hierarchy, looking for files that match a specified Boolean expression.
grepSearches files for a pattern and prints all lines containing that pattern.
headCopies first n lines of specified file names to standard output.
lnCreates a hard link to a file. Links a file name to a target by creating a directory entry that refers to the target.
lsLists the contents of a directory.
mkdirCreates a named directory with read, write, and execute permission for every type of user.
moreFilters and displays the contents of a text file on the terminal, one screen at a time.
mvMoves a file name to a target.
rmRemoves an entry for a file from a directory.
rmdirRemoves a directory.
sedCopies named file names to a standard output; edits according to a script of commands (a stream editor).
sortSorts the lines of all named files, groups them, and writes the result to standard output.
tailCopies a named file to standard output, beginning at a designated place.
teeTranscribes standard input to standard output and makes copies in a file name.
touchUpdates the access time or the modification time of a file.
uniqReports on repeated lines in a file.
wcDisplays a count of lines, words, or characters in a file.
viEdits text in a screen-based environment.
perlAn interpreted language that scans text files, extracts information from those files, and prints reports based on that information.

Using vi


The vi editor is an interactive text editor for creating and editing ASCII files. The vi editor requires you to enter a command to perform an action, such as entering text, deleting text, or moving the cursor. You can be in one of two modes when using vi: command mode or input mode. In command mode, you can enter commands to perform such actions as deleting text or moving the cursor in the file. In input mode, you can enter and change text. You enter input mode by entering a specific vi command. You leave input mode by pressing ESC.

This section provides basic information to get you started using vi. After you understand the mechanics of using vi, you can explore its functionality. (The mechanics are simple; the details can seem obscure at first.) For more information about the complete functionality of vi, see any of the available print or online sources, including Services for UNIX Help.

To edit a file by using vi, at the command prompt type:

vi file-name

and press ENTER.

If the file already exists, it appears on the screen. If the file does not exist, vi creates it.

NOTE


You can take advantage of a file recovery feature that is provided with vi. If the system saves a copy of the last saved version of your file in a buffer, you can access that copy of the file by typing vi -r file-name and pressing ENTER.

What you see on the screen is the text of the file (if it exists), a blinking cursor in the left corner of the screen, a column of tildes along the left margin of the file that represent blank lines (if any are in view), and the name of the file in the last line of the screen. (The bottom of the screen is also used to display messages, to show commands you enter that begin with /, ?, !, and :, and to indicate input mode if the showmode option is set.)

To begin entering text, press i (to insert text). You can then begin typing. The text you enter appears, beginning at the position of the cursor. When you are done entering text, press ESC.

To save the file and exit vi, type

:wq

and press ENTER.

Use the colon to escape to the shell so that you can enter a command at the bottom of the screen. Press w to write the file to disk. Press q to quit the vi editor. Table 25.19 provides a summary of the of the commands used for starting and quitting vi.

Table 25.19 Starting and Quitting vi


























CommandDescription
vi file-nameEdits file-name (this creates a new file or edits an existing one).
vi -r file-nameRecovers a file after a system failure and edits it.
:qQuits vi if no changes have been made.
:q!Quits vi without saving changes.
:wqWrites (saves changes) and quits vi.

As the size of the file increases, you can more easily move throughout the file by using the following commands in command mode, as shown in Table 25.20.

Table 25.20 Moving the Cursor in Command Mode






















































CommandDescription
SpacebarMoves the cursor forward one character.
BackspaceMoves the cursor back one character.
lMoves the cursor one character to the right.
hMoves the cursor one character to the left.
jMoves the cursor down one line.
kMoves the cursor up one line.
Ctrl-dScrolls down half a screen.
Ctrl-uScrolls up half a screen.
Ctrl-fScrolls down one screen.
Ctrl-bScrolls up one screen.
nGMoves the cursor to line n.
GMoves the cursor to the end of the file.

Tables 25.21 and 25.22 list many ways for inserting and changing text that allow for detailed control.

Table 25.21 Input Mode






























Command Description
aInserts text after the cursor.
AInserts text at the end of the current line.
IInserts text before the cursor.
IInserts text before the current line.
oOpens a line in the text below the cursor.
OOpens a line in the text above the cursor.

Table 25.22 Changing Text






























CommandDescription
rReplaces the current character with the next character typed; returns to Command mode.
RReplaces text beginning with the current character until you pressESC.
CcChanges the entire current line to the new text entered.
CwChanges the current word, beginning at the cursor position, to the new text entered.
SSubstitutes the character at the cursor position with the new text entered.
SSubstitutes the entire current line with the new text entered.

Table 25.23 lists ways to delete text in vi.

Table 25.23 Deleting Text in vi


















CommandDescription
DDeletes from the cursor to the end of the line.
xDeletes the current character.
ddDeletes the current line.

You can yank and put—that is, copy and paste—text within a file and between files. The yank command, as shown in Table 25.24, copies selected text and places it in a buffer. The put commands copy the text from the buffer to a specified place in the file. Named buffers and numbered buffers are available but are beyond the scope of this discussion.

Table 25.24 Yank and Put Commands






















CommandDescription
yy or YYanks (copies) the current line and places it in a buffer.
5yyYanks (copies) five lines and places them in a buffer.
PPuts (pastes) the text that is in the buffer into the line after the current one.
PPuts (pastes) the text that is in the buffer into the line before the current one.

You can search for a character string within the file. The search tools are case-sensitive. If the pattern is not found, vi displays a message at the bottom of the screen telling you that it is unable to find the pattern. Table 25.25 lists the available search commands and their descriptions.

Table 25.25 Search Commands






















CommandDescription
/patternMoves forward to the first character in the next occurrence of the character string pattern.
/Repeats the previous forward search.
?patternMoves backward to the first character in the next occurrence of the character string pattern.
?Repeats the previous backward search.

You can access global pattern substitution from the command prompt.

The command takes the following form:

:s/string/replacement/g

In this command, string represents any regular expression that you want to search for, replacement represents the text that replaces string, and g specifies global replacement of all occurrences of string. If the trailing g is omitted, only the first occurrence of the string in each line is replaced. If you want to be prompted to confirm each substitution, type a c after the g in the command, as follows:

:s/string/replacement/gc

Table 25.26 lists a few of the many other commands available in vi.

Table 25.26 Other Useful Commands


































CommandDescription
:shEscapes to the shell to run a command.
:!commandRuns one command.
uUndoes the last change.
URestores the last deleted line.
~Toggles the case of the current character.
xpTransposes the character in the current cursor position with the next character.
.Repeats the last change.

Scripting


Services for UNIX includes two tools that you can use for scripting: Perl and sh.

Perl is a scripting language that is useful for automated tasks, such as processing text files by using pattern matching techniques. Perl is "open source" software. Not all Perl functions are implemented in Services for UNIX. For more information about Perl, see Services for UNIX Help.

The Korn shell provided with Services for UNIX can be used as a shell script processor. For more information about using the Korn shell for scripting, see Services for UNIX Help under the topic sh.

/ 335