zoukankan      html  css  js  c++  java
  • shell脚本运行

           最近工作特别忙,感觉好长时间没有写日志了,今天就来简单的聊一下linux系统中的shell脚本。其实简单来说就是shell编程就是对一堆Linux命令的逻辑化处理,在脚本里编辑所要执行的业务逻辑。

          比如说,我想了解数据库中的被执行的执行或操作过的表占所有表的百分比。那么脚本通常为首先通过vi或touch,mkdir创建一个以.sh后缀名的文件(touch test.sh)通过vi  test.sh打开这个文件,注意这个#!/bin/bash不能写错,也不能漏写。比如这样:

    #!/bin/bash
    #Modify below variables if you need.
    user=oracle                     ----数据库的用户名
    hottime='2020-08-28 0:01:00'            -----开始的时间
    #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.sh

    最后执行  ./test.sh就可以了。

    学而不思则罔,思而不学则殆
  • 相关阅读:
    [转] Linux下crontab命令的用法
    [转] Try to use one var statement per scope in JavaScript
    [转] 主流JS框架中DOMReady事件的实现
    MySQL 表复制语句
    [转] MySQL中的运算符展示
    [转] mysql分组取每组前几条记录(排名)
    MySQL 连接结果集
    [转] mysql show processlist命令 详解
    [转] mysql 5.0存储过程学习总结
    jquery中使用event.target的几点
  • 原文地址:https://www.cnblogs.com/linyu51/p/13581910.html
Copyright © 2011-2022 走看看