程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> Oracle數據庫 >> Oracle數據庫基礎 >> 使用Linux下script工具記錄Oracle輸出

使用Linux下script工具記錄Oracle輸出

編輯:Oracle數據庫基礎
Linux系統下使用Oracle數據庫時,如果我們想記錄輸出記錄有很多方法可以選擇,但是本文介紹的是使用script工具。

  在Linux下有一個script工具,可以將當前終端會話中的所有輸入輸出結果捕獲到一個指定的文件裡。

  看一下這個工具的man輸出:

  [oracle@jumper Oracle]$ which script

  /usr/bin/script

  [oracle@jumper Oracle]$ man script

  SCRIPT(1) BSD General Commands Manual SCRIPT(1)

  NAME

  script - make typescript of terminal session

  SYNOPSIS

  script [-a] [-f] [-q] [-t] [file]

  DESCRIPTION

  Script makes a typescript of everything printed on your terminal. It is

  useful for students who need a hardcopy record of an interactive session

  as proof of an assignment, as the typescript file can be printed out

  later with lpr(1).

  If the argument file is given, script saves all dialogue in file. If no

  file name is given, the typescript is saved in the file typescript.

  當然最重要的是看一下實際效果。

在記錄操作前執行 script 命令開始記錄,最後輸入 exit 退出記錄,中間的所有操作都會被記錄下來,以下是一個測試過程,中間步驟被省略:

  [oracle@jumper Oracle]$ script

  Script started, file is typescript

  [oracle@jumper Oracle]$ sqlplus "/ as sysdba"

  <...ignore Operation here...>

  [oracle@jumper Oracle]$ exit

  Script done, file is typescript

  現在讓我們來看看記錄文件typescript中記錄了什麼內容:

  [oracle@jumper Oracle]$ cat typescript

  Script started on Thu 26 Jun 2008 07:56:18 AM CST

  [oracle@jumper Oracle]$ sqlplus "/ as sysdba"

  SQL*Plus: Release 9.2.0.4.0 - Production on Thu Jun 26 07:56:24 2008

  Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

  Connected to:

  Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production

  With the Partitioning option

  JServer Release 9.2.0.4.0 - Production

  SQL> set linesize 120

  SQL> alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';

  Session altered.

  SQL> col status for a8

  SQL> col group# for 999999

  SQL> select * from v$log;

  GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIME

  ------- ---------- ---------- ---------- ---------- --- -------- ------------- -------------------

  1 1 14 1048576 1 YES INACTIVE 1.9008E+10 2008-06-23 00:42:36

  3 1 15 1048576 1 YES INACTIVE 1.9008E+10 2008-06-25 14:29:37

  4 1 13 1048576 1 YES INACTIVE 1.9008E+10 2008-06-20 14:56:12

  5 1 16 1048576 1 NO CURRENT 1.9008E+10 2008-06-25 15:58:38

  SQL> exit

  Disconnected from Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production

  With the Partitioning option

  JServer Release 9.2.0.4.0 - Production

  [oracle@jumper Oracle]$

  [oracle@jumper Oracle]$ exit

  Script done on Thu 26 Jun 2008 07:57:38 AM CST

  這個工具是不是很有用途呢?

  當然還有更強悍的 scriptreplay 工具可以replay script,不過缺省一般不帶,不說了。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved