《Linux命令、编辑器与Shell编程》读书笔记13-系统脚本和登录环境

Linux系统启动过程

主机加电自检

按下电源键后,系统加载BIOS,检查连接到系统的外接设备、并枚举和初始化设备(比如让光驱激光头复位、测试风扇状态等),如果没有出错,则根据BIOS中的设置查找处于活动状态并能引导系统的硬盘分区、光盘或者U盘,从而从中读取引导装载程序。

引导装载程序加载内核

不同的操作系统,引导装载程序也有所不同;linux中广泛使用的是GRUB,该程序被读取后,会从/boot/grub/menu.lst(或者/boot/grub/grub.conf)文件中读取相应的配置;menu.lst文件的内容大致如下:

#这两个值表示启动后光标所在的默认菜单编号,菜单项就是下面title列出来的项
#0表示默认在第一项,8表示8秒内无动作、则默认启动第一项
default 0
timeout 8
##YaST - generic_mbr-这里设置了mbr引导分区文件的位置、启动背景图案等参数,都在下面这个message文件里写着
#启动背景存放在/etc/bootsplash/themes/SLES/cdrom下面
gfxmenu (hd0,1)/boot/message
##YaST - activate-这里表示GRUB引导选择界面隐藏用户选择菜单,为空则显示选择菜单
hiddenmenu
###Don't change this comment - YaST2 identifier: Originalname: linux###
#下面三段分别表示选择界面的三个选择项
         #名称
title SUSE Linux Enterprise Server 11 SP3 - 3.0.76-0.11
         #根目录
root (hd0,1)
#要加载的内核文件和内核参数
kernel/boot/vmlinuz-3.0.76-0.11-default root=/dev/sda2 resume=/dev/sda1 splash=silentcrashkernel= showopts
#挂在内存映像文件
    initrd/boot/initrd-3.0.76-0.11-default
###Don't change this comment - YaST2 identifier: Originalname: failsafe###
title Failsafe -- SUSE Linux Enterprise Server 11 SP3 -3.0.76-0.11
    root (hd0,1)
    kernel/boot/vmlinuz-3.0.76-0.11-default root=/dev/sda2 showopts ide=nodma apm=offnoresume edd=off powersaved=off nohz=off highres=off processor.max_cstate=1nomodeset x11failsafe
    initrd/boot/initrd-3.0.76-0.11-default
 
###Don't change this comment - YaST2 identifier: Originalname: floppy###
title Floppy
    rootnoverify(fd0)
    chainloader +1


*关于内存映像文件

可以把上面的initrd-3.0.76-0.11-default文件单独拷到一个文件夹中、解压:

zcat  initrd-3.0.76-0.11-default  |  cpio  -imd

解压出的文件中有一个名为init的shell可执行脚本,其功能主要是挂在文件系统、加载相应内核模块等。

此时如果使用root用户执行这个脚本,会进入fast boot模式,这有可能临时修复损坏的系统,但有可能损坏硬盘分区上的业务数据,因此、运营中服务器千万不要这么做,危险!

*定制内存映像文件

后面会详细学习这部分内容,这里先不深究每一个命令参数的使用是否正确。

这样做的目的主要是为了能在系统启动时加载一些特殊设备(如SCSI设备、Raid卡等)的驱动。

首先要明确被装载驱动文件的位置。比如我们队防火墙的内核驱动文件进行了修改/升级:

/lib/modules/3.0.76-0.11-default/kernel/drivers/firewire/firewire-core.ko

*注:.ko是内核模块文件,是内核加载的某个模块,一般是驱动程序。

之后就可以在内存映像文件目录(也就是上面initrd-3.0.76-0.11-default文件所在的目录)中使用mkinitrd命令制作(我觉得叫升级更合适)内存映像,该命令的基本格式如下:

mkinitrd  [选择性参数]  <必要参数>

必要参数包括:

<映像文件>:/boot/grub/menu.lst中指定要加载的内核文件

<内核版本>:所依据的内核版本,使用uname  -r查看。

 

