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

(0)

相关推荐

  • 在windws下模拟Linux下可获取命令执行时间的time命令

    Linux 下的 time 命令可以获取命令执行时间,Windows 下并没有类似的命令,我们可以自力更生写一个批处理,命名为time.bat。 [plain] @echo off set /a St ...

  • windows下的类似linux下的grep命令--findstr

    windows下的类似linux下的grep命令——findstr 经常用linux下的grep命令,比如: netstat -an|grep 1521 其实windows下也有一个类似的命令find ...

  • Linux下使用blkid命令查询设备及文件系统信息的方法

    在Linux下可以使用blkid命令对查询设备上所采用文件系统类型进行查询.blkid主要用来对系统的块设备(包括交换分区)所使用的文件系统类型.LABEL.UUID等信息进行查询.要使用这个命令必须 ...

  • Fedora 29下安装Chrome浏览器的具体操作步骤

    我们在系统上如何安装国际化的浏览器Chrome呢?接下来就跟小编一起来看一下吧.具体如下:1. 首先可以通过在电脑上的浏览器搜索名字来找到需要安装的浏览器,并且点击打开.2. 进入浏览器官网,点击下载 ...

  • linux下find查找命令用法

    Linux下find命令在目录结构中搜索文件,并执行指定的操作。Linux下find命令提供了相当多的查找条件,功能很强大。由于find具有强大的功能,所以它的选项也很多,其中大部分选项都值得我们花时 ...

  • ubuntu linux 下使用Qt连接MySQL数据库

    环境说明: ubuntu 10.04.2 QtSDK (1.5G安装包的那个) mysql5.1 1.安装MySQL Linux下完整的MySQL开发需要安装服务器端,如果安装客户端也没什么不好。直接 ...

  • linux下history(历史)命令用法详解

    如果你经常使用 Linux 命令行,那么使用 history(历史)命令可以有效地提升你的效率。本文将通过实例的方式向你介绍 history 命令的15个用法。 1. 使用 HISTTIMEFORMA ...

  • Linux 下使用mount命令挂载CDROM的方法

    Linux显示所有的目录都在一个目录树下,而与它们位于哪一个驱动器或硬件无关.在Linux下的磁盘内容作为子目录形式出现的,可移动介质的内容不会自动出现在这些子目录中,因此需要我们通过挂载驱动器来实现 ...

  • Linux下编译安装配置MariaDB数据库的方法

    说明: 操作系统:CentOS 5.10 32位 MariaDB版本:mariadb-5.5.33a MariaDB数据库存放目录:/data/mysql 准备篇: 一、配置好IP、DNS 、网关,确 ...