zoukankan      html  css  js  c++  java
  • shell编程

            打开文本编辑器(可以使用 vi/vim 命令来创建文件),新建一个文件 test.sh,扩展名为 sh(sh代表shell),扩展名并不影响脚本执行,见名知意就好,如果你用 php 写 shell 脚本,扩展名就用 php 好了。

    #! 是一个约定的标记,它告诉系统这个脚本需要什么解释器来执行,即使用哪一种 Shell。

    echo 命令用于向窗口输出文本。

    #!/bin/bash
    #Modify below variables if you need.
    user= 用户名(大写)
    hottime='2020-11-04 12:05:57'
    #Do not modify below variables.
    oracle_uid=`awk -F : '/oracle/ {print $3}' /etc/passwd`
    if [ `id -u` -ne $oracle_uid ];then
    echo 'Use ORACLE account to run this scripts!'
    exit 1
    fi
    sqlplus -S / as sysdba <<EOF >>/dev/null
    set pages 0
    set feedback off
    set long 99999
    spool /tmp/fulltext.txt
    select sql_fulltext
    from v$sqlarea
    where parsing_schema_name = '$user'
    and last_load_time >
    to_date('$hottime', 'yyyy-mm-dd hh24:mi:ss');
    spool off
    spool /tmp/aobjs.txt
    select object_name from dba_objects where object_type = 'TABLE' and owner = '$user';
    spool off
    exit
    EOF
    hot=$(cat /tmp/fulltext.txt|egrep -oi $(str1=""; for i in `cat /tmp/aobjs.txt` ;do str1=$str1"|"$i;done ;echo $str1)|tr a-z A-Z|sort|uniq|wc -l)
    aobjs=`cat /tmp/aobjs.txt|wc -l`
    echo "scale=2;$hot/$aobjs"|bc
    #clean
    rm -rf /tmp/aobjs.txt /tmp/fulltext.txt

    chmod +x ./test.#使脚本具有执行权限

    ./test.sh     #执行脚本

    注意,一定要写成 ./test.sh,而不是 test.sh,运行其它二进制的程序也一样,直接写 test.sh,linux 系统会去 PATH 里寻找有没有叫 test.sh 的,而只有 /bin, /sbin, /usr/bin,/usr/sbin 等在 PATH 里,你的当前目录通常不在 PATH 里,所以写成 test.sh 是会找不到命令的,要用 ./test.sh 告诉系统说,就在当前目录找。

    学而不思则罔,思而不学则殆
  • 相关阅读:
    uboot流程分析--修改android启动模式按键【转】
    RK平台Android4.4 添加一个新的遥控器支持以及添加特殊按键【转】
    C语言中函数strcpy ,strncpy ,strlcpy的用法【转】
    对字符串进行加密解密
    数字转IP地址函数
    汉字转拼音函数
    输出指定格式的数据列
    在SQL SERVER中实现RSA加解密函数(第二版)
    在SQL SERVER中实现RSA加解密函数(第一版)
    无序字符比较函数
  • 原文地址:https://www.cnblogs.com/linyu51/p/13964583.html
Copyright © 2011-2022 走看看