Linux script command record (database) operation steps for DBA, often encounter Database Upgrade or apply patch, and sometimes need to run a large number of scripts. For these operations, we want to output files simultaneously on the screen for subsequent steps or errors that have been lost during query. Script Commands in Linux are a good helper to solve this problem. 1. The script command description [python] script command records all operations to the file and outputs them on the screen at the same time until the login session is terminated, or the CRTL + D is used, or exit with exit to stop the record. This command can be used for database upgrades or important settings for subsequent query operations to succeed or fail. Usage: $ script [upgrade. log] If no log file name is specified, the log file name is automatically generated as typescript. If you need to output to an existing Log File, use the-a parameter, and then connect the existing log file name. If you want to view the content of a log file while outputting it to a log file, you can use the-f parameter. # Script help description robin @ SZDB: ~> Man script NAME script-make typescript of terminal session SYNOPSIS script [-a] [-c COMMAND] [-f] [-q] [-t] [file] DESCRIPTION Script makes typescript of everything printed on your terminal. it is useful for students who need a hardcopy record of an interactive session as proof 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 pro-gram that behaves differently when its stdout is not a tty. -f Flush output after each wri Te. 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 '. -q Be quiet. -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 th Is time. this information can be used to replay typescripts with realistic typing and output delays. 2. script command usage example [python] a. The script command is followed by the log file name robin @ SZDB: ~> Script test_logfile.log # enable script Script started, file is test_logfile.log... ...... the intermediate operation omitting robin @ SZDB: ~> Exit # Stop script exit Script done, file is test_logfile.log # view the generated log file 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 SQL * Plus: Release 10.2.0.3.0-Production on Fri Apr 26 17:46:12 2013 Copyright (c) 1982,200 6, Oracle. All Rights Reserved. Error accessing PRODUCT_USER_PROFILE Warning: Product user profile information not loaded! You may need to run PUPBLD. SQL as SYSTEM Connected to: Oracle Database 10g Release 10.2.0.3.0-64bit Production goex_admin @ SYBO2SZ> alter session set current_schema = scott; Session altered. goex_admin @ SYBO2SZ> select * from dept; deptno dname loc ---------- --------------------- 10 accounting new york 20 research dallas 30 sales chicago 40 operations boston goex_admin @ SYBO2SZ> exit Disconne Cted from Oracle Database 10g Release 10.2.0.3.0-64bit Production robin @ SZDB: ~> Exit Script done on Fri 26 Apr 2013 05:46:32 pm cst B. Example robin @ SZDB: ~> Script-c retval. sh Script started, file is typescript 7788 scott analyst 7566 19870419 3100 00:00:00 20 Script done, file is typescript # the content of the shell script executed by 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