[可选参数]包括

--builtin=<模块>

认为指定模块已经装入内核,忽略错误

-f

允许覆盖已存在的映像文件

--image-version

内核版本号将附加到建立的映像文件的目录前

--fstable=<文件系统列表>

使用列表自动探测根设备所建立的文件系统类型

--nocompress

不压缩生成的映像文件

--nopivot

不使用pivot_root系统调用作为映像的一部分

--omit-lvm-modules

不载入任何lvm模块

--omit-scsi-modules

不载入任何scsi模块

--preload=<模块>

将指定的模块载入映像中

-v

在创建映像过程中打印信息

-version

打印程序版本信息

初始化系统环境

Linux加载内核后、会将控制权移交给内核,内核根据读取到得配置项等信息构造最基本的内核环境,执行的动作有:调用初始化函数初始化各种设备、加载驱动、加载内核等。内核环境构造完成后,启动系统的第一个进程-INIT进程。

要初始化的系统脚本有很多,这里着重介绍几个常用的:

启动服务/etc/init.d/rc

当系统读取了当前要启动的runlevel后、会执行/etc/init.d/rc脚本:

l0:0:wait:/etc/init.d/rc 0

l1:1:wait:/etc/init.d/rc 1

l2:2:wait:/etc/init.d/rc 2

l3:3:wait:/etc/init.d/rc 3

#l4:4:wait:/etc/init.d/rc 4

l5:5:wait:/etc/init.d/rc 5

l6:6:wait:/etc/init.d/rc 6

去执行对应文件夹的系统脚本来实现这一过程。

以runlevel=3为例,Linux会去执行/etc/init.d/rc3.d目录下的文件,该目录下的文件命名规律:

S和K开头的文件分别代表start和kill,表示需要运行/关闭的服务;S和K后面的数字表示优先级;最后是服务名。

(SUSE下待确认)/etc/rc.d/rc.sysinit

该脚本是在INIT进程被载入后开始运行。作用:

1. 取得网路环境与主机类型:

首先读取网路设定档 /etc/sysconfig/network ,取得主机名称与预设通讯闸(gateway) 等网路环境。

2. 测试与挂载记忆体装置 /proc 及 USB 装置 /sys:

除挂载记忆体装置 /proc 之外,还会主动侦测系统上是否具有 usb 的装置,若有则会主动载入 usb 的驱动程式,并且尝试挂载 usb 的档案系统。

3. 决定是否启动 SELinux :

近期以来,很多 distributions 都加入了美国国家安全局发展的 Security Enhance Linux 套件, 这个 SELinux 可以更加强化 Linux 操作环境的安全性,不过,由于安全挂帅, 对于新手来说,不是很容易上手。因此,我们才会建议大家先不要启动啊。无论如何,在这个阶段我们可以分析 SELinux 是否要启动。

4. 周边设备的侦测与 Plug andPlay (PnP) 参数的测试:

根据核心在开机时侦测的结果 (/proc/sys/kernel/modprobe ) 开始进行 ide / scsi / 网路 / 音效 等周边设备的侦测,以及利用以载入的核心模组进行 PnP 装置的参数测试。

5. 使用者自订模组的载入

