lecture
in color
/bin/sh: The Bourne Shell
/usr/bin/tcsh.
/bin/sh (or /bin/bash).
bash# csh csh# ... do whatever you need to ... csh# exit # end c-shell; back to bash bash#
csh vs. sh
topic csh sh
variables set var=value var=value
environment setenv VAR value export VAR=value
arrays $a[1-9] no concept of array
command exec `command` $(command)
arithmetic @ i = $i+$j i=$[$i+$j]
conditionals if (conditions) then if conditions; then
... ...
else else
... ...
endif fi
foreach foreach i (stuff) for i in stuff; do
... ...
end done
while while (conditions) while conditions; do
... ...
end done
exit status $status $?
stderr foo >& bar foo > bar 2>&1
foo >>& bar foo >> bar 2>&1
foo |& bar foo | bar 2>&1
startup .cshrc .profile
aliases alias m more no concept of alias
TERM (no shell variable $term!)
PATH (no shell variable $path!)
EDITOR
;, &, etc.
*, [...], {...}, ?, ...)
works the same way in both shells
(but sh has variable wildcarding as well, to replace arrays). "...", '...', `...` are interpreted exactly the same way.
(...) works the same way in both.
(...) works the same way in sh and csh, and means to execute the
contents in a subshell bash# (export EDITOR=emacs; pine)sets your
EDITOR to emacs and runs pine, after which you get your old EDITOR variable back!( cd /from; tar cf - . ) | ( cd /to; tar xfBp - )
sh shell variables:
var=1 # csh: set var=1
sh environment variables:
TERM=vt100; export TERM # csh: setenv TERM vt100or, more simply:
export TERM=vt100
${var} - the value of the variable var
$(var) - the value of the command var
$[var] - the value of the arithmetic expression var
sh syntax: foo -bar cat is a command
foo with arguments -bar cat whose meaning is determined solely by foo (man foo for details).
sh and csh: csh is closer to C.
sh syntax is closer to the way the machine operates.
csh has security problems)
sh, you have to understand the operating system.
sh scripts depends dearly on an understanding of process exit status.
exit(0); /* worked correctly */
exit 0 # worked correctly.
0.
man (end of manual page entry)
csh, after each command, the exit status is in the variable $status.
sh, the status is stored in $?.
& and |.
csh and sh):
a ; b - for a and b commands, do b only after a completes.
a & b - for a and b commands, do a and b in parallel
(background execution).
a && b - for a and b commands, do b only if a succeeds (status 0)
grep -l foo bar.c && rm -f bar.conly removes
bar.c if it contains the word foo. a || b
a and b commands, do b only if a fails (status not 0)
grep -l foo bar.c || rm -f bar.conly removes
bar.c if it doesn't contain the word foo. ( a ) - execute a in a subshell.
csh and tcsh as well.
sh programming they're ubiquitous.
bash# grep couch /etc/motd >/dev/null && cat >>/etc/motd <<EOF couch was here\! EOF
bash# niscat passwd.org_dir | grep couch || rm -rf /
test: translate logical condition into exit statussh conditionals work based upon command exit status.
test (man test for details).
test $foo - is the string value of variable foo nonempty?
test $foo = 'ho' - is the string value of variable foo equal to 'ho'?
test $foo != 'ho' - is the string value of variable foo unequal to 'ho'?
test $foo -eq $bar - is the numeric value of foo equal to the numeric value of bar?
test $foo -ne $bar - is the numeric value of foo equal to the numeric value of bar?
test $foo -ge $bar - is the numeric value of foo greater than or equal to the numeric value of bar?
test $foo -gt $bar - is the numeric value of foo greater than the numeric value of bar?
test $foo -le $bar - is the numeric value of foo less than or equal to the numeric value of bar?
test $foo -lt $bar - is the numeric value of foo less than the numeric value of bar?
test -f foo: is foo a file?
test -d foo: is foo a directory?
test -e foo: does foo exist?
test -L foo: is foo a symlink?
test -x foo: is foo executable (to you)?
This is different from permissions or -perm in find. It tests whether the file
is executable to you with the permissions you have.
find (!)-a: logical and
-o: logical or
!: logical not
test -f foo -a ! -L foois true (status 0) if
foo represents a file and not a symlink (it can be both).
test is so frighteningly useful that there's a shorthand for it in sh
(only):
[ conditions ] ^ ^ spaces MUST be here!means
test conditionswhere the spaces after
[ and before ] are required (so that the first test argument won't be treated as part of the command).
sh? Translate [...] into
equivalent calls to test. bash# [ -f /etc/motd -a ! -L /etc/motd ] && [ $USER = 'couch' ] && echo 'hi couch'
test if (condition) thenmeans
test condition ; if ($status == 0) then
if [ condition ] ; then ... fimeans
if test condition; then ... fi
find . -exec test \`basename {} .c\` = 'foo' \; -print
prints every file whose basename is foo with a .c extension, i.e., all files named foo.c.
<, >, <<, >>,
| same as in csh.
>&, >>&,
|& handled very differently. csh sh a >& b a > b 2>&1 a >>& b a >> b 2>&1 a |& b a | b 2>&1
2>&1 - copy output of file descriptor 2 (standard error) onto
file descriptor 1 (standard output).
stdin
stdout
stderr
FILE*) you get a file descriptor
inside the FILE* structure. fileno:
#include <stdio.h>
main() {
FILE *f = fopen("foo","r");
printf("fileno of stdin is %d\n",fileno(stdin));
printf("fileno of stdout is %d\n",fileno(stdout));
printf("fileno of stderr is %d\n",fileno(stderr));
printf("fileno of f is %d\n",fileno(f));
}
fileno of stdin is 0 fileno of stdout is 1 fileno of stderr is 2 fileno of f is 3
shsh, the status of the previous command is stored in $?.
if statement:
if [ $foo = 'hi' ]; then
echo 'hi yourself'
else
echo 'good morning'
fi
[ and before ] are obligatory.
[...] is a test to execute.
if test $foo = 'hi' ; then
echo 'hi yourself'
else
echo 'good morning'
fi
if can be any command
if grep -l couch /etc/motd >/dev/null ; then echo 'you are famous' fi
grep returns 0 if it finds its pattern.
grep returns 1 if it doesn't find its pattern.
echo occurs only if I'm mentioned in the motd
grep to /dev/null to
discard it. I only want the exit status. while, for other logical tests, etc.
if [ $foo = 'bar' ]; then ... fifails with a syntax error if
$foo is the empty string.if [ x$foo = x'bar' ]; then ... fifails with a syntax error if
$foo is the empty string. This does not ever fail as a test, even if $foo is empty.
case statement
case statement is similar to the switch statement
case "$state" in
'start')
echo 'Starting'
;;
'stop')
echo 'Stopping'
;;
*)
echo "state must be start or stop"
;;
esac
$state as a variable!
for i in 1 2 3 4 5; do echo $i doneprints
1 2 3 4 5
foo='1 2 3' for i in $foo; do echo $i done
i=1 while [ $i != 10 ]; do echo $i i= $[$i+1] done
$[$i+1]- substitute the arithmetic value of $i+1.
$foo or ${foo}
$[$foo*$bar]
$(cat /etc/csh.people)
${foo:-bar} value of ${foo} or 'bar' if no value (default)!
${foo:=bar} value of ${foo} or set value of ${foo} to 'bar' if no value (default)!
${foo:?"I am unset"} displays error message if ${foo} isn't set!
${foo#pattern} is the value of ${foo} except the pattern pattern
is stripped from the beginning of ${foo}.
foobar='one two three'
for cat in $foobar; do
echo $cat ${foo:-hawk}
foo=$cat
done
prog=hand
goo=${foo:=cat}
case $goo in
st*t) echo ${hand:-dog} is starting
;;
st*p) echo ${hand:-dog} is stopping
;;
*) echo ${hand:-dog} does not understand!
;;
esac
ls /etc/rc.d/rc2.d/S* produces:
/etc/rc.d/rc2.d/S10network /etc/rc.d/rc2.d/S45pcmcia /etc/rc.d/rc2.d/S11xntpd /etc/rc.d/rc2.d/S60lpd /etc/rc.d/rc2.d/S16apmd /etc/rc.d/rc2.d/S75keytablethen what is the output of the following:
for i in /etc/rc.d/rc2.d/S*; do
echo ${i#/etc/rc.d/rc2.d/S??}
done
sh!
sh syntax.
shutdown +10 "to forever sleep"
+10 in 10 minutes.
"to forever sleep": comment for users.
-r reboot.
-c cancel running shutdown.
halt
/etc/rc.d/rc.sysinit (rc.boot) - needed to get to single-user mode.
/etc/rc.d/rc - needed to get from single-user mode to multi-user mode.
contents of sh/rc.sysinit...
#!/bin/bash
#
# /etc/rc.d/rc.sysinit - run once at boot time
#
# Taken in part from Miquel van Smoorenburg's bcheckrc.
#
# Couch: the following step exec's initlog to replace this process exactly
# once. The point is to log all the stuff that this script outputs in a file
# (/var/log/messages). If we've already done this we don't do it again.
# Rerun ourselves through initlog
if [ -z "$IN_INITLOG" -a -x /sbin/initlog ]; then
exec /sbin/initlog $INITLOG_ARGS -r /etc/rc.d/rc.sysinit
fi
# If we're using devfs, start devfsd now - we need the old device names
[ -e /dev/.devfsd -a -x /sbin/devfsd ] && /sbin/devfsd /dev
HOSTNAME=`/bin/hostname`
# Couch: now we source the file /etc/sysconfig/network to read
# the PARAMETERS of our network (not time to start yet)
if [ -f /etc/sysconfig/network ]; then
. /etc/sysconfig/network
else
NETWORKING=no
fi
if [ -z "$HOSTNAME" -o "$HOSTNAME" = "(none)" ]; then
HOSTNAME=localhost
fi
# Couch: read in the definitions of lots of useful shell functions
. /etc/init.d/functions
# Start the graphical boot, if necessary
if [ "$BOOTUP" = "graphical" ]; then
if [ -x /usr/bin/rhgb ]; then
/usr/bin/rhgb
else
export BOOTUP=color
fi
fi
# Couch: redirect output to all locally connected terminals
# so system administrator can see boot process
last=0
for i in `LC_ALL=C grep '^[0-9]*.*respawn:/sbin/mingetty' /etc/inittab | sed 's/^.* tty\([0-9][0-9]*\).*/\1/g'`; do
> /dev/tty$i
last=$i
done
if [ $last -gt 0 ]; then
> /dev/tty$((last+1))
> /dev/tty$((last+2))
fi
if [ "`/sbin/consoletype`" = "vt" -a -x /sbin/setsysfont ]; then
echo -n "Setting default font ($SYSFONT): "
/sbin/setsysfont
if [ $? -eq 0 ]; then
success
else
failure
fi
echo ; echo
fi
# Print a text banner.
echo -en $"\t\tWelcome to "
if LC_ALL=C grep -q "Red Hat" /etc/redhat-release ; then
[ "$BOOTUP" = "color" ] && echo -en "\\033[0;31m"
echo -en "Red Hat"
[ "$BOOTUP" = "color" ] && echo -en "\\033[0;39m"
PRODUCT=`sed "s/Red Hat \(.*\) release.*/\1/" /etc/redhat-release`
echo " $PRODUCT"
else
PRODUCT=`sed "s/ release.*//g" /etc/redhat-release`
echo "$PRODUCT"
fi
if [ "$PROMPT" != "no" ]; then
echo -en $"\t\tPress 'I' to enter interactive startup."
echo
sleep 1
fi
# Fix console loglevel
/bin/dmesg -n $LOGLEVEL
# Mount /proc (done here so volume labels can work with fsck)
action $"Mounting proc filesystem: " mount -n -t proc /proc /proc
# Unmount the initrd, if necessary
if LC_ALL=C grep -q /initrd /proc/mounts && ! LC_ALL=C grep -q /initrd/loopfs /proc/mounts ; then
if [ -e /initrd/dev/.devfsd ]; then
umount /initrd/dev
fi
action $"Unmounting initrd: " umount /initrd
/sbin/blockdev --flushbufs /dev/ram0 >/dev/null 2>&1
fi
# Configure kernel parameters
action $"Configuring kernel parameters: " sysctl -e -p /etc/sysctl.conf
# Set the system clock.
ARC=0
SRM=0
UTC=0
>
if [ -f /etc/sysconfig/clock ]; then
. /etc/sysconfig/clock # Couch: read CONFIGURATION of clock
# convert old style clock config to new values
if [ "${CLOCKMODE}" = "GMT" ]; then
UTC=true
elif [ "${CLOCKMODE}" = "ARC" ]; then
ARC=true
fi
fi
# Couch: build $CLOCKFLAGS so that one can set clock
CLOCKDEF=""
CLOCKFLAGS="$CLOCKFLAGS --hctosys"
case "$UTC" in
yes|true)
CLOCKFLAGS="$CLOCKFLAGS --utc";
CLOCKDEF="$CLOCKDEF (utc)";
;;
no|false)
CLOCKFLAGS="$CLOCKFLAGS --localtime";
CLOCKDEF="$CLOCKDEF (localtime)";
;;
esac
case "$ARC" in
yes|true)
CLOCKFLAGS="$CLOCKFLAGS --arc";
CLOCKDEF="$CLOCKDEF (arc)";
;;
esac
case "$SRM" in
yes|true)
CLOCKFLAGS="$CLOCKFLAGS --srm";
CLOCKDEF="$CLOCKDEF (srm)";
;;
esac
/sbin/hwclock $CLOCKFLAGS # Couch: actually modify clock
action $"Setting clock $CLOCKDEF: `date`" date
# Couch: start setting up system console correctly.
# load appropriate keymap, etc
if [ "`/sbin/consoletype`" = "vt" -a -x /bin/loadkeys ]; then
KEYTABLE=
KEYMAP=
if [ -f /etc/sysconfig/console/default.kmap ]; then
KEYMAP=/etc/sysconfig/console/default.kmap
else
if [ -f /etc/sysconfig/keyboard ]; then
. /etc/sysconfig/keyboard
fi
if [ -n "$KEYTABLE" -a -d "/lib/kbd/keymaps" ]; then
KEYMAP=$KEYTABLE
fi
fi
if [ -n "$KEYMAP" ]; then
# Since this takes in/output from stdin/out, we can't use initlog
if [ -n "$KEYTABLE" ]; then
echo -n $"Loading default keymap ($KEYTABLE): "
else
echo -n $"Loading default keymap: "
fi
loadkeys $KEYMAP < /dev/tty0 > /dev/tty0 2>/dev/null && \
success $"Loading default keymap" || failure $"Loading default keymap"
echo
fi
fi
# Set the hostname.
action $"Setting hostname ${HOSTNAME}: " hostname ${HOSTNAME}
# Initialize USB controller and HID devices
usb=0
if ! LC_ALL=C grep -iq "nousb" /proc/cmdline 2>/dev/null && ! LC_ALL=C grep -q "usb" /proc/devices 2>/dev/null ; then
aliases=`/sbin/modprobe -c | awk '/^alias usb-controller/ { print $3 }'`
if [ -n "$aliases" -a "$aliases" != "off" ]; then
modprobe usbcore
for alias in $aliases ; do
[ "$alias" != "off" ] && action $"Initializing USB controller ($alias): " modprobe $alias
done
[ $? -eq 0 -a -n "$aliases" ] && usb=1
fi
fi
if ! LC_ALL=C grep -iq "nousb" /proc/cmdline 2>/dev/null && LC_ALL=C grep -q "usb" /proc/devices 2>/dev/null ; then
usb=1
fi
if [ $usb = 1 -a ! -f /proc/bus/usb/devices ]; then
action $"Mounting USB filesystem: " mount -t usbdevfs usbdevfs /proc/bus/usb
fi
needusbstorage=
if [ $usb = "1" ]; then
needusbstorage=`LC_ALL=C grep -e "^I.*Cls=08" /proc/bus/usb/devices 2>/dev/null`
LC_ALL=C grep 'hid' /proc/bus/usb/drivers || action $"Initializing USB HID interface: " modprobe hid 2> /dev/null
action $"Initializing USB keyboard: " modprobe keybdev 2> /dev/null
action $"Initializing USB mouse: " modprobe mousedev 2> /dev/null
fi
if [ -f /fastboot ] || LC_ALL=C grep -iq "fastboot" /proc/cmdline 2>/dev/null ; then
fastboot=yes
fi
if [ -f /fsckoptions ]; then
fsckoptions=`cat /fsckoptions`
fi
if [ -f /forcefsck ]; then
fsckoptions="-f $fsckoptions"
elif [ -f /.autofsck ]; then
echo $"Your system appears to have shut down uncleanly"
AUTOFSCK_TIMEOUT=5
[ -f /etc/sysconfig/autofsck ] && . /etc/sysconfig/autofsck
if [ "$AUTOFSCK_DEF_CHECK" = "yes" ]; then
AUTOFSCK_OPT=-f
fi
if [ "$PROMPT" != "no" ]; then
if [ "$AUTOFSCK_DEF_CHECK" = "yes" ]; then
if /sbin/getkey -c $AUTOFSCK_TIMEOUT -m $"Press N within %d seconds to not force file system integrity check..." n ; then
AUTOFSCK_OPT=
fi
else
if /sbin/getkey -c $AUTOFSCK_TIMEOUT -m $"Press Y within %d seconds to force file system integrity check..." y ; then
AUTOFSCK_OPT=-f
fi
fi
echo
else
# PROMPT not allowed
if [ "$AUTOFSCK_DEF_CHECK" = "yes" ]; then
echo $"Forcing file system integrity check due to default setting"
else
echo $"Not forcing file system integrity check due to default setting"
fi
fi
fsckoptions="$AUTOFSCK_OPT $fsckoptions"
fi
if [ "$BOOTUP" = "color" ]; then
fsckoptions="-C $fsckoptions"
else
fsckoptions="-V $fsckoptions"
fi
_RUN_QUOTACHECK=0
ROOTFSTYPE=`awk '/ \/ / && ($3 !~ /rootfs/) { print $3 }' /proc/mounts`
if [ -z "$fastboot" -a "X$ROOTFSTYPE" != "Xnfs" ]; then
STRING=$"Checking root filesystem"
echo $STRING
initlog -c "fsck -T -a $fsckoptions /"
rc=$?
if [ "$rc" = "0" ]; then
success "$STRING"
echo
elif [ "$rc" = "1" ]; then
passed "$STRING"
echo
fi
# A return of 2 or higher means there were serious problems.
if [ $rc -gt 1 ]; then
if [ "$BOOTUP" = "graphical" ]; then
chvt 1
fi
failure "$STRING"
echo
echo
echo $"*** An error occurred during the file system check."
echo $"*** Dropping you to a shell; the system will reboot"
echo $"*** when you leave the shell."
str=$"(Repair filesystem)"
PS1="$str \# # "; export PS1
sulogin
# Couch: we found a fatal error in the filesystem
# Reboot to fix:
echo $"Unmounting file systems"
umount -a
mount -n -o remount,ro /
echo $"Automatic reboot in progress."
reboot -f
elif [ "$rc" = "1" ]; then
_RUN_QUOTACHECK=1
fi
fi
# Possibly update quotas if fsck was run on /.
LC_ALL=C grep -E '[[:space:]]+/[[:space:]]+' /etc/fstab | \
awk '{ print $4 }' | \
LC_ALL=C grep -q quota
_ROOT_HAS_QUOTA=$?
if [ X"$_RUN_QUOTACHECK" = X1 -a \
"$_ROOT_HAS_QUOTA" = "0" -a \
-x /sbin/quotacheck ]; then
if [ -x /sbin/convertquota ]; then
if [ -f /quota.user ]; then
action $"Converting old user quota files: " \
/sbin/convertquota -u / && rm -f /quota.user
fi
if [ -f /quota.group ]; then
action $"Converting old group quota files: " \
/sbin/convertquota -g / && rm -f /quota.group
fi
fi
action $"Checking root filesystem quotas: " /sbin/quotacheck -nug /
fi
# Couch: ISA bus Plug-and-Play support
if [ -x /sbin/isapnp -a -f /etc/isapnp.conf -a ! -f /proc/isapnp ]; then
# check for arguments passed from kernel
if ! LC_ALL=C grep -iq nopnp /proc/cmdline >/dev/null 2>&1 ; then
PNP=yes
fi
if [ -n "$PNP" ]; then
action $"Setting up ISA PNP devices: " /sbin/isapnp /etc/isapnp.conf
else
action $"Skipping ISA PNP configuration at users request: " /bin/true
fi
fi
# Remount the root filesystem read-write.
state=`awk '/ \/ / && ($3 !~ /rootfs/) { print $4 }' /proc/mounts`
[ "$state" != "rw" ] && \
action $"Remounting root filesystem in read-write mode: " mount -n -o remount,rw /
# Couch: extend kernel with "modules" using "modprobe"
# LVM initialization
if [ -f /etc/lvmtab -a ! -e /proc/lvm ] ; then
modprobe lvm-mod >/dev/null 2>&1
fi
if [ -e /proc/lvm -a -x /sbin/vgchange -a -f /etc/lvmtab ]; then
action $"Setting up Logical Volume Management:" /sbin/vgscan && /sbin/vgchange -a y
fi
Couch: now we're starting to really bring the system up
# Start up swapping.
action $"Activating swap partitions: " swapon -a -e
# Clear mtab
>/etc/mtab
# Remove stale backups
rm -f /etc/mtab~ /etc/mtab~~
# Enter root, /proc and (potentially) /proc/bus/usb and devfs into mtab.
mount -f /
mount -f /proc
[ -f /proc/bus/usb/devices ] && mount -f -t usbdevfs usbdevfs /proc/bus/usb
[ -e /dev/.devfsd ] && mount -f -t devfs devfs /dev
# The root filesystem is now read-write, so we can now log
# via syslog() directly..
if [ -n "$IN_INITLOG" ]; then
IN_INITLOG=
fi
if ! LC_ALL=C grep -iq nomodules /proc/cmdline 2>/dev/null && [ -f /proc/ksyms ]; then
USEMODULES=y
fi
# Our modutils don't support it anymore, so we might as well remove
# the preferred link.
rm -f /lib/modules/preferred /lib/modules/default
if [ -x /sbin/depmod -a -n "$USEMODULES" ]; then
# If they aren't using a recent sane kernel, make a link for them
if [ ! -n "`uname -r | LC_ALL=C grep -- "-"`" ]; then
ktag="`cat /proc/version`"
mtag=`LC_ALL=C grep -l "$ktag" /lib/modules/*/.rhkmvtag 2> /dev/null`
if [ -n "$mtag" ]; then
mver=`echo $mtag | sed -e 's,/lib/modules/,,' -e 's,/.rhkmvtag,,' -e 's,[ ].*$,,'`
fi
if [ -n "$mver" ]; then
ln -sf /lib/modules/$mver /lib/modules/default
fi
fi
if [ -L /lib/modules/default ]; then
INITLOG_ARGS= action $"Finding module dependencies: " depmod -A default
else
INITLOG_ARGS= action $"Finding module dependencies: " depmod -A
fi
fi
# tweak isapnp settings if needed.
if [ -n "$PNP" -a -f /proc/isapnp -a -x /sbin/sndconfig ]; then
/sbin/sndconfig --mungepnp >/dev/null 2>&1
fi
# Load sound modules if and only if they need persistent DMA buffers
if LC_ALL=C grep -q "options sound dmabuf=1" /etc/modules.conf 2>/dev/null ; then
RETURN=0
alias=`/sbin/modprobe -c | awk '/^alias sound / { print $3 }'`
if [ -n "$alias" -a "$alias" != "off" ]; then
action $"Loading sound module ($alias): " modprobe sound
RETURN=$?
fi
alias=`/sbin/modprobe -c | awk '/^alias sound-slot-0 / { print $3 }'`
if [ -n "$alias" -a "$alias" != "off" ]; then
action $"Loading sound module ($alias): " modprobe sound-slot-0
RETURN=$?
fi
fi
if [ -f /proc/sys/kernel/modprobe ]; then
if [ -n "$USEMODULES" ]; then
sysctl -w kernel.modprobe="/sbin/modprobe" >/dev/null 2>&1
sysctl -w kernel.hotplug="/sbin/hotplug" >/dev/null 2>&1
else
# We used to set this to NULL, but that causes 'failed to exec' messages"
sysctl -w kernel.modprobe="/bin/true" >/dev/null 2>&1
sysctl -w kernel.hotplug="/bin/true" >/dev/null 2>&1
fi
fi
# Couch: Extend kernel with new modules
# Load modules (for backward compatibility with VARs)
if [ -f /etc/rc.modules ]; then
/etc/rc.modules
fi
if [ -f /etc/raidtab ]; then
# Add raid devices
[ -f /proc/mdstat ] || modprobe md >/dev/null 2>&1
fi
if [ -f /etc/raidtab -a -f /proc/mdstat ]; then
echo -n $"Starting up RAID devices: "
rc=0
for i in `awk '{if ($1=="raiddev") print $2}' /etc/raidtab`
do
RAIDDEV=`basename $i`
RAIDSTAT=`LC_ALL=C grep "^$RAIDDEV : active" /proc/mdstat`
if [ -z "$RAIDSTAT" ]; then
# First scan the /etc/fstab for the "noauto"-flag
# for this device. If found, skip the initialization
# for it to avoid dropping to a shell on errors.
# If not, try raidstart...if that fails then
# fall back to raidadd, raidrun. If that
# also fails, then we drop to a shell
RESULT=1
INFSTAB=`LC_ALL=C grep -c "^$i" /etc/fstab`
if [ $INFSTAB -eq 0 ] ; then
RESULT=0
RAIDDEV="$RAIDDEV(skipped)"
fi
NOAUTO=`LC_ALL=C grep "^$i" /etc/fstab | LC_ALL=C grep -c "noauto"`
if [ $NOAUTO -gt 0 ]; then
RESULT=0
RAIDDEV="$RAIDDEV(skipped)"
fi
if [ $RESULT -gt 0 -a -x /sbin/raidstart ]; then
/sbin/raidstart $i
RESULT=$?
fi
if [ $RESULT -gt 0 -a -x /sbin/raid0run ]; then
/sbin/raid0run $i
RESULT=$?
fi
if [ $RESULT -gt 0 -a -x /sbin/raidadd -a -x /sbin/raidrun ]; then
/sbin/raidadd $i
/sbin/raidrun $i
RESULT=$?
fi
if [ $RESULT -gt 0 ]; then
rc=1
fi
echo -n "$RAIDDEV "
else
echo -n "$RAIDDEV "
fi
done
echo
# A non-zero return means there were problems.
if [ $rc -gt 0 ]; then
echo
echo
echo $"*** An error occurred during the RAID startup"
echo $"*** Dropping you to a shell; the system will reboot"
echo $"*** when you leave the shell."
str=$"(RAID Repair)"
PS1="$str \# # "; export PS1
sulogin
echo $"Unmounting file systems"
umount -a
mount -n -o remount,ro /
echo $"Automatic reboot in progress."
reboot -f
fi
# LVM initialization, take 2 (it could be on top of RAID)
if [ -e /proc/lvm -a -x /sbin/vgchange -a -f /etc/lvmtab ]; then
action $"Setting up Logical Volume Management:" /sbin/vgscan && /sbin/vgchange -a y
fi
fi
if [ -x /sbin/devlabel ]; then
/sbin/devlabel restart
fi
_RUN_QUOTACHECK=0
# Check filesystems
if [ -z "$fastboot" ]; then
STRING=$"Checking filesystems"
echo $STRING
initlog -c "fsck -T -R -A -a $fsckoptions"
rc=$?
if [ "$rc" = "0" ]; then
success "$STRING"
echo
elif [ "$rc" = "1" ]; then
passed "$STRING"
echo
fi
# A return of 2 or higher means there were serious problems.
if [ $rc -gt 1 ]; then
if [ "$BOOTUP" = "graphical" ]; then
chvt 1
fi
failure "$STRING"
echo
echo
echo $"*** An error occurred during the file system check."
echo $"*** Dropping you to a shell; the system will reboot"
echo $"*** when you leave the shell."
str=$"(Repair filesystem)"
PS1="$str \# # "; export PS1
sulogin
# Couch: yet again, we've crashed. Reboot
echo $"Unmounting file systems"
umount -a
mount -n -o remount,ro /
echo $"Automatic reboot in progress."
reboot -f
elif [ "$rc" = "1" -a -x /sbin/quotacheck ]; then
_RUN_QUOTACHECK=1
fi
fi
# Mount all other filesystems (except for NFS and /proc, which is already
# mounted). Contrary to standard usage,
# filesystems are NOT unmounted in single user mode.
action $"Mounting local filesystems: " mount -a -t nonfs,smbfs,ncpfs -O no_netdev
# check remaining quotas other than root
if [ X"$_RUN_QUOTACHECK" = X1 -a -x /sbin/quotacheck ]; then
if [ -x /sbin/convertquota ]; then
# try to convert old quotas
for mountpt in `awk '$4 ~ /quota/{print $2}' /etc/mtab` ; do
if [ -f "$mountpt/quota.user" ]; then
action $"Converting old user quota files: " \
/sbin/convertquota -u $mountpt && \
rm -f $mountpt/quota.user
fi
if [ -f "$mountpt/quota.group" ]; then
action $"Converting old group quota files: " \
/sbin/convertquota -g $mountpt && \
rm -f $mountpt/quota.group
fi
done
fi
action $"Checking local filesystem quotas: " /sbin/quotacheck -aRnug
fi
if [ -x /sbin/quotaon ]; then
action $"Enabling local filesystem quotas: " /sbin/quotaon -aug
fi
# Couch: here we check if the machine was a new build, and,
# if so, ask the user to specify lots of things about it...
# Configure machine if necessary.
if [ -f /.unconfigured ]; then
if [ "$BOOTUP" = "graphical" ]; then
chvt 1
fi
if [ -x /usr/bin/passwd ]; then
/usr/bin/passwd root
fi
if [ -x /usr/sbin/netconfig ]; then
/usr/sbin/netconfig
fi
if [ -x /usr/sbin/timeconfig ]; then
/usr/sbin/timeconfig
fi
if [ -x /usr/sbin/kbdconfig ]; then
/usr/sbin/kbdconfig
fi
if [ -x /usr/sbin/authconfig ]; then
/usr/sbin/authconfig --nostart
fi
if [ -x /usr/sbin/ntsysv ]; then
/usr/sbin/ntsysv --level 35
fi
# Reread in network configuration data.
if [ -f /etc/sysconfig/network ]; then
. /etc/sysconfig/network
# Reset the hostname.
action $"Resetting hostname ${HOSTNAME}: " hostname ${HOSTNAME}
fi
rm -f /.unconfigured
fi
# Clean out /.
rm -f /fastboot /fsckoptions /forcefsck /.autofsck /halt /poweroff
# Do we need (w|u)tmpx files? We don't set them up, but the sysadmin might...
_NEED_XFILES=
[ -f /var/run/utmpx -o -f /var/log/wtmpx ] && _NEED_XFILES=1
# Clean up /var. I'd use find, but /usr may not be mounted.
for afile in /var/lock/* /var/run/* ; do
if [ -d "$afile" ]; then
case "`basename $afile`" in
news|mon) ;;
sudo)
rm -f $afile/*/* ;;
*) rm -f $afile/* ;;
esac
else
rm -f $afile
fi
done
rm -f /var/lib/rpm/__db*
# Reset pam_console permissions
[ -x /sbin/pam_console_apply ] && /sbin/pam_console_apply -r
{
# Clean up utmp/wtmp
>/var/run/utmp
touch /var/log/wtmp
chgrp utmp /var/run/utmp /var/log/wtmp
chmod 0664 /var/run/utmp /var/log/wtmp
if [ -n "$_NEED_XFILES" ]; then
>/var/run/utmpx
touch /var/log/wtmpx
chgrp utmp /var/run/utmpx /var/log/wtmpx
chmod 0664 /var/run/utmpx /var/log/wtmpx
fi
# Delete X locks
rm -f /tmp/.X*-lock
# Delete VNC & X locks
rm -rf /tmp/.X*-unix
# Delete ICE locks
rm -rf /tmp/.ICE-unix
# Delete Postgres sockets
rm -f /tmp/.s.PGSQL.*
# Now turn on swap in case we swap to files.
swapon -a
action $"Enabling swap space: " /bin/true
# Initialize the serial ports.
if [ -f /etc/rc.serial ]; then
. /etc/rc.serial
fi
# If a SCSI tape has been detected, load the st module unconditionally
# since many SCSI tapes don't deal well with st being loaded and unloaded
if [ -f /proc/scsi/scsi ] && LC_ALL=C grep -q 'Type: Sequential-Access' /proc/scsi/scsi 2>/dev/null ; then
if LC_ALL=C grep -qv ' 9 st' /proc/devices && [ -n "$USEMODULES" ]; then
modprobe st >/dev/null 2>&1
fi
fi
# Load usb storage here, to match most other things
if [ -n "$needusbstorage" ]; then
modprobe usb-storage >/dev/null 2>&1
fi
# Ooh, firewire too.
if ! LC_ALL=C grep -iq "nofirewire" /proc/cmdline 2>/dev/null ; then
aliases=`/sbin/modprobe -c | awk '/^alias ieee1394-controller/ { print $3 }'`
if [ -n "$aliases" -a "$aliases" != "off" ]; then
for alias in $aliases ; do
[ "$alias" != "off" ] && action $"Initializing firewire controller ($alias): " modprobe $alias
done
LC_ALL=C grep -q "SBP2" /proc/bus/ieee1394/devices 2>/dev/null && modprobe sbp2 >/dev/null 2>&1
fi
fi
# If they asked for ide-scsi, load it
if LC_ALL=C grep -q "ide-scsi" /proc/cmdline ; then
modprobe ide-cd >/dev/null 2>&1
modprobe ide-scsi >/dev/null 2>&1
fi
# Couch: now for finesse: apply performance tuning directions
# Turn on harddisk optimization
# There is only one file /etc/sysconfig/harddisks for all disks
# after installing the hdparm-RPM. If you need different hdparm parameters
# for each of your disks, copy /etc/sysconfig/harddisks to
# /etc/sysconfig/harddiskhda (hdb, hdc...) and modify it.
# Each disk which has no special parameters will use the defaults.
# Each non-disk which has no special parameters will be ignored.
#
disk[0]=s;
disk[1]=hda; disk[2]=hdb; disk[3]=hdc; disk[4]=hdd;
disk[5]=hde; disk[6]=hdf; disk[7]=hdg; disk[8]=hdh;
disk[9]=hdi; disk[10]=hdj; disk[11]=hdk; disk[12]=hdl;
disk[13]=hdm; disk[14]=hdn; disk[15]=hdo; disk[16]=hdp;
disk[17]=hdq; disk[18]=hdr; disk[19]=hds; disk[20]=hdt;
if [ -x /sbin/hdparm ]; then
for device in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; do
unset MULTIPLE_IO USE_DMA EIDE_32BIT LOOKAHEAD EXTRA_PARAMS
if [ -f /etc/sysconfig/harddisk${disk[$device]} ]; then
. /etc/sysconfig/harddisk${disk[$device]}
HDFLAGS[$device]=
if [ -n "$MULTIPLE_IO" ]; then
HDFLAGS[$device]="-q -m$MULTIPLE_IO"
fi
if [ -n "$USE_DMA" ]; then
HDFLAGS[$device]="${HDFLAGS[$device]} -q -d$USE_DMA"
fi
if [ -n "$EIDE_32BIT" ]; then
HDFLAGS[$device]="${HDFLAGS[$device]} -q -c$EIDE_32BIT"
fi
if [ -n "$LOOKAHEAD" ]; then
HDFLAGS[$device]="${HDFLAGS[$device]} -q -A$LOOKAHEAD"
fi
if [ -n "$EXTRA_PARAMS" ]; then
HDFLAGS[$device]="${HDFLAGS[$device]} $EXTRA_PARAMS"
fi
else
HDFLAGS[$device]="${HDFLAGS[0]}"
fi
if [ -e "/proc/ide/${disk[$device]}/media" ]; then
hdmedia=`cat /proc/ide/${disk[$device]}/media`
if [ "$hdmedia" = "disk" -o -f "/etc/sysconfig/harddisk${disk[$device]}" ]; then
if [ -n "${HDFLAGS[$device]}" ]; then
action $"Setting hard drive parameters for ${disk[$device]}: " /sbin/hdparm ${HDFLAGS[$device]} /dev/${disk[$device]}
fi
fi
fi
done
fi
# Boot time profiles. Yes, this should be somewhere else.
if LC_ALL=C grep -q "netprofile=" /proc/cmdline ; then
cmdline=`cat /proc/cmdline`
for arg in $cmdline ; do
if [ "${arg##netprofile=}" != "${arg}" ]; then
[ -x /usr/sbin/redhat-config-network-cmd ] &&
/usr/sbin/redhat-config-network-cmd --profile ${arg##netprofile=}
fi
done
fi
# Generate a header that defines the boot kernel.
/sbin/mkkerneldoth
# Adjust symlinks as necessary in /boot to keep system services from
# spewing messages about mismatched System maps and so on.
if [ -L /boot/System.map -a -r /boot/System.map-`uname -r` -a \
! /boot/System.map -ef /boot/System.map-`uname -r` ]; then
ln -s -f System.map-`uname -r` /boot/System.map
fi
if [ ! -e /boot/System.map -a -r /boot/System.map-`uname -r` ]; then
ln -s -f System.map-`uname -r` /boot/System.map
fi
# The special Red Hat kernel library symlink must point to the right library
# We need to deal with cases where there is no library, and we need to
# deal with any version numbers that show up.
shopt -s nullglob
for library in /lib/kernel/$(uname -r)/libredhat-kernel.so* ; do
ln -f $library /lib/
ldconfig -n /lib/
done
shopt -u nullglob
# Now that we have all of our basic modules loaded and the kernel going,
# let's dump the syslog ring somewhere so we can find it later
dmesg -s 131072 > /var/log/dmesg
# Also keep kernel symbols around in case we need them for debugging
i=5
while [ $i -ge 0 ]; do
if [ -f /var/log/ksyms.$i ]; then
mv /var/log/ksyms.$i /var/log/ksyms.$(($i+1))
fi
i=$(($i-1))
done
(/bin/date;
/bin/uname -a;
/bin/cat /proc/cpuinfo;
[ -r /proc/modules ] && /bin/cat /proc/modules;
[ -r /proc/ksyms ] && /bin/cat /proc/ksyms) >/var/log/ksyms.0
# create the crash indicator flag to warn on crashes, offer fsck with timeout
touch /.autofsck
sleep 1
kill -TERM `/sbin/pidof getkey` >/dev/null 2>&1
} &
if [ "$PROMPT" != "no" ]; then
/sbin/getkey i && touch /var/run/confirm
fi
wait
...end of sh/rc.sysinit
rc.sysinit just does the basic configuration.
/etc/rc.d/rc:
contents of sh/rc...
#! /bin/bash
#
# rc This file is responsible for starting/stopping
# services when the runlevel changes.
#
# Original Author:
# Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
#
# Couch: define useful shell function
# check a file to be a correct runlevel script
check_runlevel ()
{
# Check if the file exists at all.
[ -x "$1" ] || return 1
# Reject backup files and files generated by rpm.
case "$1" in
*.rpmsave|*.rpmorig|*.rpmnew|*~|*.orig)
return 1
;;
esac
return 0
}
# Now find out what the current and what the previous runlevel are.
argv1="$1"
set `/sbin/runlevel`
runlevel=$2
previous=$1
export runlevel previous
# Couch: read lots of useful functions
. /etc/init.d/functions
# See if we want to be in user confirmation mode
if [ "$previous" = "N" ]; then
if [ -f /var/run/confirm ] \
|| grep -i confirm /proc/cmdline >/dev/null ; then
rm -f /var/run/confirm
CONFIRM=yes
export CONFIRM
echo $"Entering interactive startup"
else
echo $"Entering non-interactive startup"
fi
fi
# Get first argument. Set new runlevel to this argument.
[ -n "$argv1" ] && runlevel="$argv1"
# Is there an rc directory for this new runlevel?
[ -d /etc/rc$runlevel.d ] || exit 0
# Couch: we need to kill off anything that shouldn't be running.
# accomplish this by running K* in the runlevel directory, in order.
# for each match, run "K??something stop"
# First, run the KILL scripts.
for i in /etc/rc$runlevel.d/K* ; do
check_runlevel "$i" || continue
# Check if the subsystem is already up.
subsys=${i#/etc/rc$runlevel.d/K??}
[ -f /var/lock/subsys/$subsys -o -f /var/lock/subsys/$subsys.init ] \
|| continue
# Bring the subsystem down.
if egrep -q "(killproc |action )" $i ; then
$i stop
else
action $"Stopping $subsys: " $i stop
fi
done
# Couch: now the same game for starts.
# match S[0-9][0-9]*, run "S??something start" in order.
# since * sorts matches into alpha order, order of run
# is predetermined!
# Now run the START scripts.
for i in /etc/rc$runlevel.d/S* ; do
check_runlevel "$i" || continue
# Check if the subsystem is already up.
subsys=${i#/etc/rc$runlevel.d/S??}
[ -f /var/lock/subsys/$subsys -o -f /var/lock/subsys/$subsys.init ] \
&& continue
# If we're in confirmation mode, get user confirmation
if [ -n "$CONFIRM" ]; then
confirm $subsys
case $? in
0) :;;
2) CONFIRM=;;
*) continue;;
esac
fi
# Bring the subsystem up.
if [ "$subsys" = "halt" -o "$subsys" = "reboot" ]; then
export LC_ALL=C
exec $i start
fi
if egrep -q "(daemon |action |success |failure )" $i 2>/dev/null \
|| [ "$subsys" = "single" -o "$subsys" = "local" ]; then
$i start
else
action $"Starting $subsys: " $i start
fi
done
...end of sh/rc
/etc/rc.d/rc calls scripts from /etc/rc.d/rcN.d.
/etc/rc.d/rcN.d are symbolic links to
scripts in /etc/rc.d/init.d: lrwxrwxrwx 1 root root 14 Feb 8 10:19 K05innd -> ../init.d/innd lrwxrwxrwx 1 root root 15 Feb 8 10:22 K10pulse -> ../init.d/pulse lrwxrwxrwx 1 root root 15 Feb 8 10:24 K10xntpd -> ../init.d/xntpd lrwxrwxrwx 1 root root 14 Feb 8 10:22 K15pvmd -> ../init.d/pvmd lrwxrwxrwx 1 root root 20 Feb 8 10:17 K20bootparamd -> ../init.d/bootparamd lrwxrwxrwx 1 root root 13 Feb 8 10:22 K20nfs -> ../init.d/nfs lrwxrwxrwx 1 root root 16 Feb 8 10:22 K20rstatd -> ../init.d/rstatd lrwxrwxrwx 1 root root 17 Feb 8 10:22 K20rusersd -> ../init.d/rusersd lrwxrwxrwx 1 root root 16 Feb 8 10:22 K20rwalld -> ../init.d/rwalld lrwxrwxrwx 1 root root 15 Feb 8 10:22 K20rwhod -> ../init.d/rwhod lrwxrwxrwx 1 root root 15 Feb 8 10:23 K25squid -> ../init.d/squid lrwxrwxrwx 1 root root 13 Feb 8 10:17 K28amd -> ../init.d/amd lrwxrwxrwx 1 root root 16 Feb 8 10:21 K30mcserv -> ../init.d/mcserv lrwxrwxrwx 1 root root 17 Feb 8 10:36 K30postfix -> ../init.d/postfix lrwxrwxrwx 1 root root 19 Feb 8 10:24 K34yppasswdd -> ../init.d/yppasswdd lrwxrwxrwx 1 root root 15 Feb 8 10:18 K35dhcpd -> ../init.d/dhcpd lrwxrwxrwx 1 root root 13 Feb 8 10:22 K35smb -> ../init.d/smb lrwxrwxrwx 1 root root 15 Feb 8 10:17 K45named -> ../init.d/named lrwxrwxrwx 1 root root 15 Feb 8 10:24 K50snmpd -> ../init.d/snmpd lrwxrwxrwx 1 root root 13 Feb 8 10:22 K54pxe -> ../init.d/pxe lrwxrwxrwx 1 root root 16 Feb 8 10:22 K55routed -> ../init.d/routed lrwxrwxrwx 1 root root 18 Feb 8 10:21 K60mars-nwe -> ../init.d/mars-nwe lrwxrwxrwx 1 root root 14 Feb 8 10:22 K61ldap -> ../init.d/ldap lrwxrwxrwx 1 root root 14 Feb 8 10:35 K61sshd -> ../init.d/sshd lrwxrwxrwx 1 root root 17 Feb 8 12:35 K62keyserv -> ../init.d/keyserv lrwxrwxrwx 1 root root 15 Feb 8 10:18 K75gated -> ../init.d/gated lrwxrwxrwx 1 root root 14 Feb 8 10:22 K80nscd -> ../init.d/nscd lrwxrwxrwx 1 root root 16 Feb 8 10:24 K84ypserv -> ../init.d/ypserv lrwxrwxrwx 1 root root 18 Feb 8 10:19 K92ipchains -> ../init.d/ipchains lrwxrwxrwx 1 root root 18 Feb 8 10:17 S06reconfig -> ../init.d/reconfig lrwxrwxrwx 1 root root 17 Feb 8 10:17 S10network -> ../init.d/network lrwxrwxrwx 1 root root 17 Feb 8 10:22 S11portmap -> ../init.d/portmap lrwxrwxrwx 1 root root 15 Feb 8 12:35 S11xntpd -> ../init.d/xntpd lrwxrwxrwx 1 root root 17 Feb 8 10:22 S14nfslock -> ../init.d/nfslock lrwxrwxrwx 1 root root 14 Feb 8 10:17 S16apmd -> ../init.d/apmd lrwxrwxrwx 1 root root 16 Feb 8 10:17 S18autofs -> ../init.d/autofs lrwxrwxrwx 1 root root 16 Feb 8 10:17 S20random -> ../init.d/random lrwxrwxrwx 1 root root 15 Feb 8 10:17 S25netfs -> ../init.d/netfs lrwxrwxrwx 1 root root 17 Feb 8 12:35 S26keyserv -> ../init.d/keyserv lrwxrwxrwx 1 root root 16 Feb 8 10:17 S30syslog -> ../init.d/syslog lrwxrwxrwx 1 root root 16 Feb 8 10:22 S35identd -> ../init.d/identd lrwxrwxrwx 1 root root 14 Feb 8 10:35 S36sshd -> ../init.d/sshd lrwxrwxrwx 1 root root 13 Feb 8 10:17 S40atd -> ../init.d/atd lrwxrwxrwx 1 root root 15 Feb 8 10:17 S40crond -> ../init.d/crond lrwxrwxrwx 1 root root 16 Feb 8 10:20 S45pcmcia -> ../init.d/pcmcia lrwxrwxrwx 1 root root 14 Feb 8 10:19 S50inet -> ../init.d/inet lrwxrwxrwx 1 root root 13 Feb 8 10:21 S60lpd -> ../init.d/lpd lrwxrwxrwx 1 root root 18 Feb 8 10:17 S75keytable -> ../init.d/keytable lrwxrwxrwx 1 root root 14 Feb 8 10:19 S80isdn -> ../init.d/isdn lrwxrwxrwx 1 root root 17 Feb 8 10:36 S80postfix -> ../init.d/postfix lrwxrwxrwx 1 root root 15 Feb 8 10:17 S85httpd -> ../init.d/httpd lrwxrwxrwx 1 root root 13 Feb 8 10:17 S90xfs -> ../init.d/xfs lrwxrwxrwx 1 root root 19 Feb 8 10:21 S99linuxconf -> ../init.d/linuxconf lrwxrwxrwx 1 root root 11 Feb 8 10:17 S99local -> ../rc.local
/etc/rc.d/init.d actually make things happen:
-rwxr-xr-x 1 root root 1038 Feb 16 2000 amd -rwxr-xr-x 1 root root 525 Mar 3 2000 anacron -rwxr-xr-x 1 root root 1367 Oct 26 1999 apmd -rwxr-xr-x 1 root root 827 Feb 17 2000 arpwatch -rwxr-xr-x 1 root root 989 Mar 1 2000 atd -rwxr-xr-x 1 root root 6577 Feb 28 2000 autofs -rwxr-xr-x 1 root root 1035 Feb 3 2000 bootparamd -rwxr-xr-x 1 root root 1031 Feb 3 2000 crond -rwxr-xr-x 1 root root 970 Feb 3 2000 dhcpd -rwxr-xr-x 1 root root 7349 Jan 21 2000 functions -rwxr-xr-x 1 root root 1417 Feb 17 2000 gated -rwxr-xr-x 1 root root 3260 Mar 8 2000 halt -rwxr-xr-x 1 root root 865 Mar 1 2000 httpd -rwxr-xr-x 1 root root 1151 Feb 22 2000 identd -rwxr-xr-x 1 root root 1463 Jan 31 2000 inet -rwxr-xr-x 1 root root 1890 Mar 2 2000 innd -rwxr-xr-x 1 root root 2448 Feb 16 2000 ipchains -rwxr-xr-x 1 root root 910 Feb 4 2000 irda -rwxr-xr-x 1 root root 11259 Mar 6 2000 isdn -rwxr-xr-x 1 root root 1065 Mar 8 2000 kdcrotate -rwxr-xr-x 1 root root 730 Feb 8 10:39 keyserv -rwxr-xr-x 1 root root 1203 Mar 6 2000 keytable -rwxr-xr-x 1 root root 449 Sep 30 1999 killall -rwxr-xr-x 1 root root 1458 Mar 8 2000 krb5server -rwxr-xr-x 1 root root 1890 Feb 14 2000 ldap lrwxrwxrwx 1 root root 43 Feb 8 10:21 linuxconf -> /usr/lib/linuxconf/redhat/scripts/linuxconf -rwxr-xr-x 1 root root 1176 Feb 14 2000 lpd -rwxr-xr-x 1 root root 1104 Feb 24 2000 mars-nwe -rwxr-xr-x 1 root root 1171 Mar 7 2000 mcserv -rwxr-xr-x 1 root root 1340 Feb 28 2000 named -rwxr-xr-x 1 root root 3217 Sep 20 1999 netfs -rwxr-xr-x 1 root root 5094 Mar 7 2000 network -rwxr-xr-x 1 root root 2257 Feb 9 2000 nfs -rwxr-xr-x 1 root root 1722 Feb 9 2000 nfslock -rwxr-xr-x 1 root root 1603 Feb 29 2000 nscd -r-xr-xr-x 1 root root 4481 Mar 7 2000 pcmcia -rwxr-xr-x 1 root root 703 Mar 6 2000 phhttpd -rwxr-xr-x 1 root root 1086 Feb 7 2000 portmap lrwxrwxrwx 1 root root 30 Feb 8 10:36 postfix -> /var/local/postfix/bin/postfix -rwxr-xr-x 1 root root 2431 Feb 12 2000 postgresql -rwxr-xr-x 1 root root 1260 Mar 8 2000 pulse -rwxr-xr-x 1 root root 824 Mar 6 2000 pvmd -rwxr-xr-x 1 root root 955 Feb 24 2000 pxe -rwxr-xr-x 1 root root 1542 Feb 4 2000 random -rwxr-xr-x 1 root root 878 Jan 5 2000 reconfig -rwxr-xr-x 1 root root 1270 Feb 10 2000 routed -rwxr-xr-x 1 root root 780 Feb 9 2000 rstatd -rwxr-xr-x 1 root root 976 Feb 9 2000 rusersd -rwxr-xr-x 1 root root 941 Feb 11 2000 rwalld -rwxr-xr-x 1 root root 882 Feb 7 2000 rwhod -rwxr-xr-x 1 root root 1504 Feb 4 2000 single -rwxr-xr-x 1 root root 1177 Feb 25 2000 smb -rwxr-xr-x 1 root root 851 Feb 27 2000 snmpd -rwxr-xr-x 1 root root 2306 Feb 14 2000 squid -rwxr-xr-x 1 root root 726 Feb 8 10:35 sshd -rwxr-xr-x 1 root root 1024 Feb 3 2000 syslog -rwxr-xr-x 1 root root 1956 Mar 6 2000 xfs -rwxr-xr-x 1 root root 1212 Feb 18 2000 xntpd -rwxr-xr-x 1 root root 1712 Feb 5 2000 ypbind -rwxr-xr-x 1 root root 1084 Mar 6 2000 yppasswdd -rwxr-xr-x 1 root root 1137 Mar 6 2000 ypserv
start: start up services
stop: shut down services
restart: shut down and restart services
/etc/rc.d/init.d/network[couch@lin05 rc.d]$ ls -l */*network -rwxr-xr-x 1 root root 5094 Mar 7 2000 init.d/network lrwxrwxrwx 1 root root 17 Feb 8 10:17 rc0.d/K90network -> ../init.d/network lrwxrwxrwx 1 root root 17 Feb 8 10:17 rc1.d/K90network -> ../init.d/network lrwxrwxrwx 1 root root 17 Feb 8 10:17 rc2.d/S10network -> ../init.d/network lrwxrwxrwx 1 root root 17 Feb 8 10:17 rc3.d/S10network -> ../init.d/network lrwxrwxrwx 1 root root 17 Feb 8 10:17 rc4.d/S10network -> ../init.d/network lrwxrwxrwx 1 root root 17 Feb 8 10:17 rc5.d/S10network -> ../init.d/network lrwxrwxrwx 1 root root 17 Feb 8 10:17 rc6.d/K90network -> ../init.d/network
rc1.d/K90network)
rc3.d/S10network)
rc6.d/K90network)
contents of sh/network...
#! /bin/bash
#
# network Bring up/down networking
#
# chkconfig: 2345 10 90
# description: Activates/Deactivates all network interfaces configured to \
# start at boot time.
# probe: true
### BEGIN INIT INFO
# Provides: $network
### END INIT INFO
# Source function library.
. /etc/init.d/functions
if [ ! -f /etc/sysconfig/network ]; then
exit 0
fi
# Couch read in configuration parameters from file
# /etc/sysconfig/network by executing as shell script
. /etc/sysconfig/network
# Couch: Need configuration of pcmcia devices
# in case network card is add-on
if [ -f /etc/sysconfig/pcmcia ]; then
. /etc/sysconfig/pcmcia
fi
# Couch: make sure it's POSSIBLE to configure networking
# Check that networking is up.
[ "${NETWORKING}" = "no" ] && exit 0
# if the ip configuration utility isn't around we can't function.
[ -x /sbin/ip ] || exit 1
# Even if IPX is configured, without the utilities we can't do much
[ ! -x /sbin/ipx_internal_net -o ! -x /sbin/ipx_configure ] && IPX=
# Even if VLAN is configured, without the utility we can't do much
[ ! -x /sbin/vconfig ] && VLAN=
# If IPv6 is explicitly configured, make sure it's available.
if [ "$NETWORKING_IPV6" = "yes" ]; then
alias=`modprobe -c | awk '/^alias net-pf-10 / { print $3 }'`
if [ "$alias" != "ipv6" -a ! -f /proc/net/if_inet6 ]; then
echo "alias net-pf-10 ipv6" >> /etc/modules.conf
fi
fi
# Couch: read in all network functions so we can use them
CWD=`pwd`
cd /etc/sysconfig/network-scripts
. network-functions
# find all the interfaces besides loopback.
# ignore aliases, alternative configurations, and editor backup files
interfaces=`ls ifcfg* | LANG=C egrep -v '(ifcfg-lo|:|rpmsave|rpmorig|rpmnew)' | \
LANG=C egrep -v '(~|\.bak)$' | \
LANG=C egrep 'ifcfg-[A-Za-z0-9\._-]+$' | \
sed 's/^ifcfg-//g'`
# See how we were called.
case "$1" in
start)
# IPv6 hook (pre IPv4 start)
if [ "$NETWORKING_IPV6" = "yes" ]; then
if [ -x /etc/sysconfig/network-scripts/init.ipv6-global ]; then
/etc/sysconfig/network-scripts/init.ipv6-global start pre
fi
fi
action $"Setting network parameters: " sysctl -e -p /etc/sysctl.conf
# bring up loopback interface
action $"Bringing up loopback interface: " ./ifup ifcfg-lo
case "$IPX" in
yes|true)
/sbin/ipx_configure --auto_primary=$IPXAUTOPRIMARY \
--auto_interface=$IPXAUTOFRAME
if [ "$IPXINTERNALNETNUM" != "0" ]; then
/sbin/ipx_internal_net add $IPXINTERNALNETNUM $IPXINTERNALNODENUM
fi
;;
esac
case "$VLAN" in
yes)
if [ -d /proc/net/vlan ] || modprobe 8021q >/dev/null 2>&1 ; then
action $"Setting 802.1Q VLAN parameters: " /sbin/vconfig set_name_type DEV_PLUS_VID_NO_PAD
else
echo $"No 802.1Q VLAN support available in kernel."
fi
;;
esac
oldhotplug=`sysctl kernel.hotplug 2>/dev/null | \
awk '{ print $3 }' 2>/dev/null`
sysctl -w kernel.hotplug="/bin/true" > /dev/null 2>&1
cipeinterfaces=""
# Couch: now we actually bring up each interface.
# bring up all other interfaces configured to come up at boot time
for i in $interfaces; do
eval $(LANG=C fgrep "DEVICE=" ifcfg-$i)
if [ -z "$DEVICE" ] ; then DEVICE="$i"; fi
if [ "${DEVICE##cipcb}" != "$DEVICE" ] ; then
cipeinterfaces="$cipeinterfaces $DEVICE"
continue
fi
if LANG=C egrep -L "^ONBOOT=['\"]?[Nn][Oo]['\"]?" ifcfg-$i > /dev/null ; then
# this loads the module, to preserve ordering
is_available $i
continue
fi
# If we're in confirmation mode, get user confirmation
[ -n "$CONFIRM" ] &&
{
confirm $i
case $? in
0)
:
;;
2)
CONFIRM=
;;
*)
continue
;;
esac
}
action $"Bringing up interface $i: " ./ifup $i boot
done
# Bring up CIPE VPN interfaces
for i in $cipeinterfaces ; do
if ! LANG=C egrep -L "^ONBOOT=['\"]?[Nn][Oo]['\"]?" ifcfg-$i >/dev/null 2>&1 ; then
# If we're in confirmation mode, get user confirmation
[ -n "$CONFIRM" ] &&
{
confirm $i
case $? in
0)
:
;;
2)
CONFIRM=
;;
*)
continue
;;
esac
}
action $"Bringing up interface $i: " ./ifup $i boot
fi
done
sysctl -w kernel.hotplug=$oldhotplug > /dev/null 2>&1
# Couch: now set up routing tables; need interfaces up first
# Add non interface-specific static-routes.
if [ -f /etc/sysconfig/static-routes ]; then
grep "^any" /etc/sysconfig/static-routes | while read ignore args ; do
/sbin/route add -$args
done
fi
# IPv6 hook (post IPv4 start)
if [ "$NETWORKING_IPV6" = "yes" ]; then
if [ -x /etc/sysconfig/network-scripts/init.ipv6-global ]; then
/etc/sysconfig/network-scripts/init.ipv6-global start post
fi
fi
# Run this again to catch any interface-specific actions
sysctl -e -p /etc/sysctl.conf >/dev/null 2>&1
touch /var/lock/subsys/network
;;
# Couch: how to nuke the network:
stop)
# If this is a final shutdown/halt, check for network FS,
# and unmount them even if the user didn't turn on netfs
if [ "$RUNLEVEL" = "6" -o "$RUNLEVEL" = "0" -o "$RUNLEVEL" = "1" ]; then
NFSMTAB=`LC_ALL=C awk '!/^#/ && $3 == "nfs" { print $2 }' /proc/mounts`
SMBMTAB=`LC_ALL=C awk '!/^#/ && $3 == "smbfs" { print $2 }' /proc/mounts`
NCPMTAB=`LC_ALL=C awk '!/^#/ && $3 == "ncpfs" { print $2 }' /proc/mounts`
if [ -n "$NFSMTAB" -o -n "$SMBMTAB" -o -n "$NCPMTAB" ] ; then
/etc/init.d/netfs stop
fi
fi
# IPv6 hook (pre IPv4 stop)
if [ "$NETWORKING_IPV6" = "yes" ]; then
if [ -x /etc/sysconfig/network-scripts/init.ipv6-global ]; then
/etc/sysconfig/network-scripts/init.ipv6-global stop pre
fi
fi
# shut down all interfaces (other than loopback)
for i in $interfaces ; do
eval $(fgrep "DEVICE=" ifcfg-$i)
if [ -z "$DEVICE" ] ; then DEVICE="$i"; fi
if ! check_device_down $i; then
action $"Shutting down interface $i: " ./ifdown $i boot
fi
done
case "$IPX" in
yes|true)
if [ "$IPXINTERNALNETNUM" != "0" ]; then
/sbin/ipx_internal_net del
fi
;;
esac
action $"Shutting down loopback interface: " ./ifdown ifcfg-lo
if [ -d /proc/sys/net/ipv4 ]; then
if [ -f /proc/sys/net/ipv4/ip_forward ]; then
if [ `cat /proc/sys/net/ipv4/ip_forward` != 0 ]; then
action $"Disabling IPv4 packet forwarding: " sysctl -w net.ipv4.ip_forward=0
fi
fi
if [ -f /proc/sys/net/ipv4/ip_always_defrag ]; then
if [ `cat /proc/sys/net/ipv4/ip_always_defrag` != 0 ]; then
action $"Disabling IPv4 automatic defragmentation: " sysctl -w net.ipv4.ip_always_defrag=0
fi
fi
fi
# IPv6 hook (post IPv4 stop)
if [ "$NETWORKING_IPV6" = "yes" ]; then
if [ -x /etc/sysconfig/network-scripts/init.ipv6-global ]; then
/etc/sysconfig/network-scripts/init.ipv6-global stop post
fi
fi
rm -f /var/lock/subsys/network
;;
status)
echo $"Configured devices:"
echo lo $interfaces
echo $"Currently active devices:"
echo `/sbin/ip -o link show | awk -F ": " '/UP>/ { print $2 }'`
;;
restart|reload)
cd $CWD
$0 stop
$0 start
;;
*)
echo $"Usage: $0 {start|stop|restart|reload|status}"
exit 1
esac
exit 0
...end of sh/network
chkconfig: checks whether init scripts are used.
bash-2.05# chkconfig --list
syslog 0:off 1:off 2:on 3:on 4:on 5:on 6:off
netfs 0:off 1:off 2:off 3:on 4:on 5:on 6:off
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
random 0:off 1:off 2:on 3:on 4:on 5:on 6:off
rawdevices 0:off 1:off 2:off 3:on 4:on 5:on 6:off
iptables 0:off 1:off 2:on 3:on 4:on 5:on 6:off
crond 0:off 1:off 2:on 3:on 4:on 5:on 6:off
gpm 0:off 1:off 2:on 3:on 4:on 5:on 6:off
keytable 0:off 1:on 2:on 3:on 4:on 5:on 6:off
xfs 0:off 1:off 2:on 3:on 4:on 5:on 6:off
xinetd 0:off 1:off 2:off 3:on 4:on 5:on 6:off
httpd 0:off 1:off 2:off 3:on 4:on 5:on 6:off
named 0:off 1:off 2:off 3:on 4:on 5:on 6:off
kdcrotate 0:off 1:off 2:off 3:off 4:off 5:off 6:off
sendmail 0:off 1:off 2:on 3:on 4:on 5:on 6:off
innd 0:off 1:off 2:off 3:on 4:on 5:on 6:off
linuxconf 0:off 1:off 2:on 3:on 4:on 5:on 6:off
identd 0:off 1:off 2:off 3:on 4:on 5:on 6:off
portmap 0:off 1:off 2:off 3:on 4:on 5:on 6:off
squid 0:off 1:off 2:off 3:on 4:on 5:on 6:off
smb 0:off 1:off 2:off 3:on 4:on 5:on 6:off
sshd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
snmpd 0:off 1:off 2:off 3:on 4:on 5:on 6:off
xinetd based services:
chargen: off
chargen-udp: off
daytime: off
daytime-udp: off
echo: off
echo-udp: off
time: off
time-udp: off
imap: off
imaps: off
ipop2: off
ipop3: off
pop3s: off
linuxconf-web: off
rsync: off
telnet: off
wu-ftpd: off
chkconfig network on
chkconfig network off
for
case ... esac
if ... fi
do ... done
. file
VAR=value
export VAR
${foo}
${foo#bar}
${foo:-bar}
$(wc foo.c)
$[$foo+1]
/etc/rc.d structure
/etc/rc.sysinit does.
/etc/rc.d/rc does.
$runlevel
/etc/rc.d/rc$runlevel.d/K??*
/etc/rc.d/rc$runlevel.d/S??*
/etc/rc.d/rc3.d/S15bar start
/etc/rc.d/rc3.d/K15foo stop
lecture
in color