Menu
Home
News
Forums
My Account

Login
Login:

Password:

Register, it's free!
Lost your password?

Users Online
There are:
0 registered users
and 1 guests online now.

Testing Center
Windows 2000 MCSE
Linux RedHat

Information Center
FREE MCSE ONLINE QUIZZES (Updates 09/10/07)
Create A Web Form Online
Windows NT 4.0 MCSE
Windows 2000 MCSE
Linux Redhat Corner
TCP/IP Calculator
TCP/IP History
TCP/IP NT 4
W2K Server Commands
A+ CompTIA
My Resume
Links

Redhat Corner
  The Korn Shell Tutorial
 
Korn Shell was created by David Korn  

This article was created to be used as a reference page for writing scripts using Korn scripting or for the beginner just starting to write Korn scripts.

Invoking the Korn shell type:
/bin/ksh

Bold text
is the command input, red text is the output and orange text are links.
 

Section I - [ Process Execution, Input/Output Redirection, File Name Substitution, & Command Substitution]

  [[ .. ]]   String Operators





[[ $X == $Y ]]

[ .. ]

-n string
-o string
-z string
string1 = string2
string1 != string2
string1 = pattern
string != pattern
string1 < string2
string1 > string2

 
remember the white space between [[ ]] and the operators

may be used, but limited

true if length of string is not zero
true if option is set
true if length of string is zero
true if string1 is equal to string2
true if string1 is not equal to string2
true if string does match pattern
true if string does not match pattern
true if string1 is less than string2
true if string1 is greater than string2

  examples using string operators from startup scripts for httpd, sendmail & network





# if variable $DEVICE is zero then run DEVICE=$i
if [ -z "$DEVICE" ] ; then DEVICE="$i"; 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
fi
done


  [[ .. ]] File Operators





[[ $X == $Y ]]

-a file
-d file
-f file
-G file
-L file
-O file
-r file
-s file
-S file
-u file
-w file
-x file
file1 -ef file2
file1 -nt file2
file1 -ot file2


remember the white space between [[ ]] and the operators

true if file exists
true if file exists and is a directory
true if file exists and is a regular file
if file exists and = to current group id
true if file exists and is a symbolic link
if file exists and = to effective user id
true if file exists and is readable
true if file exists and its size is greater than zero
true if file exists and is a socket file
true if file exists and its set user-id bit is set
true if file exists and is writable
true if file exists and is executable.
true if file1 exists and is another name for file2
true if file1 exists and is newer than file2
true if file1 exists and is older than file2


  examples of using file operators from startup scripts for httpd, sendmail, & network





# if httpd.pid exists as a regular file then function stop start is executed.
if [ -f /var/run/httpd.pid ] ; then
stop
start
fi

# if ipv4 is a directory run commands
if [ -d /proc/sys/net/ipv4 ];
then commands
fi

# if the ip configuration utility isn't around we can't function.
[ -x /sbin/ip ] || exit 1

 


  More examples of [[ .. ]] with operators && ||





[[ expression1 && expression2 ]] (true if expression1 and expression2 are true.)
[[ -a tmp ]] && echo "File tmp exists"
[[ -d /tmp ]] && echo "/tmp is a directory"
[[ -r tmp ]] && echo "File tmp is read-only"
[[ -r tmp && -d tmp ]] && "tmp is read-only and a directory

[[ expression1 || expression2 ]] (true if either expression1 or expression2 are true.)

[[ -a tmp ]] || echo "File tmp does not"
[[ -d /tmp ]] || echo "/tmp is not a directory"
[[ -r tmp ]] || echo "File tmp is not read-only"
[[ -r tmp || -w tmp ]] && echo "tmp is either a read-only file or writable.

[[ (expression) ]] true if expression eveluates to true. The ()'s are used to override the precedence rules.

[[ !expression ]] true if expression evaluates to false.

 


  [[ .. ]]   Integer Operators





exp1 -eq exp2
exp1 -ne exp2
exp1 -le exp2
exp1 -lt exp2
exp1 -ge exp2
exp1 -gt exp2


 
true if exp1 is equal to exp2
true if exp1 is not equal to exp2
true if exp1 is less than or equal to exp2
true if exp1 is less than exp2
true if exp1 is greater than or equal to exp2
true if exp1 is greater than exp2

  Examples using Integer Operators





