<<delimiter符号称为此处文档(here-document),delimiter称为分界符,该符号表明:shell将分界符delimiter之后直至下一个delimiter之前的所有内容作为命令
的输入。
实验一:
[oracle@~/lxdir]$ cat >> newfile <<EOI
> good
> hello world
> java oracle
> EOI
[oracle@~/lxdir]$ cat newfile
good
hello world
java oracle
此实验中我们使用了here-document技术,<<EOI到下一个EOI之间的所有内容作为cat命令的输入,然后cat将接受到的东西重定向到newfile文件中。
实验二:
[oracle@~/lxdir]$ vi startDB.sh
#! /bin/bash
sqlplus /nolog <<ABC
conn / as sysdba
startup
ABC
[oracle@~/lxdir]$ ls -l startDB.sh
-rw-r--r-- 1 oracle oinstall 64 Jul 17 16:22 startDB.sh
[oracle@~/lxdir]$ chmod u+x startDB.sh
[oracle@~/lxdir]$ ./startDB.sh
SQL*Plus: Release 10.2.0.1.0 - Production on 星期四 7月 17 16:22:58 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
SQL> Connected to an idle instance.
SQL> ORACLE instance started.
Total System Global Area 629145600 bytes
Fixed Size 1220964 bytes
Variable Size 171970204 bytes
Database Buffers 452984832 bytes
Redo Buffers 2969600 bytes
Database mounted.
Database opened.
SQL> Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
[oracle@~/lxdir]$
这个实验编写了一个shell脚本,通过shell脚本启动数据库。
实验三:
[oracle@~/lxdir]$ echo $ORACLE_SID
demo
[oracle@~/lxdir]$ ps -ef | grep oracle
root 4096 3542 0 10:49 ? 00:00:00 sshd: oracle [priv]
oracle 4099 4096 0 10:49 ? 00:00:00 sshd: oracle@pts/1
oracle 4100 4099 0 10:49 pts/1 00:00:00 -bash
root 5041 3542 0 14:06 ? 00:00:00 sshd: oracle [priv]
oracle 5043 5041 0 14:06 ? 00:00:00 sshd: oracle@pts/2
oracle 5044 5043 0 14:06 pts/2 00:00:00 -bash
oracle 5528 1 0 16:23 ? 00:00:00 ora_pmon_demo
oracle 5530 1 0 16:23 ? 00:00:00 ora_psp0_demo
oracle 5532 1 0 16:23 ? 00:00:00 ora_mman_demo
oracle 5534 1 0 16:23 ? 00:00:00 ora_dbw0_demo
oracle 5536 1 0 16:23 ? 00:00:00 ora_lgwr_demo
oracle 5538 1 0 16:23 ? 00:00:00 ora_ckpt_demo
oracle 5540 1 0 16:23 ? 00:00:00 ora_smon_demo
oracle 5542 1 0 16:23 ? 00:00:00 ora_reco_demo
oracle 5544 1 0 16:23 ? 00:00:00 ora_mmon_demo
oracle 5546 1 0 16:23 ? 00:00:00 ora_mmnl_demo
oracle 5550 1 0 16:23 ? 00:00:00 ora_qmnc_demo
oracle 5558 1 0 16:23 ? 00:00:00 ora_q001_demo
oracle 5560 1 0 16:23 ? 00:00:00 ora_q002_demo
oracle 5566 5044 0 16:25 pts/2 00:00:00 ps -ef
oracle 5567 5044 0 16:25 pts/2 00:00:00 grep oracle
发现,有很多oracle后台进程,这时我们可以编写一个shell脚本来关闭数据库
[oracle@~/lxdir]$ vi stopDB.sh
#! /bin/bash
sqlplus /nolog <<DEF
conn / as sysdba
shutdown immediate
DEF
[oracle@~/lxdir]$ ls -l stopDB.sh
-rw-r--r-- 1 oracle oinstall 75 Jul 17 16:28 stopDB.sh
[oracle@~/lxdir]$ chmod u+x stopDB.sh
[oracle@~/lxdir]$ ls -l stopDB.sh
-rwxr--r-- 1 oracle oinstall 75 Jul 17 16:28 stopDB.sh
[oracle@~/lxdir]$ ./stopDB.sh
SQL*Plus: Release 10.2.0.1.0 - Production on 星期四 7月 17 16:28:57 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
SQL> Connected.
SQL> Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
现在数据库已关闭了,here-document技术还是很不错的,避免了人机交互,方便管理