For DBAs, it's often the case for the upgrade database or apply patch, and sometimes a lot of scripts need to be run. For these operations we want the files that are now being printed on the screen to be exported at the same time as the steps or errors that were lost during the subsequent query. The script command under Linux is a good helper to solve this problem.
1. Script Command Description
code as follows:
script command records all operations to the file at the same time as the screen output, until the logon session is terminated, or the crtl+d is used, or exit exits with exit to stop the recording.
This command can be used for subsequent query success or failure in the case of database upgrades or important settings.
Usage: $ script [Upgrade.log]
if the log file name is not specified, the automatically generated log file name is typescript.
If you need to output to a log file that already exists, use the-a parameter, and then the log file name already exists.
You can also view the contents of a log file while outputting to a log file, you can use the-f argument. </p> <p># Script Help Description
robin@szdb:~> man Script
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 to students who need a hardcopy record of
a interactive session as proof of a 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 was saved in the
file typescript.</p> <p> options:</p> <p>-a Append the output to file or typescript, retain ing the prior contents.</p> <p>-C COMMAND
Run the COMMAND rather than an interactive shell. This is makes it easy for a script to capture the output of a pro-
gram that behaves differently as its stdout are 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 do using ' cat foo ' .</p> <p>-Q be quiet.</p> <p>- T Output timeing data to standard error. This is the data contains two fields, separated by a. The 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 is used to replay typescripts with realistic typing and output delays.
2. Example of script command usage
code as follows:
A, script command followed by log file name
robin@szdb:~> script Test_logfile.log #启用script
Script started, the file is Test_logfile.log</p> <p> ..... #中间操作省略
robin@szdb:~> exit #停止script
Script Done, the file is test_logfile.log</p> <p> #查看刚刚生成的日志文件
robin@szdb:~> more Test_logfile.log
Script started on Fri Apr 2013 05:45:23 PM CST
Bash:sid:command not found
robin@szdb:~> SQL </p> <p>sql*plus:release 10.2.0.3.0-production on Fri Apr 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 are 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 SE T current_schema=scott;</p> <p>session altered.</p> <p>goex_admin@SYBO2SZ> SELECT * FROM dept;</p> <p> DEPTNO dname LOC
---------- -------------- -------------
ACCOUNTING NEW YORK
OPERATIONS boston</p> <p>goex_admin@SYBO2SZ> exit
disconnected from Oracle Database 10g release 10.2.0.3.0-64bit Production
exit</p> <p>script do on Fri Apr 2013 05:46:32 PM CST </p> <p>b, script direct to scripting name
robin@szdb:~> script-c retval.sh
Script started, file is Typescript
7788 SCOTT ANALYST 7566 19870419 00:00:00 3100 20
Script Done, the file is typescript</p> <p> #被执行的shell脚本的内容
# blog:http://blog.csdn.ner/robinson_0612</p> <p>robin@SZDB:~> more ~/dba_scripts/custom/bin/ Retval.sh
retval= ' sqlplus-silent scott/tiger <<eof
SET PAGESIZE 0 FEEDBACK off VERIFY off HEADING off ECHO off
SELECT * from emp WHERE ename= ' SCOTT ';
if [-Z "$RETVAL"]; Then
echo "No rows returned from database"