# if users logged in are less then 1 print true
(($(who | wc -l) > 1))
echo $?
0 (true more then one user logged in)

# less then 2 arguments
(($# < 2))

# less then 4 users logged in
[[ $(who | wc -l) -lt 4 ]] && echo less then 4 users logged in

# more then 4 users logged in

[[ $(who | wc -l) -gt 4 ]] && echo more then 4 users logged in

 


  command execution format





command; command2 - runs command1 followed by command2

command & - execute command in background

command1|command2 - pass standard output of command1 to standard input of command2

command1 && command2 - execute command2 if command1 returns zero (successful)

command1 || command2 - execute command2 if command1 returns non-zero (unsuccessful)

command |& - execute command asynchronously with its standard input and standard output

command \ - continue command on next line

{ command; } - execute command in current shell - remember spaces!
(command) - execute command in its own shell - no spaces required


  command execution examples files in directory are "one two three"





1) ls; echo "files"

2) ls &

3) ls | wc -l
4) ls && echo true

5) ls || echo false
6) echo \abc
7) { date; }
8) (date)

1) one two three
files

2) [1] 6034
one three two
3) 14
4) one three two
true

5) one three two
6) abc
7) Sat Jul 13 20:11:07 PDT 2002
8) Sat Jul 13 20:11:27 PDT 2002




  Quotes ' .. ' " .. " ` .. `





' .. '
` .. `
" .. "


hide meanings of all special characters except another '
back quotes are used to assign variables from output
double quotes hide all meanings except special characters like $, ', and \


  Examples using Quotes  





echo 'date'
echo 'the 'date' today is'
echo "the 'weather' is rain"
echo "my prompt is $PS1"


REDHAT='uname`

echo $REDHAT


date
the 'date' today is
the 'weather' is rain
my prompt is [\u@\h \W]\$

Linux


  Some I/O Redirection Operators





<file
>file
>>file
>|file
<>file
<&-
>&-



redirect standard input from file
redirect standard output to file
append out to file
redirect standard output to file
open file for reading and writing as standard input
close standard input
close standard output

  Examples using Redirectors  





1) # cat <hello.world - hello world

2) # hello.world> - hello.world (created)

3) # cat hello.world >> hello.world - hello.world hello.world

4) # echo "hello world" >&- - (nothing will be displayed)

5) # cat hello.world | wc -l <&- - (input will not be displayed)

 


  File Descriptors  





0
1
2
3-9


standard input
standard ouput
standard error
unassigned file descriptors



  Redirect Operators / File Descriptors
 
<&n
>&n
n<file
n>file
n>>file
n>|file
n<&m
n>&m
n<>file
n<<word
n<<-word

 
redirect std.inp from file desc. n
redirect std.out to file desc. n
redirect file desc. n from file
redirect file desc. n to file
redirect file desc. n to file
redirect file desc. n to file
redirect file desc. n input from file desc.
redirect file desc. n output to file desc.
open file for reading and writing as file desc. n
redirect to file desc. n until word is read
redirect to file desc. n until word is read




 

  Examples using File Descriptors





1) #echo This output is going to standard error >&2 - This output is going to standard error

2) #ls hello world .out 2>ls.out 1>&2 cat ls.out - ls: hello: No such file or directory
ls: world.out: No such file or directory


3) #cat hello.world >/dev/null - all output is sent to "/dev/null" which is a trash bin.

4) #cat hello.world >&- - all output is closed with &-

5) #cat hello.world 1>/dev/null - contents of hello.world if exist will be sent to /dev/null

6) #cat hello.world 2>/dev/null - any errors from running 'cat hello.world' are sent to /dev/null


  Basic Pattern-Matching Characters
 
?
*
[xyz]
[a-c]
[a-ce-g]
[!abc]
[!a-c]
.
 
match any single character
match zero or more characters
match any character or characters between brackets
match any character or characters in the range a to c
match any character or characters in the range a to c, to g
match any characters or characters not between brackets
match any character or characters not in the range of a-c
strings starting with . must be explicitly matched





 


  Examples using Pattern Matching   using the file "a"
 
