linux下通过script 命令记录(数据库)操作步骤

来源: 电脑维修教程 阅读:     发表时间:

对dba而言,常常碰着进级数据库或是apply patch,和有些时辰需要运行大量的剧本。对于这些操作我们但愿此刻在屏幕同时又输出的文件以备后续查询进程中

对dba而言,常常碰着进级数据库或是apply patch,和有些时辰需要运行大量的剧本。对于这些操作我们但愿此刻在屏幕同时又输出的文件以备后续查询进程中曾丢掉的步调或过错。linux下的script号令就是解决这个问题的好辅佐

1、script号令描写

复制代码

代码以下:

script号令会记实所有的操作到文件同时在屏幕上输出,直到终止登岸的会话,或利用crtl+d,或利用exit退出则遏制记实。

这个号令对于数据库的进级或是主要设置的景象下利用可以用于后续查询操作成功或掉败。

用法: $ script [upgrade.log]

若是未指定日记文件名的景象,主动生成日记文件名为typescript。

若是需要输出到已存在的日记文件,则利用 -a 参数,再接已存在日记文件名。

若是需要在输出到日记文件的同时,也能够查看日记文件的内容,可使用 -f 参数。</p> <p># script 扶助描写

robin@szdb:~> man script

name

script - make typescript of terminal session</p> <p>synopsis

script [-a] [-c command] [-f] [-q] [-t] [file]</p> <p>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).</p> <p> 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.</p> <p> options:</p> <p> -a append the output to file or typescript, retaining the prior contents.</p> <p> -c command

run the command rather than an interactive shell. this makes it easy for a script to capture the output of a pro-

gram that behaves differently when its stdout is not a tty.</p> <p> -f flush output after each write. this is nice for telecooperation: one person does `mkfifo foo; script -f foo' and

another can supervise real-time what is being done using `cat foo'.</p> <p> -q be quiet.</p> <p> -t output timeing data to standard error. this data contains two fields, separated by a space. the first field indi-

cates how much time elapsed since the previous output. the second field indicates how many characters were output

this time. this information can be used to replay typescripts with realistic typing and output delays.

2、script号令用法示例

复制代码

代码以下:

a、script号令后接日记文件名

robin@szdb:~> script test_logfile.log #启用script

script started, file is test_logfile.log</p> <p> .................#中心操作省略

robin@szdb:~> exit #遏制script

exit

script done, file is test_logfile.log</p> <p>#查看方才生成的日记文件

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 </p> <p>sql*plus: release 10.2.0.3.0 - production on fri apr 26 17:46:12 2013</p> <p>copyright (c) 1982, 2006, oracle. all rights reserved.</p> <p>error accessing product_user_profile

warning: product user profile information not loaded!

you may need to run pupbld.sql as system</p> <p>connected to:

oracle database 10g release 10.2.0.3.0 - 64bit production</p> <p>goex_admin@sybo2sz> alter session set current_schema=scott;</p> <p>session altered.</p> <p>goex_admin@sybo2sz> select * from dept;</p> <p> deptno dname loc

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

10 accounting new york

20 research dallas

30 sales chicago

40 operations boston</p> <p>goex_admin@sybo2sz> exit

disconnected from oracle database 10g release 10.2.0.3.0 - 64bit production

robin@szdb:~> exit

exit</p> <p>script done on fri 26 apr 2013 05:46:32 pm cst </p> <p>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</p> <p>#被执行的shell剧本的内容

# author : robinson

# blog : http://blog.csdn.ner/robinson_0612</p> <p>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下通过script 命令记录(数据库)操作步骤问题的详细资料教程