Operation steps via script command record (database) under Linux

Source: Internet
Author: User
Tags oracle database

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

Copy Code 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

Copy Code 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

robin@szdb:~> Sid

Bash:sid:command not found

robin@szdb:~>. ~/.bash_profile

robin@szdb:~> Sid


oracle_path=.:/ Users/robin/dba_scripts/custom/sql





robin@szdb:~> SQL </p> <p>sql*plus:release 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 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

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




OPERATIONS boston</p> <p>goex_admin@SYBO2SZ> exit

disconnected from Oracle Database 10g release Production

robin@szdb:~> Exit

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脚本的内容

# Author:robinson

# blog:http://blog.csdn.ner/robinson_0612</p> <p>robin@SZDB:~> more ~/dba_scripts/custom/bin/ Retval.sh


retval= ' sqlplus-silent scott/tiger <<eof


SELECT * from emp WHERE ename= ' SCOTT ';



if [-Z "$RETVAL"]; Then

echo "No rows returned from database"

Exit 0




Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.