ls ?a
ls a*
ls [abc]
ls [a-c]
ls [a-ce-g]
ls [!z]
ls [!s-z]
ls [.a]

 
a
a
a
a
a
a
a
a




 


  Advanced Pattern Matching    
 
?(pattern)
*(pattern)
+(pattern)
@(pattern)
!(pattern)
pattern
 
match zero or one occurrences of any pattern
match zero or more occurrences of any pattern
match on or more occurrences of any pattern
match exactly one occurrence of any pattern
match anything except any pattern
multiple patterns must be separate





 

  Examples using Adv. Pattern Matching   using files a aa aaa
 
ls ?(a)
ls *(a)
ls +(a)
ls @(a)
ls !(z)
ls (a|j|[1-3])
ls !(z|[1-3]|z)

 
a
a aa aaa
a aa aaa
a
a aa aaa
a aa aaa
a aa aaa




 



Section II - [ Variable Attributes, Special Parameters, Variable Expansion, Array Variables ]

  Variable Attributes with using typeset
 
typeset -i var - Set var to be a integer
typset -l var
- Set var to lower case
typeset -L var
- Left justify var
typeset -Ln var
- Left justify var, set field width to n
typeset -r var
- Set var to read-only
typeset -R var
- Right justify var
typeset -Rn var
- Right justify var, set field width to n
typeset -RZn var
- Right justify var, set field width t on and fill as leading 0s
typeset -t var
- Set the user-defined attribute forvar.
typeset -u var
- Set var to upper case
typeset -x var
- Automatically export var to environment







  Special Parameters
 
? - exit status of last command
$ - process id of current shell
- - current options in effect
! - process id of last background process
ERRNO - error number returned by most recently failed sys call
PPID - process id of the parent shell
~ - home directory of current user






  Examples of Special Parameters
 
1) echo $?
2) echo $$
3) echo $-
4) echo $PPID
 
1) 0
2) 5459
3) ims
4) 5336





 


  Variable Expansion Formats
 
1) ${#variable} - length of variable
2) ${variable:-word} - value of variable if set and not null, else print word
3) ${variable:=word} - value of variable if set and not null, else set
4) ${variable:+word} - value of word is variable is set and not null, else nothing

5) ${variable:?} - value of variable if set and not null else print 'not set'
6) ${variable:?word} - value of variable if set and not null, else print value of word

7) ${variable#pattern} - value of variable without the smallest beginning portion
that matches pattern

8) ${variable##pattern} - value of variable without the largest beginning portion
that matches pattern

9) ${variable%pattern} - value of variable without the smallest ending portion
that matches pattern

10) ${variable%%pattern} - value of variable without the largest ending portion
that matches pattern

11) ${variable||pattern1|pattern2} - replace all occurrences of pattern1 with pattern2 variable






  Examples of Variable Expansion   using variable PS1=# USERNAME=root
 
1) echo ${#PS1}
2) echo ${PS5:-NEW}
3) echo ${PS5:=NEW}
4) echo ${PS6:?}
5) echo ${PS5:?PS1}
6) echo ${USERNAME#r}
7) echo ${USERNAME##t}
8) echo ${USERNAME%t}
 
1) 2
2) NEW
3) variable for PS5 is now NEW
4) /bin/ksh: PS6: parameter null or not set
5) /bin/ksh: PS7: PS1
6) oot
7) root
8) roo





 


  Array Variables    
 
