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 告诉系统说,就在当前目录找。

    学而不思则罔,思而不学则殆
  • 相关阅读:
    poj 1684 Lazy Math Instructor(字符串)
    STL内存配置器
    迭代器(iterators)
    类型萃取(type traits)
    hdu 2191 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活(多重背包+dp)
    hdoj 1114 Piggy-Bank(完全背包+dp)
    hdoj 2546 饭卡(0-1背包)
    hdoj 2620 Bone Collector(0-1背包)
    U3d开发个人总结
    Android软键盘的用法总结
  • 原文地址:https://www.cnblogs.com/linyu51/p/13964583.html
Copyright © 2011-2022 走看看