使用者可以在 /etc/sysconfig/modules/*.modules 加入自订的模组, 则此时会被载入到系统当中喔!

6. 载入核心的相关设定:

系统会主动去读取 /etc/sysctl.conf 这个档案的设定值,使核心功能成为我们想要的样子。

7. 设定系统时间 (clock):

8. 设定终端机 (console) 字形:

9. 设定 RAID 与 LVM 等硬碟功能:

10. 以 fsck 检验磁碟档案系统:

11. 进行磁碟配额 quota 的转换 (非必要):

12. 重新以可读取模式挂载系统磁碟:

13. 启动 quota 功能:

14. 启动系统乱数装置 (产生乱数功能):

15. 清除开机过程当中的暂存档案:

16. 此外还设置了鼠标键盘及产生随机数设备等,很多底层功能都能在该脚本中得到定义。

/etc/init.d/rc.local

该文件在SUSE下的名字是/etc/init.d/boot.local

该脚本会在INIT进程启动完毕后开始自动执行,如果你有需要开启自动执行/启动的脚本/应用,可以将命令加进来。关于该文件的官方解释:

# Here you should add things, that shouldhappen directly after booting

# before we're going to the first runlevel.

加入命令时要注意:

使用&将要执行的命令放到后台,避免命令执行后一直占用终端。

脚本的位置要用决定路径,否则在开机启动时报错,很难定位原因(因为输出信息不便于被查看)。

注:如果系统启动后发现有问题,可以通过/var/log/boot.msg和/var/log/boot.omsg查看系统启动过程中的错误信息。

启动INIT进程

此时基本的内核环境已经准备好了,Linux开始加载系统的第一个进程-INIT进程,这也是所有进程的父进程,启动该进程时,会读取/etc/inittab中的配置信息。

*INIT进程的配置文件

/etc/inittab文件内容如下:

# /etc/inittab
#
# Copyright (c) 1996-2002 SuSE Linux AG,Nuernberg, Germany.  All rights reserved.
#
# Author: Florian La Roche, 1996
# Please send feedback tohttp://www.suse.de/feedback
#
# This is the main configuration file of/sbin/init, which
# is executed by the kernel on startup. Itdescribes what
# scripts are used for the differentrun-levels.
#
# All scripts for runlevel changes are in/etc/init.d/.
#
# This file may be modified by SuSEconfigunless CHECK_INITTAB
# in /etc/sysconfig/suseconfig is set to"no"
#
 
#这里定义系统的默认运行级别
#格式为id:runlevels:action:process,可以通过“maninittab”查看相关的信息
id:3:initdefault:
 
# First script to be executed, if notbooting in emergency (-b) mode
si::bootwait:/etc/init.d/boot
 
# /etc/init.d/rc takes care of runlevelhandling
#
# runlevel 0  is System halt   (Do not use this forinitdefault!)
# runlevel 1  is Single user mode
# runlevel 2  is Local multiuser without remote network (e.g. NFS)
# runlevel 3  is Full multiuser with network
# runlevel 4  is  Notused
# runlevel 5  is Full multiuser with network and xdm
# runlevel 6  is System reboot (Do not use this for initdefault!)
#下面定义了不同runlevel下要初始化的系统脚本
l0:0:wait:/etc/init.d/rc 0
l1:1:wait:/etc/init.d/rc 1
l2:2:wait:/etc/init.d/rc 2
l3:3:wait:/etc/init.d/rc 3
#l4:4:wait:/etc/init.d/rc 4
l5:5:wait:/etc/init.d/rc 5
l6:6:wait:/etc/init.d/rc 6
 
# what to do in single-user mode
ls:S:wait:/etc/init.d/rc S
~~:S:respawn:/sbin/sulogin
 
# what to do when CTRL-ALT-DEL is pressed
#定义组合键CTRL-ALT-DEL的意义
ca::ctrlaltdel:/sbin/shutdown -r -t 4 now
 
# special keyboard request (Alt-UpArrow)
# look into the kbd-0.90 docs for this
kb::kbrequest:/bin/echo "KeyboardRequest -- edit /etc/inittab to let this work."
 
# what to do when power fails/returns
pf::powerwait:/etc/init.d/powerfail start
pn::powerfailnow:/etc/init.d/powerfail now
#pn::powerfail:/etc/init.d/powerfail now
po::powerokwait:/etc/init.d/powerfail stop
 
# for ARGO UPS
#定义了市电中断、UPS电源启动后要做的动作
sh:12345:powerfail:/sbin/shutdown -h nowTHE POWER IS FAILING
 
# getty-programs for the normal runlevels
#<id>:<runlevels>:<action>:<process>
# The "id" field  MUST be the same as the last
# characters of the device (after"tty").
1:2345:respawn:/sbin/mingetty --nocleartty1
2:2345:respawn:/sbin/mingetty tty2
3:2345:respawn:/sbin/mingetty tty3
4:2345:respawn:/sbin/mingetty tty4
5:2345:respawn:/sbin/mingetty tty5
6:2345:respawn:/sbin/mingetty tty6
#
#S0:12345:respawn:/sbin/agetty -L 9600ttyS0 vt102
#cons:12345:respawn:/sbin/smart_agetty -L38400 console
 
#
# Note: Do not use tty7 in runlevel 3, this virtual line
#  isoccupied by the programm xdm.
#
 
# This is for the package xdmsc, after installing and
# and configuration you should remove the comment character
# from the following line:
#7:3:respawn:+/etc/init.d/rx tty7
 
 
# modem getty.
# mo:235:respawn:/usr/sbin/mgetty -s 38400modem
 
# fax getty (hylafax)
# mo:35:respawn:/usr/lib/fax/faxgetty/dev/modem
 
# vbox (voice box) getty
# I6:35:respawn:/usr/sbin/vboxgetty -d/dev/ttyI6
# I7:35:respawn:/usr/sbin/vboxgetty -d /dev/ttyI7
 
# end of /etc/inittab


加载Login

INIT进程最后加载的是/bin/login,也就是登录界面。

用户环境

全局用户配置文件/etc/profile

所有新建的用户都会使用该文件构建用户环境。这里保存了用户使用的SHELL类型、UID/EUID值、环境变量、快捷键设置及命令别名等。

其具体内容如下:

# /etc/profile for SuSE Linux

#这里是一些简单的说明
# PLEASE DO NOT CHANGE /etc/profile. Thereare chances that your changes
# will be lost during system upgrades.Instead use /etc/profile.local for
# your local settings, favourite globalaliases, VISUAL and EDITOR
# variables, etc ...
#检查用户使用SHELL类型并为用户调用对应的Shell
# Check which shell is reading this file
if test -f /proc/mounts ; then
  if! is=$(readlink /proc/$$/exe 2>/dev/null) ; then
   case "$0" in
   *pcksh)    is=ksh       ;;
   *)               is=sh         ;;
   esac
  fi
 case "$is" in
   */bash)    is=bash
         case"$0" in
         sh|-sh|*/sh)
                   is=sh         ;;
         esac          ;;
   */ash)       is=ash  ;;
   */dash)    is=ash  ;;
   */ksh)       is=ksh  ;;
   */ksh93)  is=ksh  ;;
   */pdksh)  is=ksh  ;;
   */*pcksh)          is=ksh  ;;
   */zsh)       is=zsh  ;;
   */*)  is=sh   ;;
 esac
  #
  #`r' in $- occurs *after* system files are parsed
  #
  fora in $SHELL ; do
   case "$a" in
     */r*sh)
       readonly restricted=true ;;
     -r*|-[!-]r*|-[!-][!-]r*)
       readonly restricted=true ;;
     --restricted)
       readonly restricted=true ;;
   esac
 done
 unset a