${array}
${array[n]}
${array[n+1]}
${array[$z]}
${array[*]}
${#array[*]}
${#array[n]}
${!array[*]}
${!array[*]:n:x}
${!array[@]:n}
 
$array element zero
array element n
array element n + 2
array element $z
all elements of array
number of array elements
length of array element n
all initialized subscript values
x array elements starting with element n
all array elements starting with element n





 

  Assigning Variables to Arrays    
 
set -A DAY Mon Tues Wed

typeset DAY[0]=Mon DAY[1]=Tues DAY[3]=Wed

 
will assign Mon, Tues, and Wed to DAY array

will also assign Mon, Tues, and Wed to DAY array




 

  Examples of arrays   using the above sample
 
echo $DAY
echo ${DAY[1]}
echo ${DAY[*]}
echo ${DAY[0+1]}
echo ${#DAY[1]}
echo ${#DAY[*]}
 
Mon
Tues
Mon Tues Wed
Tues
4
3





 




Section III - [ Manipulating Jobs, Checking Job Status, Background Jobs and I/O, Job Names, Leaving Stopped Jobs ]

  Job Commands    
 
Ctlr-z
fg
fg %n
bg
bg %n
jobs
jobs -l
sleep 100
wait
kill -l
kill -signal %n
kill %n
stty tostop
stty -tostop

 
suspend current job
bring background job into the foreground
bring background job n into the foreground
send job into the background
send job n into the background
display current jobs and status
display current jobs and process ids
put into background for 100 seconds
wait for the job to finish
list all valid signal names
send specified signal to job n
kill job n
prevent background jobs from generating output
allow background jobs to generate output





 

  Job names    
 
%n
%+, %%
%-
%string
%?string
 
job n
current job
previous job
job whose name begins with string
job that matches part or all of string





 



Section IV - [ Working with Arithmetic Operators ]


  Arithmetic Operators anything between (( .. )) ( ... ) grouping (used to override precedence rules)





-
!
~
*, /, %
+, -
<<,>>
<=,<
>=,>
==
!=
&
^
|
&&
||
=
*=, /=, %=
<<=, >>=
&=, ^=, |=
( ... )




unary minus
logical negation
bitwise negation
multiply, division, remainder
addition, subtraction
left shift, right shift
less than or equal to, less than
greater than or equal to, greater than
equal to
not equal to
bitwise AND
bitwise exclusive OR
bitwise OR
logical AND
logical OR
assignment
multiply assign, divide assign
left shift assign, right shift assign
bitwise AND assign, bitwise exclusive OR assign, bitwise OR assign
grouping (used to override precedence rules)


  Examples of Arithmetic  





((X=-1))
echo $7


((Z=1+1))
echo $Z

((Y=1-1))
echo $Y

((X=$Y-$Z))
echo $X


((X=!Y))
echo $X

four=$((2 + 2))
echo $four
eight=$(($four + 4))
print $(($four * $eight))


-1


2


0


2


1


four

eight
32



Section V - [ case, select, function, while, until, if, do, read, continue, echo, print ]

  case function linux-mag  





#!/bin/ksh

case $1 in

1) echo one
;;
2) echo two
;;
3) echo three
;;
*) echo does not exists

esac




./hello.case 1
one
./hello.case 2
two
./hello.case 3
three
./hello.case 777
does not exist



  select function  





#!/bin/ksh

OPTIONS="Monday Tuesday Wednesday Thursday Friday"

select opt in $OPTIONS; do

if [ "$opt" = "Monday" ]; then
echo Monday
i

elif [ "$opt" = Tuesday" ]; then
echo Tuesday

exit

else

clear echo bad option
fi

done


./hello.select


1) Monday
2) Tuesday
3) Wednesday
4) Thursday
5) Friday
#?
1
monday
#?


  function a function will be passive until called from a scripts





functionname()
{
commands
}

or

function name()
{
commands
}

 


example from httpd startup

example from sendmail startup

if [ "1" != "2" ] ;
then
functionone
fi

functionone() {
echo this is function one
}

functionone

 


  if function linux-mag execute commands if a given condition is true





if command1
then command2
fi

file and string ops


if [[ "X" = "Y" ]]; then
echo X = Y
fi


  else function used with if usually when if a set of commands is not true





if command1
then
comamnds
else
commands
then
fi









file and string ops


if [[ "X" = "Y" ]]; then
echo X = Y
else
echo X does not equal Y
fi

if [ $? -eq 127 ] ; then
print error
else print everything ok
fi

grep ipx | lsmod
if [[ $? -eq 0 ]] ; then
echo YES
else
echo NO
fi



  elif function execute a set of commands that are true




if commands
then
commands
elif command
then
command
fi
if [ -d /deva ]; then
echo deva is a directory
elif [ -d /dev ]; then
echo dev is a directory not deva
fi

  while function linux-mag looping syntax




while command1
do command
done
while (($# != 0 ))
do
echo test
done

  until function linux-mag similar to while except executes when condition is false




until command1
do command
done
until (($# == 0))
do
echo true
done

  for function linux-mag execute commands a specified number of times





for i in $(ls);
do
echo files: $i
done


files: a
files: b
files: c


  echo function displays its arguments on standard output




-n
-e

-E
don't output trailing line
enable interpretation of the backslash-escaped characters listed below
disable interpretation of those sequences in STRINGs


  exec function used to perform I/O redirection with file descriptors 0-9





exec 1>std.out
exit

all standard output is no going to file std.out
will allow you to exit the shell and view the output of std.out

  read function input from read is assigned to variable




read age when age is entered its assigned to $age


Section VI - [ find, awk, grep, sed ]

  find function [path...] [expression] - used to locate files - man page linuxpowered.com




-amin n - find / -amin 10 (access all files in / that have been accessed 10 minutes ago)
-anewer file - find / -anewer file2 (access all files in / that are newer then file2)
-atime n - find / -atime 10 (access all files in / that have been accessed 10 days ago)
-cmin - find / -cmin 10 (access all files in / that have been changed 10 days ago)
-name find / -name *test (access all files in / that have the name *test)

find / -atime +7 -exec rm {} \; (locate and remove all files that match)



  grep function [ -bchilnsvw ] limited-regular-expression [ filename... ] search a file for a pattern - man page




grep ls * - search all files in current directory for "ls"
grep failure maillog - search maillog for the word "failure"
grep failure maillog > failed - search maillog for the word "failure" and write to file "failed'



  awk function [ -f progfile ] [ -Fc ] [ `prog' ] [ parameters ] [ filename...] pattern scanning and processing language - man page




awk -F: '{print $1, $2}' /etc/passwd

will print out column 1 and 2 separated by : in /etc/passwd.



  sed function [ -n ] script [ file ... ] /usr/bin/sed [ -n ] [ -e script ] ... [ -f script_file ] ... [ file ... ] - steam editor - man page




sed 's/bash/ksh/' > file.out
sed 's/tmp\/backup/usr\/local\/backup/' backup_now > backup_now.2

search for all instances of bash and replace with ksh and write to file.out
use \ for literal meanings.

  Commands often used when writing scripts




at Execute a command at a specified time
cat Display contents of a file
chmod Change file permissions
comm Compare files
cp Copy files
df Display disk space usage of filesystems
diff Compare text files
du Displays disk space usage of directories
echo Display text
eval Evaluate an expression
grep Find strings
kill Terminate a process
lpr Print data
less Page through a file
ls List file information
mail Send a mail message
mkdir Create a directory
mv Move a file or directory
nice Set process priority
nohup Run a command immune to hang-ups
od Display file contents in octal and other formats
passwd Set a user's password
pr Format data for printing
ps Display process information
rm Remove a file
rmdir Remove a directory
sh Launch a shell
sleep Pause a process
sort Sort data
spell Check spelling
tail Display last lines of file
time Time the execution of a script
times Displays CPU time used
uniq Eliminates duplicate data
w Displays logged in users
wait Waits for child processes to terminate
wc Counts characters, words, and lines
who Displays logged in users



Section VII [ default redhat 7.2 startup scripts httpd, sendmail, and network ]



  /etc/rc.d/init.d/httpd  





#!/bin/bash
#
# Startup script for the Apache Web Server
#
# chkconfig: - 85 15
# description: Apache is a World Wide Web server. It is used to serve \
# HTML files and CGI.
# processname: httpd
# pidfile: /var/run/httpd.pid
# config: /etc/httpd/conf/access.conf
# config: /etc/httpd/conf/httpd.conf
# config: /etc/httpd/conf/srm.conf

# Source function library.
. /etc/rc.d/init.d/functions

# This will prevent initlog from swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS=""

# Path to the apachectl script, server binary, and short-form for messages.
apachectl=/www/bin/apachectl
httpd=/www/bin/httpd
prog=httpd
RETVAL=0

# Find the installed modules and convert their names into arguments httpd
# can use.
moduleargs() {
moduledir=/usr/lib/apache
moduleargs=`
/usr/bin/find ${moduledir} -type f -perm -0100 -name "*.so" | env -i tr '[:lower:]' '[:upper:]' | awk '{\
gsub(/.*\//,"");\
gsub(/^MOD_/,"");\
gsub(/^LIB/,"");\
gsub(/\.SO$/,"");\
print "-DHAVE_" $0}'`
echo ${moduleargs}
}

# The semantics of these two functions differ from the way apachectl does
# things -- attempting to start while running is a failure, and shutdown
# when not running is also a failure. So we just do it the way init scripts
# are expected to behave here.
start() {
echo -n $"Starting $prog: "
daemon $httpd -DSSL `moduleargs` $OPTIONS
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/httpd
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc $httpd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/httpd /var/run/httpd.pid
}
reload() {
echo -n $"Reloading $prog: "
killproc $httpd -HUP
RETVAL=$?
echo
}

# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status $httpd
RETVAL=$?
;;
restart)
stop
start
;;
condrestart)
if [ -f /var/run/httpd.pid ] ; then
stop
start
fi
;;
reload)
reload
;;
graceful|help|configtest)
$apachectl $@
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"
exit 1
esac

exit $RETVAL





  /etc/rc.d/init.d/sendmail  





#!/bin/bash
#
# sendmail This shell script takes care of starting and stopping
# sendmail.
#
# chkconfig: 2345 80 30
# description: Sendmail is a Mail Transport Agent, which is the program \
# that moves mail from one machine to another.
# processname: sendmail
# config: /etc/sendmail.cf
# pidfile: /var/run/sendmail.pid

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Source sendmail configureation.
if [ -f /etc/sysconfig/sendmail ] ; then
. /etc/sysconfig/sendmail
else
DAEMON=no
QUEUE=1h
fi

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

[ -f /usr/sbin/sendmail ] || exit 0

RETVAL=0
prog="sendmail"

start() {
# Start daemons.

echo -n $"Starting $prog: "
/usr/bin/newaliases > /dev/null 2>&1
if test -x /usr/bin/make -a -f /etc/mail/Makefile ; then
make -C /etc/mail -s
else
for i in virtusertable access domaintable mailertable ; do
if [ -f /etc/mail/$i ] ; then
makemap hash /etc/mail/$i < /etc/mail/$i
fi
done
fi
daemon /usr/sbin/sendmail $([ "$DAEMON" = yes ] && echo -bd) \
$([ -n "$QUEUE" ] && echo -q$QUEUE)
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/sendmail
return $RETVAL
}

stop() {
# Stop daemons.
echo -n $"Shutting down $prog: "
killproc sendmail
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/sendmail
return $RETVAL
}

# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
stop
start
RETVAL=$?
;;
condrestart)
if [ -f /var/lock/subsys/sendmail ]; then
stop
start
RETVAL=$?
fi
;;
status)
status sendmail
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart|condrestart|status}"
exit 1
esac

exit $RETVAL





  /etc/rc.d/init.d/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

. /etc/sysconfig/network

if [ -f /etc/sysconfig/pcmcia ]; then
. /etc/sysconfig/pcmcia
fi


# 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=

# 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

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

oldhotplug=`sysctl kernel.hotplug 2>/dev/null | \
awk '{ print $3 }' 2>/dev/null`
sysctl -w kernel.hotplug="/bin/true" > /dev/null 2>&1

cipeinterfaces=""

# bring up all other interfaces configured to come up at boot time
for i in $interfaces; do
eval $(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

# 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
;;
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=`grep -v '^#' /proc/mounts | awk '{ if ($3 ~ /^nfs$/ ) print $2}'`
SMBMTAB=`grep -v '^#' /proc/mounts | awk '{ if ($3 ~ /^smbfs$/ ) print $2}'`
NCPMTAB=`grep -v '^#' /proc/mounts | awk '{ if ($3 ~ /^ncpfs$/ ) print $2}'`
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 ": " '{ print $2 }'`
;;
restart|reload)
cd $CWD
$0 stop
$0 start
;;
*)
echo $"Usage: $0 {start|stop|restart|reload|status}"
exit 1
esac

exit 0





  Links for Korn  




Korn Shell (ksh) Programming
Korn Shell 93 User Manual
http://www.bolthole.com/solaris/ksh.html
http://dfrench.tripod.com/kshman93.html

 
   
   

Google Content

Google Content

Get Firefox!