Вы находитесь на странице: 1из 27

Apache HTTP- ( /.p.i/, . a patchy server) .

Apache ,
Linux, BSD, Mac OS, Microsoft Windows, Novell NetWare, BeOS.
Apache .
,
,
. . IPv6.

2.1

2.2

2.3 (MPM)

2.4

2.5

3.1

3.2

3.3

3.4

3.5 Server Side Includes

4 .

1995 , a
patchy (. ),
NCSA HTTPd 1.3. , 2.
NCSA, . 2.2,
1.3 2.0 .
- Apache
Apache Software Foundation ,
Oracle IBM WebSphere.
1996 HTTP- .
[3]

Netcraft, 2007 51 % - , 2009

[4]

46 %. . Netcraft 2011 , 160


[5]

- Apache, 59 % -.

- , . .

Apache ,
, HTTP . ( )
Apache Software Foundation, .
, apache , .
, .
Apache C.


Apache .
:

(httpd.conf).

(httpd.conf c 2.2 extra/httpd-vhosts.conf).

(.htaccess).

, .
,
MPM. .

( /etc/passwd /etc/hosts).
, .

(MPM)
- Apache .
:

worker

Apache
Software
Foundation

OS

Linux, FreeBSD

-.
,

pre-fork

Apache
Software
Foundation

perchild

Apache
Software
Foundation

netware

Apache
Software
Foundation

winnt

Apache
Software
Foundation

ApacheITK

peruser

Steinar H.
Gunderson

Sean Gabriel
Heacock

MPM,

threads.

threads.

Linux

,

,

.

Novell NetWare


NetWare.

Novell
NetWare

Microsoft
Windows

Windows .
Microsoft
Server.
Windows.

Linux, FreeBSD

MPM,
prefork.

uid gid.

,
,

.

.

Linux, FreeBSD

,
MPM perchild.

uid gid.

.

,
,

threads.

Linux, FreeBSD


4 2007
,

10
2009
.


[6]

Apache HTTP Server . 500 ,


. Apache Software Foundation,
open source-.
, ,
, .
, :

-, ISPmanager VDSmanager
Apache.


Apache .
IP- ( ),
.
,
. MPM, Apache-ITK
httpd uid guid.
, ,
(CPU, RAM, ) .



, Apache
.
:

PHP (mod_php).

Python (mod python, mod wsgi).

Ruby (apache-ruby).

Perl (mod perl).

ASP (apache-asp).

[7]

, Apache CGI FastCGI,


, C, C++, sh, Java.


Apache .
:

HTTP-
(mod_auth_basic) digest- (mod_auth_digest).

, IP .

,
.

, PAM.

MPM- Apache
uid gid .
, suexec, CGI-
.
,
SSL, OpenSSL. X.509.
, mod_security.

2.0 .
, ,
SSI .
,
. Apache , Unicode,
, .


HTTP
, 404 (Not Found) 403 (Forbidden).
.

Server Side Includes


: Server Side Includes
1.3 Server Side Includes,
HTML- .
SSI mod_include, Apache.

10 Bash Shell Scripting



PATH - . PATH
MSDOS.
HOME - .
MAIL - .
IFS - , .
, , , .
:
$ echo $IFS | od -bc

PS1 PS2 - bash. PS1 $ PS2


'>'. , :
$ $ ls |

... .
USER - .
TERM - .
vi .
SHELL - , .
: ,
echo c $. :
$ echo $USER
ravi

... USER.

bash shell scripting


1)
#!/bin/bash

... #, !, .
.
2) , .
:
$ chmod ugo+x your_shell_script.sh

3) .sh. ,
.


'if'
:

if condition_is_true
then
execute commands
else
execute commands
fi

if . ,
.

if condition_is_true
then
execute commands
elif another_condition_is_true
then
execute commands
else
execute commands
fi

if grep "linuxhelp" thisfile.html


then
echo "Found the word in the file"
else
echo "Sorry no luck!"
fi

if - test , .
:


-eq

-le

- - - - - - True
.
-f file

True file

-r file

True file

-w file

True file

-x file

True file

-d file

True file

-s file

True


-n str

True, str null

-z str

True, str null

str1 == str2

True

str1 != str2

True

str

True, str
null

.
-a AND
-o OR

:
test $d -eq 25 ; echo $d

... , d 25, .
test $s -lt 50; do_something

if [ $d -eq 25 ]
then
echo $d
fi

, test -
.