else
 is=sh
fi
 
#
# Call common progams from /bin or /usr/binonly
#
path ()
{
   if test -x /usr/bin/$1 ; then
         ${1+"/usr/bin/$@"}
   elif test -x   /bin/$1 ; then
         ${1+"/bin/$@"}
   fi
}
 
#初始化登录终端
# Initialize terminal
#
tty=`path tty 2> /dev/null`
test $? -ne 0 && tty=""
if test -O "$tty" -a -n"$PS1"; then
   test -z "${TERM}"             &&{ TERM=linux; export TERM; }
   test "${TERM}" = "unknown"  && { TERM=linux; export TERM; }
    #Do not change settings on local line if connected to remote
   if test -z "$SSH_TTY" -a "${TERM}" !="dumb" ; then
         pathstty sane cr0 pass8 dec
         pathtset -I -Q
   fi
    #on iSeries virtual console, detect screen size and terminal
   if test -d /proc/iSeries -a \( "$tty" = "/dev/tty1"-o "$tty" = "/dev/console" \) ; then
       LINES=24
         COLUMNS=80
         exportLINES COLUMNS TERM
       if test -x /bin/initviocons ; then
              eval `/bin/initviocons -q -e`
         fi
   fi
fi
unset TERMCAP
 
#不明
# Time until a complete key sequence musthave arrived
#ESCDELAY=2000
#export ESCDELAY
 
