here-document技术

<<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技术还是很不错的,避免了人机交互,方便管理

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

历史五千年

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值