Chinaunix

标题: 求shell高手 [打印本页]

作者: chizhilove    时间: 2010-06-10 10:11
标题: 求shell高手

        sqlplus "/as sysdba"
        startup
        connect $EFPS_DBUSER/$EFPS_DBPASS
        @$EFPS_HOME/init/crt_tbl.sql
        quit
        
主要难点是执行sqlplus后,进入了oracle终端运行命令行
SQL>
然后这时候,我后面的命令startup~~~等都不能执行了。
如何改动,以实现sql>后面的命令也自动执行。求各位达人指点一二!
小弟感激不尽!


作者: lkk2003rty    时间: 2010-06-10 10:13
here document
  sqlplus  .... <<EOF
....
EOF
红色的写你在sqlplus下执行的命令
作者: iori809    时间: 2010-06-10 10:15
你起码应该先连接到Oracle在Startup吧~
顺序应该搞明白吧~找一本Oracle的书看看吧~
作者: chizhilove    时间: 2010-06-10 10:16
回复 2# lkk2003rty


    按你这种方式的时候提示语法错误。
作者: iori809    时间: 2010-06-10 10:17
看错了~你为什么连接两回呢?
作者: chizhilove    时间: 2010-06-10 10:18
dbstart
        lsnrctl start

        sqlplus "/as sysdba" <<EOF
        startup
        connect $EFPS_DBUSER/$EFPS_DBPASS
        @$EFPS_HOME/init/crt_tbl.sql
        quit

        EOF

本来是想写一个脚本容易点的。。
作者: chizhilove    时间: 2010-06-10 10:22
回复 5# iori809


    startup的权限不够吧。要先用system把数据库启动起来,然后再连接自己的用户。不过这不是错误的重点吧,改了这里也没作用的。
作者: iori809    时间: 2010-06-10 10:32
回复 7# chizhilove


    [oracle@test7: ~]$sqlplus "/ as sysdba"
[uniread] Loaded history (804 lines)

SQL*Plus: Release 11.1.0.6.0 - Production on Thu Jun 10 10:28:42 2010

Copyright (c) 1982, 2007, Oracle.  All rights reserved.

Connected to an idle instance.

idle> startup
ORACLE instance started.

Total System Global Area  839282688 bytes
Fixed Size                  2149040 bytes
Variable Size             603981136 bytes
Database Buffers          226492416 bytes
Redo Buffers                6660096 bytes
Database mounted.
Database opened.

没问题的,只不过由于你一开始Oracle的instance是关闭的,所以你连接上的是一个idle。
sysdba已经是最高权限了
作者: chizhilove    时间: 2010-06-10 10:42
回复 8# iori809


    呃。。。首先感谢您的解答。
不过我是要写一个shell脚本自动执行,如果手动输入命令是没问题的。
然后这里的问题是如果没有<<EOF...EOF时,会进入如你的idle>的SQL>处理行。
然后这时候我脚本里面要执行的命令,startup, connect~~便不能自动执行,处于等待输入状态。
然后手动退出SQL>处理行后,又提示:
./bash_db.sh: line 18: startup: command not found
./bash_db.sh: line 20: connect: command not found
我是想问如何实现这些命令,在SQL> 后执行。而不是退出后才执行。
作者: iori809    时间: 2010-06-10 10:52
回复 9# chizhilove


    [oracle@test7: ~]$more sh1.sh

#!/bin/bash
sqlplus "/nolog" <<EOF
conn / as sysdba
startup
select 1+1 from dual;
quit;
EOF
[oracle@test7: ~]$sh sh1.sh

SQL*Plus: Release 11.1.0.6.0 - Production on Thu Jun 10 10:53:55 2010

Copyright (c) 1982, 2007, Oracle.  All rights reserved.

idle> Connected to an idle instance.
idle> ORACLE instance started.

Total System Global Area  839282688 bytes
Fixed Size                  2149040 bytes
Variable Size             603981136 bytes
Database Buffers          226492416 bytes
Redo Buffers                6660096 bytes
Database mounted.
Database opened.
idle>
       1+1
----------
         2

idle> Disconnected from Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@test7: ~]$

这是我写的一个脚本~运行没问题。看看是不是你要的
作者: chizhilove    时间: 2010-06-10 11:43
回复 10# iori809


    好的,我试下!谢谢哦!
作者: chizhilove    时间: 2010-06-10 16:22
问题已解决,原来EOF必须放在行首,而不能为了漂亮加Tab效果。




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2