#
# The user file-creation mask
# The global umask value is stored in/etc/login.defs and
# will be set by pam_umask.so (see"man pam_umask").
#umask 022
 
#
# Setup for gzip and (t)csh users
#
if test -z "$PROFILEREAD" ; then
    #GZIP=-9
    #export GZIP
   CSHEDIT=emacs
   export CSHEDIT
fi
 
#
# ksh/ash sometimes do not know
#
test -z "$UID"  && readonly  UID=`path id -ur 2> /dev/null`
test -z "$EUID" && readonlyEUID=`path id -u  2> /dev/null`
test -z "$USER" &&USER=`path id -un 2> /dev/null`
test -z "$MAIL" &&MAIL=/var/spool/mail/$USER
test -z "$HOST" &&HOST=`/bin/uname -n 2> /dev/null`
test -z "$CPU"  && CPU=`/bin/uname -m 2> /dev/null`
 
# Remark: /proc/sys/kernel/domainname andthe program domainname
# its self will provide the NIS/YPdomainname, see domainname(8).
if test -s /etc/HOSTNAME ; then
   test -z "$HOSTNAME" && HOSTNAME=`cat /etc/HOSTNAME`
else
   test -z "$HOSTNAME" && HOSTNAME=$HOST
fi
 
test -z "$LOGNAME"  && LOGNAME=$USER
case "$CPU" in
   i?86) HOSTTYPE=i386   ;;
   *)    HOSTTYPE=${CPU} ;;
esac
 OSTYPE=linux
MACHTYPE=${CPU}-suse-${OSTYPE}
# Do NOT export UID, EUID, USER, andLOGNAME
export MAIL HOST CPU HOSTNAME HOSTTYPEOSTYPE MACHTYPE
 
#
# You may use /etc/initscript,/etc/profile.local or the
# ulimit package instead to set up ulimitsand your PATH.
#
# if test "$is" !="ash" -a ! -r /etc/initscript; then
#    ulimit -Sc 0            # don'tcreate core files
#    ulimit -Sd $(ulimit -Hd)
#    ulimit -Ss $(ulimit -Hs)
#    ulimit -Sm $(ulimit -Hm)
# fi
 
#
# Make path more comfortable
#
if test -z "$PROFILEREAD" ; then
   PATH=/usr/local/bin:/usr/bin:/bin
   if test "$HOME" != "/" ; then
         fordir in $HOME/bin/$CPU $HOME/bin ; do
             test -d $dir && PATH=$dir:$PATH
         done
   fi
   if test "$UID" = 0 ; then
         test-d /opt/kde3/sbin  &&PATH=/opt/kde3/sbin:$PATH
         PATH=/sbin:/usr/sbin:/usr/local/sbin:$PATH
   fi
   for dir in   /usr/X11/bin \
                   /usr/bin/X11\
                   /usr/X11R6/bin\
                   /var/lib/dosemu\
                   /usr/games\
                   /opt/bin\
                   /opt/kde3/bin\
                   /opt/kde2/bin\
                   /opt/kde/bin\
                   /usr/openwin/bin\
                   /opt/cross/bin
   do
         test-d $dir && PATH=$PATH:$dir
   done
   unset dir
   export PATH
fi
 
#环境变量INPUTRC,设置加载快捷键
# Many programs using readline library forline editing
# should know about this (e.g. bash)
#
if test -z "$INPUTRC" ; then
   INPUTRC=/etc/inputrc
   test -s $HOME/.inputrc && INPUTRC=$HOME/.inputrc
   export INPUTRC
fi
 
#
# Most bourn shell clones knows about this
#
if test -z "$PROFILEREAD" ; then
   HISTSIZE=1000
   export HISTSIZE
fi
 
