在Linux下使用script命令记录数据库操作

Linux下使用Oracle时,很多时候我们想记录操作信息,有很多方法可以实现,如:spool之类的。但本文介绍的是Linux下带的script工具。

Linux下有一个script工具可以讲当前终端会话中的所有输入输出结果捕获到一个指定的文件中。下面我们就看看script的介绍和用法。

[oracle@HZCC-SRV-NEW1 newccs]$ which script

/usr/bin/script

[oracle@HZCC-SRV-NEW1 newccs]$ man script

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

NAME

     script - make typescript of terminal session

SYNOPSIS

     script [-a] [-c COMMAND] [-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.

     Options:

     -a      Append the output to file or typescript, retaining the prior

             contents.

     -c COMMAND

             Run the COMMAND rather than an interactive shell.  This makes it

             easy for a script to capture the output of a program that

             behaves differently when its stdout is not a tty.

     -f      Flush output after each write. This is nice for telecooperation:

             One person does 鈥榤kfifo foo; script -f foo?and another can

             supervise real-time what is being done using 鈥榗at foo?

     -q      Be quiet.

     -t      Output timeing data to standard error. This data contains two

             fields, separated by a space. The first field indicates how much

             time elapsed since the previous output. The second field indi-

             cates how many characters were output this time.

     The script ends when the forked shell exits (a control-D to exit the

     Bourne shell (sh(1)), and exit, logout or control-d (if ignoreeof is not

     set) for the C-shell, csh(1)).

     Certain interactive commands, such as vi(1), create garbage in the type-

     script file.  Script works best with commands that do not manipulate the

     screen, the results are meant to emulate a hardcopy terminal.

ENVIRONMENT

     The following environment variable is utilized by script:

     SHELL  If the variable SHELL exists, the shell forked by script will be

            that shell. If SHELL is not set, the Bourne shell is assumed.

            (Most shells set this variable automatically).

SEE ALSO

     csh(1) (for the history mechanism).

HISTORY

     The script command appeared in 3.0BSD.

BUGS

     Script places everything in the log file, including linefeeds and

     backspaces.  This is not what the naive user expects.

Linux                           July 30, 2000                           Linux

 [oracle@HZCC-SRV-NEW1 newccs]$ script

Script started, file is typescript

省略中间操作部分。

[oracle@HZCC-SRV-NEW1 newccs]$ exit

exit

Script done, file is typescript

[oracle@HZCC-SRV-NEW1 newccs]$ cat typescript

Script started on Wed 14 Jul 2010 01:16:20 PM CST

[oracle@HZCC-SRV-NEW1 newccs]$ sqlplus "/ as sysdba"

 

SQL*Plus: Release 10.2.0.4.0 - Production on Wed Jul 14 13:16:34 2010

 

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

 

 

Connected to:

Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

 

SQL> select dbid from v$database;

 

      DBID

----------

3728795045

 

SQL> exit

Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

[oracle@HZCC-SRV-NEW1 newccs]$ exit

exit

 

Script done on Wed 14 Jul 2010 01:17:05 PM CST

通过上述方法我们可以很方面的记录在用户的操作。当然还有功能更强大的scriptreplay工具,可以replay script。不过这里就不做过多的介绍了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值