• Aucun résultat trouvé

Default Local Login Scripts

When adding a new user, the system administrator should make sure that the new user has a local login script. HP- UX provides three default local login scripts:

• /etc/d.profile for Korn and Bourne shell users .

• / etc/ d .login and / etc/ d. cshrc for C shell users.

When adding a new user manually, the administrator copies the appropriate 4 file into the user's directory. For example, if the new user's shell is ksh and

home directory is /users/newuser, the administrator copies as follows:

$ cp /etc/d.profile /users/newuser/.profile

If the administrator uses the SAM program to add a new user, SAM

automatically copies the appropriate default local login script into the user's home directory.

/etc/d .profile

The default local login script resets the value of PATH, and sets terminal

characteristics, the shell environment, and shell variables. This section shows a sample d. profile and describes its contents.

# @(#) $Revision: 66.1 $

# Default user .profile file (/bin/sh initialization).

# Set up the terminal:

eval ' tset -s -Q -m ':?hp' , stty hupcl ixon ixoff

# Set up the search paths:

PATH=$PATH: .

# Set up the shell environment:

set -u

trap "echo 'logout'" 0

# Set up the shell variables:

EDITOR=vi export EDITOR

4-24 Login

Task Explanation

Set terminal The tset command generates the TERM

=

(hp) prompt during characteristics login. Based on the value you enter, the TERM environment

variable is set and the terminal's characteristics are defined. If you press (Return], TERM is set to hp. Refer to tset(l) for more

information.

Set PATH Set shell environment

Set shell variables

The stty command sets options for modem connections and scrolling text on your screen. Refer to stty(l) for more information.

Changes the value of PATH by adding the current directory to the end of PATH.

The set -u command prevents the shell from attempting to execute command lines with undefined shell variables. This command is a safety feature because, by default, the shell substitutes a null value for variables that aren't defined. For example, if a script uses a variable named WORK and you have not assigned a value to WORK, the script will not execute.

The trap command captures the exit signal (0) that is generated when you log out. When the shell receives this signal, the command

"eeho logout" is executed. (This trap command duplicates the one set in /ete/profile.)

Shell variables such as EDITOR are set and exported as global variables. EDITOR is a Korn shell variable that determines which in-line editor the shell uses.

Login 4-25

4

4

/etc/d.login

The default C shell local login script is similar to the Bourne shell/Korn shell script. The default local login script resets the value of PATH, sets terminal characteristics, and sets shell variables.

# @(#) $Revision: 64.2 $

# De£ault user .login rile ( /bin/csh initialization )

# Set up the de£ault search paths:

set path=(/bin /usr/bin /usr/contrib/bin /usr/local/bin .)

# Set up the terminal type:

eval 'tset -s -Q -m ':?hp' ,

stty erase "~H" kill "~U" intr "~C" eo£ "~D"

stty susp "~Z" hupcl ixon ixo££ tostop tabs

# Set up shell environment:

set noclobber set history=20

4-26 Login

Task Set path

Explanation

The value of path, if set here, explicitly changes the default search path. Note that for security purposes, the current directory should be placed at the end of the search path.

Set terminal Because of the question mark in the string ': ?hp', tset queries you characteristics for verification of TERM

=

(hp) during login. If you press (Return),

TERM is set to hp. If you enter a different value, the TERM

environment variable is set accordingly. See tset (1) for information on the tset command and terminfo( 4) on the terminal capabilities database.

Set shell variables

The stty command sets options for modem connections and scrolling text on your screen. Refer to stty(l) for more information.

The local shell variables noclobber and history are set.

The shell variable noclobber restricts output redirection, to prevent accidental destruction of file contents.

The shell variable history creates your command history buffer and sets its size. By default, history is set to record the last 20

commands executed. If this variable is not set, you have no command history and cannot edit and reuse previously executed commands.

The /etc/d.login (used by C shell) differs slightly in syntax and function from /etc/d.profile (used by Bourne and Korn shells). For information you can use to customize users' shells, consult csh(l), ksh(l), and sh(l) in the HP- UX Reference Manual

Login 4·27

4

4

jetcjd.cshrc

The / etc/ d. cshrc default script sets a restricted version of path for your subshells, sets local shell variables, and defines command aliases.

# Default user .cshrc file (/bin/csh initialization).

# Usage: Copy this file to a user's home directory and edit it to

# customize it to taste. It is run by csh each time it starts up.

# Set up default command search path:

#

# (For security, this default is a minimal set.) set path=( /bin /usr/bin

# Set up C shell environment:

if ( $?prompt ) then set history=20 set savehist=20 set system='hostname'

# shell is interactive.

# previous commands to remember.

# number to save across sessions.

# name of this system.

set prompt = U$system \1. " # command prompt.

# Sample alias:

alias endif

4-28 Login

h history

Task Set PATH

Set shell variables

Set command aliases

Explanation

A restricted path is defined that includes only /bin and /usr /bin.

Since . eshre executes before . login during the login process, this restricted value of path is overridden by the path defined in

$HOME/ . login. When subshells are spawned, the restricted value of path is used.

If the shell is interactive, various shell variables are set.

The shell variable history creates your command history buffer and sets its size. In this script, history is set to record the last 20 commands executed. If this variable is not set, your subshells have no command history and you cannot edit and reuse previously executed commands.

The shell variable savehist tells the shell to record the last 20 commands in the $HOME/ . history file. This file is used as the history from which the next session starts.

A shell variable system is set to the value output by the hostname command.

The shell variable prompt is set to the value in the system variable, followed by the command event number and a colon.

If the shell is interactive, command aliases are set. A command alias is an abbreviation for a long command line. This script sets an alias of h for the history command.

The jete/d. eshre script also contains sample aliases that are commented out by default. Because of space limitations, these commands are not shown in the example. To use these aliases, remove the pound sign (#) at the beginning of the line, thus changing the line from a comment to a command.

Login 4-29

4

4