#
# Set some environment variables forTeX/LaTeX (Not used due luatex)
#
#if test -n "$TEXINPUTS" ; then
#   TEXINPUTS=":$TEXINPUTS:$HOME/.TeX:/usr/share/doc/.TeX:/usr/doc/.TeX"
#else
#   TEXINPUTS=":$HOME/.TeX:/usr/share/doc/.TeX:/usr/doc/.TeX"
#fi
#export TEXINPUTS
 
#
# Configure the default pager on SuSE Linux
#
if test -z "$LESS" -a -x/usr/bin/less ; then
   LESS="-M -I"
   LESSOPEN="lessopen.sh %s"
   LESSCLOSE="lessclose.sh %s %s"
   LESS_ADVANCED_PREPROCESSOR="no"
   if test -s /etc/lesskey.bin ; then
         LESSKEY=/etc/lesskey.bin
   fi
   PAGER=less
   MORE=-sl
   export LESSOPEN LESSCLOSE LESS LESSKEY PAGER LESS_ADVANCED_PREPROCESSORMORE
fi
 
#
# Minicom
#
if test -z "$PROFILEREAD" ; then
   MINICOM="-c on"
   export MINICOM
fi
 
#
# Current manpath
#
if test -z "$PROFILEREAD" ; then
   tmp="$MANPATH"
   unset MANPATH
   if test -n "$tmp" ; then
         MANPATH="${tmp}:`test-x /usr/bin/manpath && /usr/bin/manpath -q`"
   else
         MANPATH="`test-x /usr/bin/manpath && /usr/bin/manpath -q`"
   fi
   unset tmp
   export MANPATH
fi
 
#
# Some applications do not handle theXAPPLRESDIR environment properly,
# when it contains more than one directory.More than one directory only
# makes sense if you have a client with/usr mounted via nfs and you want
# to configure applications machinedependent. Uncomment the lines below
# if you want this.
#
#XAPPLRESDIR="$XAPPLRESDIR:/var/X11R6/app-defaults:/usr/X11R6/lib/X11/app-defaults"
#export XAPPLRESDIR
 
#
# Set INFOPATH to tell xemacs where he canfind the info files
#
if test -z "$PROFILEREAD" ; then
   tmp="$INFODIR"
   if test -n "$tmp" ; then
         INFODIR="${tmp}:/usr/local/info:/usr/share/info:/usr/info"
   else
         INFODIR="/usr/local/info:/usr/share/info:/usr/info"
   fi
   INFOPATH=$INFODIR
   unset tmp
   export INFODIR INFOPATH
fi
 
#
# These settings are recommended for oldmotif applications
#
if test -z "$PROFILEREAD" ; then
   if [ -r /usr/share/X11/XKeysymDB ]; then
         exportXKEYSYMDB=/usr/share/X11/XKeysymDB
   else
         exportXKEYSYMDB=/usr/X11R6/lib/X11/XKeysymDB
   fi
   if [ -d /usr/share/X11/nls ]; then
         exportXNLSPATH=/usr/share/X11/nls
   else
         exportXNLSPATH=/usr/X11R6/lib/X11/nls
   fi
 
    #
    #Midnight Commander needs this to run in color mode
    #
   COLORTERM=1
   export COLORTERM
fi
 
#
# For RCS
#
#VERSION_CONTROL=numbered
#export VERSION_CONTROL
 
#
# Source the files generated by SuSEconfig
#
# But do not source this if PROFILEREAD isalready set to avoid
# overriding locale variables alreadypresent in the environment
#
if test -z "$PROFILEREAD" ; then
   test -r /etc/profile.d/sh.ssh  && . /etc/profile.d/sh.ssh
   test -r /etc/SuSEconfig/profile && . /etc/SuSEconfig/profile
   if test -z "$SSH_SENDS_LOCALE" ; then
       if test -r /etc/sysconfig/language -a -r /etc/profile.d/sh.utf8 ; then
             tmp="$(. /etc/sysconfig/language; echo$AUTO_DETECT_UTF8)"
             test "$tmp" = "yes"&& . /etc/profile.d/sh.utf8
             unset tmp
         fi
   fi