if [ $str1 == $str2 ]
then
do something
fi
if [ -n "$str1" -a -n "$str2" ]
then
echo 'Both $str1 and $str2 are not null'
fi

... null echo. ,


test [],
test, [ ]. : test
. . .

case Case .
:

case expression in
pattern1) execute commands ;;
pattern2) execute commands ;;
...
esac

case esac. ';;' .


')', . :
...
echo "Enter your option : "
read i;
case $i in
1) ls -l ;;
2) ps -aux ;;
3) date ;;
4) who ;;
5) exit
esac

: ;; , , .
:
case `date |cut -d" " -f1` in
Mon) commands ;;
Tue) commands ;;
Wed) commands ;;
...
esac

Case .
wild-cards .
...
echo "Do you wish to continue? (y/n)"
read ans
case $ans in
Y|y) ;;
[Yy][Ee][Ss]) ;;
N|n) exit ;;
[Nn][Oo]) exit ;;
*) echo "Invalid command"
esac

, Yes, YES, yEs ,


.

while
:

while condition_is_true
do
execute commands
done

:
while [ $num -gt 100 ]
do
sleep 5
done
while :
do
execute some commands
done

. ' '
':'. looping .
. - . -

.
until
. :
until false
do
execute commands
done

:
...
until [ -r myfile ]
do
sleep 5
done

, myfile .
for
:
for variable in list
do
execute commands
done

:
...
for x in 1 2 3 4 5
do

echo "The value of x is $x";


done

1 5. :
for var in $PATH $MAIL $HOME
do
echo $var
done

, java .
, :
...
for file in *.java
do
javac $file
done

: wild-card .

w.r.t shell scripts


$* - ,
.. $ 1, $ 2
.
$0 - .
$# - , .
$? - .

, (positional parameters).
.
my_script.sh. :
$ ./my_script.sh linux is a robust OS

... , 5 . ,
: $ * - "linux ',' ',' ',' ',' OS".
$ 0 - my_script.sh - . $ # - $ $ - $ 1 - $ 2 - $* -
'linux','is','a','robust','OS'.
$0 - my_script.sh - .
$# - 5 - .br>
$$ - ID .
- , .

$1 - 'linux'
$2 - 'is'
... . set shift
set - .
, :

$ set `date`
$ echo $1
$ echo $*
$ echo $#
$ echo $2

shift :
$ set `date`
$ echo $1 $2 $3
$ shift
$ echo $1 $2 $3
$ shift
$ echo $1 $2 $3

ID , :
$ echo $$
2667

, , :
$ ps -f |grep bash

read
. read ,
. , . id
, .
:
#!/bin/sh
echo "Enter your name : "
read name
echo "Hello $name , Have a nice day."

shell script
shell, ASPLinux, , shell
script. , shell: Bourne shell shell,
, .
, C shell, C. ,
. Bourne shell
.
Linux shell script? ,
.
UNIX ,
.
. , ,
. - ,
, , . shell script

