你好,游客 登录 注册 搜索
背景:
阅读新闻

Linux script 命令记录(数据库)操作步骤

[日期:2013-05-02] 来源:Linux社区  作者:robinson [字体:大 中 小]

2、script命令用法示例

a、script命令后接日志文件名
robin@SZDB:~> script test_logfile.log        #启用script
Script started, file is test_logfile.log

  .................#中间操作省略
 
robin@SZDB:~> exit    #停止script
exit
Script done, file is test_logfile.log

#查看刚刚生成的日志文件
robin@SZDB:~> more test_logfile.log
Script started on Fri 26 Apr 2013 05:45:23 PM CST
robin@SZDB:~> sid 
bash: sid: command not found
robin@SZDB:~> . ~/.bash_profile
robin@SZDB:~> sid
ORA_CRS_HOME=/opt/Oracle/product/10gR2/crs
ORACLE_PATH=.:/users/robin/dba_scripts/custom/sql
ORA_ASM_HOME=/opt/oracle/product/10gR2/asm
ORACLE_SID=SYBO2SZ
ORACLE_BASE=/users/oracle
ORACLE_HOME=/users/oracle/OraHome10g
robin@SZDB:~> sql   

SQL*Plus: Release 10.2.0.3.0 - Production on Fri Apr 26 17:46:12 2013

Copyright (c) 1982, 2006, Oracle.  All Rights Reserved.

Error accessing PRODUCT_USER_PROFILE
Warning:  Product user profile information not loaded!
You may need to run PUPBLD.SQL as SYSTEM

Connected to:
Oracle Database 10g Release 10.2.0.3.0 - 64bit Production

goex_admin@SYBO2SZ> alter session set current_schema=scott;

Session altered.

goex_admin@SYBO2SZ> select * from dept;

    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 ACCOUNTING    NEW YORK
        20 RESEARCH      DALLAS
        30 SALES          CHICAGO
        40 OPERATIONS    BOSTON

goex_admin@SYBO2SZ> exit
Disconnected from Oracle Database 10g Release 10.2.0.3.0 - 64bit Production
robin@SZDB:~> exit
exit

Script done on Fri 26 Apr 2013 05:46:32 PM CST 

b、script 命下直接跟脚本名的示例
robin@SZDB:~> script -c retval.sh
Script started, file is typescript
7788 SCOTT ANALYST 7566 19870419 00:00:00 3100 20
Script done, file is typescript

#被执行的shell脚本的内容

robin@SZDB:~> more ~/dba_scripts/custom/bin/retval.sh
#!/bin/bash
RETVAL=`sqlplus -silent scott/tiger <<EOF
SET PAGESIZE 0 FEEDBACK OFF VERIFY OFF HEADING OFF ECHO OFF
SELECT * FROM emp WHERE ename='SCOTT';
EXIT;
EOF`
if [ -z "$RETVAL" ]; then
  echo "No rows returned from database"
  exit 0
else
  echo $RETVAL
fi

linux
相关资讯       Linux script命令  Linux script 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款