You are on page 1of 9

www.

askj
j
.
com.
cn

She
l
l

Hello

Shell

Shell
Shell
Shell
Shell vmstat Oracle

1.1

Linux UNIX Shell


Linux UNIX
100

Shell .
Shell Linux UNIX

.
Linux Linux
UNIX .

1.2
1.2.1

Shell
Shell

Shell
Shell
CPU

""
Shell.
Shell Linux
/bin
Shell df /bin df Shell.
[root@OracleJJ shell]# df
Filesystem
1K-

%
/dev/mapper/VolGroup00-LogVol00
36253304 6905692 27506052 21% /
/dev/hdc1
101086
9091
86776 10% /boot
none
322836
0
322836
0% /dev/shm
/dev/hda10
4248876 3150864
1098012 75% /home/o10g
Shell

Shell

www.askjj.com.cn

Shell DOS COMMAND.COM

1.2.2

Shell

Shell
Shell Shell .
Shell Shell Shell Shell .

1.3

Shell

Shell
1
Shell

Shell Shell

2
Shell Linux Shell
/etc/profile Shell .
Shell Shell

1.4

Shell

"Hello world"
Hello world Hello world
( vi ):
-------hw--------1 #!/bin/bash
2 # Hello world
3 echo Hello world
4 exit 0
------------------------------ chmod x
:
[root@OracleJJ shell]# chmod +x hw
:
[root@OracleJJ shell]# ./hw
Hello world
-2-

Shell

www.askjj.com.cn

Hello world echo


1 #!/bin/bash , Shell bash shell
bin bash bin :
[root@OracleJJ shell]# ls -lF /bin/bash
-rwxr-xr-x 1 root root 616312 2004-12-07

/bin/bash*

/bin bash

#!/bin/bash bash cat


#!/bin/cat
# Hello world
echo Hello world
exit 0

[root@OracleJJ shell]# ./hw.bas


#!/bin/cat
# Hello world
echo Hello world
exit 0
cat .

#!/bin/

#!/bin/bash ksh
Shell
#!/bin/bash
Shell Shell
Shell : #!/bin/ksh
Shell KSH
Shell

2 #
#!/bin/bash

3 echo echo
4 exit 0 Shell 0 Linux
0 0 .
1.1 3 ,
echo Hello world
Shell Linux bash
Shell : 0
-3-

Shell

1.5

www.askjj.com.cn

Shell

Shell Oracle
Shell
shell

CPU Oracle vmstat


vmstat Linux :
[root@OracleJJ shell]# vmstat 3 2
procs -----------memory------- -------swap------- -----io---- ------system------ --------------cpu------------r b
swpd
free
buff
cache
si
so
bi bo
in
cs us sy id wa
1 0
0
581168 12144
30236
0
0
4
2
1006
34 1 0 98 0
0 0
0
581168 12144
30236
0
0
0 1
1001
24 3 0 97 0
3 2

r CPU .
b I/O
swpd KB
free KB
buff Buffer KB
cache Cache KB
siKB/s
soKB/s
bi/s
bo/s
in
cs
us CPU
sy CPU
id CPU
wa I/O CPU
vmstat
Oracle vmstat my_os_stat
create table scott.my_os_stat (stat_date dater numberb number
swpd numberfree number
buff numbercache number,
si numberso numberbi numberbo number,
myin numbercs numberus number,
sy numberid numberwa number);
scott vmstat

-4-

Shell
1
2
3
4
5
6
7
8
9

www.askjj.com.cn

vmstat 3 2|sed 1,3d|tr -s " "|{


read a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16;
sqlplus scott/password <<EOF
insert into my_os_stat values(sysdate,$a1,$a2,$a3,$a4,$a5,$a6,$a7,$a8,$a9,
$a10,$a11,$a12,$a13,$a14,$a15,$a16);
commit;
exit
EOF
}

EOF

vmstat 3 2 "|""" vmstat


""
sed 1,3d vmstat 1 3 d 1,3 1
3 vmstat :
0

0 581168

12144 30236

1 1001

24 3 0 97

: vmstat 5 2|sed 1,3d .


tr -s " " 1
:
[root@OracleJJ shell]# vmstat 3 2|sed 1,3d|tr -s " "
0 0 0 257168 27828 296188 0 0 0 30 1002 37 0 0 97 3
{ }
1 9 2

read a1 a2 ...a16
a1a2 read
read
read
;
3 sqlplus scott/password <<EOF Sqlplus
scott password
Scott <<EOF 4 7 Shell
sqlplus 4 7 Sqlplus Oracle 8 EOF
8 Shell
4 5 sysdate,$a1,$a2,$a16 sysdate Oracle
$a1,$a2.. a1 a2 Shell "$"
read $
vi scott
Oracle vmstat 3

vmstat

-5-

Shell

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

www.askjj.com.cn

#!/bin/bash
# mystat vmstat my_os_stat
# ./mystat
# 300 5
i=1
k="$1"
j="$2"
if [ -z "$1" ]
then
k=300
fi
if [ -z "$2" ]
then
j=2
fi
while (( i <= j ))
do
vmstat $k 2|sed 1,3d|tr -s " "|{
read a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16;
sqlplus scott/password << EOF
insert into my_os_stat values(sysdate,$a1,$a2,$a3,$a4,$a5,$a6,$a7,$a8,$a9,
$a10,$a11,$a12,$a13,$a14,$a15,$a16);
commit;
exit
EOF
# EOF
}
if [ -n "$2" ]
then
let i=i+1
fi
done

1 3 25 #Shell

56 $1
$2

[root@OracleJJ shell]# ./mystat 300 20


$1 300$2 20 300 5
20
7 10 $1 k 300 k
vmstat
11 14 27 30 $2

-6-

Shell

www.askjj.com.cn

[root@OracleJJ shell]# ./mystat


5
[root@OracleJJ shell]# ./mystat 120
2
30

-7-