, , .
, (
shell script, Linux ,
.
shell script , .
, , .
shell ,
.
, Bourne shell, ..
ASPLinux.
:

, :

#! ///
, shell script , .
, .
Linux Bourn shell bash,
:

#! /bin/bash
, shell script,
. ,
, .
:

. program
, . ..
. ,
exit .
* /root/bin ,
shell script. ,
.

shell script, .
.
, .
. ,
.
shell script " " .
, . ,
.
* bash 2 local.
Bourne shell.

. ,
. .
sample01 .

1
2
3
4
5
6

#!/bin/bash
CAR="porshe the best"
echo "CAR:"
echo CAR
echo '$CAR: '
echo $CAR

1 , .
( ),
"" ( 2). ,
.

CAR="porsh the best"


, $ ( 6).

echo $CAR
3, CAR:
4, CAR
5 . shell script
, . . . $
$CAR:
shell script . Bourne
shell , 1024 . bash .
sample02 .

1 #!/bin/bash
2 #
3 #CAR[0]=porsh
4 #CAR[1]=bmw
5 #CAR[2]=mers
6 #CAR[3]=zaporozets
7 #CAR[10]=LADA
8 #CAR=([0]=porsh [1]=bmw [2]=mers [5]=zaporozets [10]=LADA)
9 CAR=(porsh bmw mers zaporozets LADA)
10 echo "*********************************"
11 echo "CAR[0]=${CAR[0]}"
12 echo "CAR[1]=${CAR[1]}"
13 echo "CAR[2]=${CAR[2]}"
14 echo "CAR[3]=${CAR[3]}"
15 echo "CAR[4]=${CAR[4]}"
16 echo "*********************************"
17 echo "ALL ${CAR[*]}"
18 echo "UHO ${CAR[@]}"
19 echo "*********************************"
bash .
.
( 3 7) .

.

CAR[1]=bmw
: 0 1 2 3 10.
, .
8.

CAR=([0]=porsh [1]=bmw [2]=mers [5]=zaporozets [10]=LADA)


,
.
( 9) ,
. , : ,
..

CAR=(porsh bmw mers zaporozets LADA)


:

${CAR[0]}
* . .

: 17 18, . ,
@, *.

${CAR[*]}
${CAR[@]}

, shell script, ,
, .
sample03 .

1
2
3
4
5
6
7

#!/bin/bash
#PATH=$PATH:~/bin; export PATH
#export PATH=$PATH:~/bin
echo "Workdir=$PWD"
echo " UID=$UID"
echo "Bash level= $SHLVL"
echo "Random=$RANDOM"

Bourne shell
, . export
( 2).

PATH=$PATH:~/bin
export PATH
bash ( 3).

export PATH=$PATH:~/bin
,
. .
env.
unset. :

unset CAR
shell . .
.

, shell script , ,
read.

read [ ...]
read,
. "Enter".
sample04 .

1
2
3
4
5
6

#!/bin/bash
#REPLY test
#echo "Write a car name and press \"Enter\" :"
echo -n 'Write a car name and press "Enter" :'
read
echo " $REPLY"

read .
echo. echo -n,
. 3 .
4- . ,
, ,
Enter.
5. read , , ,
REPLAY.
6- .
shell script ,
.
,

`date`
$

$(date)
, , ,
. , .. .
sample05 .

1 #!/bin/bash
2 #
3 echo "**************************************"
4 DATE=`date`
5 echo "DATE=$DATE"
6 echo "**************************************"
7 USERS=`who | wc -l`
8 echo "USERS v sisteme=$USERS"
9 echo "**************************************"
10 UP=`date; uptime`
11 echo "Sostavnie=$UP"
12 echo "**************************************"
13 exit 0
4 DATE , date . 5-
.
( 7). ,
wc .

10 . UP ,
date uptime .
, , . ,
,
.
"+", "-", "*", "/" .
"++" "--".
,
$.

$(( 2*2 ))
.
. ,
.
sample06 .

1
2
3
4
5

#!/bin/bash
#
PERM=2
echo "2*2=$(( 2*$PERM ))"
echo "((2*3+5)-4)/2=$(( ((2*3+5)-4)/2 ))"

PERM , , test, echo ( 4)


"0".
if .
0. ,
, .
, shell script . .
if fi.
, ,
then fi.
else, ,
.
sample07 .

1
2
3
4
5
6
7
8

#!/bin/bash
# if then else
if rm test 2> /dev/null
then
echo "Deleted"
else
echo "Not deleted"
fi

3 rm. ,
rm (rm test 2> /dev/null). test,
. - ,
. , ..
/dev/null.
0 5. 7.
if , ,
test. If test.
sample08 , ,
test ( 3).

1
2
3
4

#!/bin/bash
# if then else test
if [ -w $HOME/bin -a -w $HOME/bin/test ]
then

5
rm $HOME/bin/test
6
echo "test deleted"
7 else
8
echo "test not deleted"
9 fi
* "[" "]". .

test :

(AND) (OR)

1 - 2 , 1,
2.
1 - 2 , 1,
2.
! .
:

1
1
1
1
1
1

-eq
-ne
-gt
-ge
-lt
-le

2
2
2
2
2
2

,
,
,
,
,
,

"=".
"!=".
">".
">=".
"<".
"<=".

-n ,
-z ,
1 = 2

.

, 1 2.
.

-e
-f
-d
-L
-r
-w
-x
-s

///
///
///
///
///
///
///
///

,
,
,
,
,
,
,
,

.
.
.
.
.
.
.

shell script , "&&",


"||".
, , ,
. :

[ -f file ] && rm file

, . ,
, , .. rm.

[ -f file ] || touch file


file. ( ),
touch, . ,
. , (), touch
, . (),
touch.
case . ,
, ";;".
, esac.
case esac.
sample09 .

1 #!/bin/bash
2 # case esac
3 case $TERM in
4
*term)
5
echo "May be xterm?!"
6
;;
7
unknown|vt[0-9]*)
8
echo "May be vt100 ?"
9
;;
10
linux)
11
echo " This is a LINUX terminal!!!"
12
;;
13
*)
14
echo "I don't know this terminal :("
15 esac
16 exit 0
3 case , TERM.
4 "*term)".
, , . ,
term. , 5.
, .
7 "|".
, unknown vt .
, 8. , .
10 , linux. ,
11. , .
( 13),
"*", default .
sample10,
case .