fi
 
#
# Source profile extensions for certainpackages, the super
# may disable some of them by setting thesticky bit.
#
if test -d /etc/profile.d -a -z"$PROFILEREAD" ; then
   for s in /etc/profile.d/*.sh ; do
         test-r $s -a ! -k $s && . $s
   done
   unset s
fi
 
if test "$is" != "ash"; then
    #
    #And now let's see if there is a local profile
    #(for options defined by your sysadmin, not SuSE Linux)
    #
   test -s /etc/profile.local && . /etc/profile.local
fi
 
#
# System wide configuration of bourneshells like ash
#
if test "$is" != "ksh"-a "$is" != "zsh" -a -z "$PROFILEREAD" ; then
   ENV=/etc/bash.bashrc
   export ENV
fi
 
#
# Avoid overwriting user settings if calledtwice
#
if test -z "$PROFILEREAD" ; then
   readonly PROFILEREAD=true
   export PROFILEREAD
fi
 
#
# Standard ssh command does not do anlogin, therefore
# /etc/profile will be sourced by/etc/bash.bashrc
#
if test -z "$_SOURCED_FOR_SSH" ;then
    #
    #System BASH specials, maybe also good for other shells
    #Note that ksh always reads /etc/ksh.kshrc
    #
   if test "$is" != ksh -a "$is" != zsh ; then
         test-r /etc/bash.bashrc && . /etc/bash.bashrc
   fi
   if test -n "$restricted" ; then
         readonly_HOMEBASHRC=true
   fi
   if test "$is" = "bash" -a -z"$_HOMEBASHRC" ; then
         #loop detection
         readonly_HOMEBASHRC=true
         test-r $HOME/.bashrc && . $HOME/.bashrc
   fi
 
    #
    #KSH specials
    #
   if test "$is" = "ksh" -a -r /etc/ksh.kshrc ; then
         iftest -n "$restricted" ; then
             readonly _HOMEKSHRC=true
         fi
         iftest ! /etc/bash.bashrc -ef /etc/ksh.kshrc ; then
             test -r /etc/bash.bashrc && ./etc/bash.bashrc
         fi
         iftest -n "$ENV" -a "$ENV" != "\$HOME/.kshrc" -a -z"$_HOMEKSHRC" ; then
             # loop detection
             readonly _HOMEKSHRC=true
             test -r $HOME/.kshrc && .$HOME/.kshrc
         fi
   fi
fi
if test -n "$restricted" ; then
   PATH=/usr/lib/restricted/bin
   export PATH
fi
 
#
# An X session
#
case "$-" in
*i*)
   if test "$TERM" = "xterm" -a -O "$tty" ;then
         iftest -z "${SSH_TTY}" ; then
             test ! -f $HOME/.hushlogin -a -s /etc/motd&& cat /etc/motd
             echo"Directory: $PWD"
             # Last but not least
             date
         fi
         #
         #shadow passwd
         #Note: on normal console this will be done by /bin/login
         #iftest -r /var/log/faillog ; then
         #    test -x /bin/faillog &&/bin/faillog
         #    test -x /usr/sbin/faillog &&/usr/sbin/faillog
         #fi
   fi
esac
 
#专门为Oracle用户添加的限制条件
if [ $USER = "oracle" ]; then
      if [ $SHELL = "/bin/ksh" ]; then
              ulimit -p 16384
              ulimit -n 65536
      else
              ulimit -u 16384 -n 65536
       fi
fi
#JAVA的环境变量,这可以让所有新建用户都是用同一套JDK环境
JAVA_HOME=/usr/local/jdk1.7.0_67
CLASSPATH=.:$JAVA_HOME/lib/tools.jar
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME CLASSPATH PATH
# End of /etc/profile


个人用户配置文件.bash_profile

SUSE中这个文件命名为.bashrc,在这里配置的环境变量、别名等信息只针对当前用户生效。

该文件的模板位于/etc/skel目录下。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值