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

    学而不思则罔,思而不学则殆
  • 相关阅读:
    为什么我会被淘汰?
    2017-3-27日碎碎念
    (原创)我对未来的人类的发展,以及AI技术发展的一些思考。
    八大排序算法图文讲解
    PE病毒初探——向exe注入代码
    [转]Patch文件结构详解
    芝麻信用商家接入指南
    如何成为一名好的程序员的一些个人经验
    .NET CoreCLR开发人员指南(上)
    七牛云:ckeditor JS SDK 结合 C#实现多图片上传。
  • 原文地址:https://www.cnblogs.com/linyu51/p/13964583.html
Copyright © 2011-2022 走看看