1 #!/bin/bash
2 # case esac
3 echo -n "Please enter [Y|yes] : "
4 read YN
5 case $YN in
6
[yY]|[yY][eE][sS])
7
echo "You entered $YN"
8
;;
9
*)
10
echo "You did not enter [Y|yes]"
11 esac
12 exit 0

"Y" "yes" ( 3).


YN ( 4). case , .
, 6 .
, , 7. ,
( 9) ( 10).
for
, do done.
,
break.
sample11, for.

1
2
3
4
5
6
7

#!/bin/bash
# for
for I in 1 2 3 4 5 6 7 8 9 10
do
echo "--> $I <--"
done
exit 0

I "1 2 3 4 5 6 7 8 9 10".
10 .
.
, , Enter, "\"
. :

for I in list1 list2 list3 \


list5 list6
for .
, .
sample12.

1 #!/bin/bash
2 # for
3 # html
4 #for FILES in `ls ~/.bash_*`
5 for FILES in ~/.bash_*
6 do
7
echo "" > ${FILES}.html
8
echo "" >> ${FILES}.html
9
echo "
" >> ${FILES}.html
10
cat ${FILES} >> ${FILES}.html
11
echo "
" >> ${FILES}.html
12
chmod a+r ${FILES}.html
13 done
14 exit 0
5 "~/.bash_*". , FILES
, , ".bash_".
: .bash_profile, .bash_logout .bash_history. .. ,
FILES .
9- 11- , ".html".
.

".html".
shell script
. . sample13.
.
, ,
. , firewall IP

, . , ,
:

iptables -A FORWARD -s IP_ADDRESS -j ACCEPT


IP_ADDRESS IP , .
sample13-data:

1
2
3
4
5

192.168.0.1
192.168.0.2
#192.168.0.3
192.168.0.4 # not pay
192.168.0.5

( 3 4).
sample13 , :

1
2
3
4
5
6
7

#!/bin/bash
#
for I in `cat ./sample13-data`
do
echo "--> $I"
done
exit 0

for. ,
"cat ./sample13-data". IP ,
, .
,
. sample13-2:

1
2
3
4
5
6
7

#!/bin/bash
#
for I in `cat ./sample13-data | cut -f1 -d ' ' | sed -e '/#/ d'`
do
echo "--> $I"
done
exit 0

, , "#".
while , do done, ,
break.
while sample14:

1
2
3
4
5
6
7
8
9

#!/bin/bash
# Primer while
X=1
while [ $X -lt 10 ]
do
echo "--> $X <--"
X=$(( $X+1 ))
done
exit 0

"1" ( 3). 10.


, 6 7. 7- X 1 .
.
select ,
"Enter".
, do done.
, ( shell).
select:

1 #!/bin/bash

2 # select
3 select FILE in ~/.b* QUIT
4 do
5
if [ -e $FILE ]
6
then
7
ls -l $FILE
8
else
9
break
10
fi
11 done
12 exit 0
select . ,
, ".b" QUIT.
, "Enter". FILE
, , do done.
5 : " ?". .
, ls ( 7). ,
. ,
QUIT, break ( 9) select.
"." shell script, .
"." include .
shell script ,
.
"." ,
. , :

PARAM=value
PARAM2=value2
, ,
. .

. file
echo $PARAM
echo $PARAM2
sample16 ".".

1 #!/bin/bash
2 # "."
3 if [ ! -x $HOME/bin/sample16-2 ]; then
4
exit 1
5 fi
6 . $HOME/bin/sample16-2
7 select FILE in ~/.* QUIT
8 do
9
if [ -f $FILE ]
10
then
11
any
12
else
13
break
14
fi
15 done
16 exit 0

, sample15,
.
3 sample16-2, ,
6. , exit, 1,
, .
sample16-2 :

1
2
3
4
5
6
7

#!/bin/bash
#
# function
any()
{
ls -l $FILE
}

shell script : function


.
.
shell script ,
, shell script. ,
.
, .
- , ,
.
.
shell script . .
, .

$0
$0
$1
$2
$#
$*

$1 ... $9 .


..
, .
$@ .

"$*" "$@". ,
:

program -v -f "The file"


, for,
:

for I in $* # .
for I in $@ # .
for I in "$@" # .
, "$@",
.
.

$? .
$! PID , background .
$$ PID shell, shell script.
sample17:

1 #!/bin/bash

2 # Primer ispolzovanija $0
3 case $0 in
4
*listtar)
5
echo "List archive $1 ..."
6
TARGS="-tvf $1"
7
;;
8
*maketar)
9
echo "Create archive $1.tar ..."
10
TARGS="-cvf $1.tar $1"
11
;;
12
*) echo "Usage: listtar file | maketar dir"
13 exit 88
14 esac
15 tar $TARGS
16 exit 0
UNIX .
, ,
. . ,
. ( )
.
shell script , .
"$0". 3 case ,
. : listtar ( 4) maketar ( 8).
( "$0" ),
"*".
tar . , listtar,
. "$1". 5,
"List archive $1 ...", "$1" . 6
TARGS , tar.
15.
maketar, . .
$1. 9 .
10- , tar.
15- .
- , ( 12).
88 ( 13).
* .

, , : listtar maketar.
. sample17, .
bash shell script.
, "" .

${VAR#$PATTERN} .
${VAR##$PATTERN} ,
.
${VAR%$PATTERN} .
${VAR%%$PATTERN} ,
.
, , sample18.

1 #!/bin/bash
2 VAR=abcd12345abc6789
3 PATTERN=a*c
4 echo "*****************************************"
5 echo "VAR = $VAR"; echo "PATTERN = $PATTERN"
6 echo '${VAR#$PATTERN} =' "${VAR#$PATTERN}"
7 echo '${VAR##$PATTERN} =' "${VAR##$PATTERN}"
8 echo "*****************************************"
9 PATTERN2=b*9
10 echo "VAR = $VAR"; echo "PATTERN2 = $PATTERN2"
11 echo '${VAR%$PATTERN2} =' "${VAR%$PATTERN2}"
12 echo '${VAR%%$PATTERN2} =' "${VAR%%$PATTERN2}"
13 echo "*****************************************"
VAR ,
. PATTERN ( 3).
6 "${VAR#$PATTERN}". "abcd12345abc6789"
, "a" "" (
). : "d12345abc6789".
7 "${VAR##$PATTERN}". ,
, , ""
"". : "6789".
9 "b*9".
11 "${VAR%$PATTERN}".
, "9" "b".
, . : "abcd12345a".
12 "${VAR%%$PATTERN}".
, , "9" "b".
: "".
sample19:

1 #!/bin/bash
2 ARGS=2
3 if [ $# -ne $ARGS ]; then
4
echo "Usage: `basename $0` old_suffix new_suffix"
5
exit 65
6 fi
7 for FILENAME in *.$1
8 do
9
echo " $FILENAME ${FILENAME%$1}$2 ..."
10
mv $FILENAME ${FILENAME%$1}$2
11 done
12 exit 0
.
:
. 3 .
2, ( 4) 65 ( 5).
, for,
, ,
$1 ( 7).
"${FILENAME%$1}$2" . ,

bin.tar, newtar. ,
:

bin.tarnewtar

getopts shell , , .
, POSIX, . "-v -t -f file" ..
":" , .
sample20.

1 #!/bin/bash
2 while getopts f:o:v OPTION
3 do
4 case $OPTION in
5
f) echo "Option f argument $OPTARG" ;;
6
o) echo "Option o argument $OPTARG" ;;
7
v) echo "Option v no argument" ;;
8
\?) echo "Usage: `basename $0` -f infile [-o outfile] [-v]"
9 esac
10 done
11 exit 0
getopts while. ,
, OPTION .
while, getopts.
, . ,
while.
, getopts
OPTARG.
getopts :

, stderr,
OPTION "?".
trap .
, .
. , .
trap sample21:

1 #!/bin/bash
2 trap clean 1
3 clean() {
4
X=1
5
echo "Start clean :"
6
while [ $X -lt 10 ]
7
do

8
9
10
11
12
13
14
15
16
17
18
19

echo -n ".."
sleep 2
X=$(( $X+1 ))
done
echo "Done"
exit 0
}
while [ 0 ]
do
:
done
exit 0

2 trap, , 1

clean.
while ( 15-18),
. . while do done

-
,

":".
clean "Start clean :", ( sleep,
9) "..". exit ( 13),
.

Вам также может понравиться