zoukankan      html  css  js  c++  java
  • 【Shell学习】shell脚步例子

    #!/bin/bash
    
    home_path="/root/.jenkins/jobs"
    path_file=${home_path}/path.txt
    log_path=${home_path}/clear.log
    disk_size_consum=$(df -h|grep -v grep|grep "vg_control-lv_root"|awk '{print $5}'|sed 's/\%//g')
    disk_limit=90
    find ${home_path} -name "builds"|sed 's/.///g' > ${path_file}
    date_time=$(date +'%Y%m%d') 
    clear()
    {
         while read line
         do
            echo -e "当前清理工程${line}"
            cd ${line}
            build_num=`ls -t|grep '^[0-9]'|wc -l`
        need_build=$((build_num-6))
        [ ${build_num} != 0 ] && rm_build=`ls -t|grep '^[0-9]'|tail -${need_build}|xargs` && rm -rf ${rm_build} && echo -e "当前清理工程${line}成功"
         done < ${path_file}
    }
    
    verify_disk()
    {
       if [ ${disk_size_consum} -ge ${disk_limit} ];then 
        clear
       else 
           echo -e "$(date +'%Y-%m-%d %H:%M:%S')-磁盘使用率为${disk_size_consum}%, 未超过${disk_limit}" 
       fi   
    }
    main()
    {
       echo -e "\033[40;31mUsage: $0 [OPTION]...\033[0m"
       echo -e "\033[40;31mExample [1]:$0 直接执行清理脚本\033[0m"
       echo -e "        \033[40;31m[2]:$0 disk 校验磁盘大小是否大于等于95%,满足则清理,不满足不清理\033[0m"
       echo -e "        \033[40;31m查看日志:clear.log\033[0m"
    }
    case $1 in
        "")
            read -p "真的需要清理么?YES/NO:" v
            if [ $v == "YES" -o $v == "y" -o $v == "Y" -o $v == "yes" ];then
                   clear
            else
                 echo -e "Exit!!!"
            fi;;
            "disk")
        verify_disk | tee -a ${log_path};;
        "-help"|"-h")
            main;;
            *)
            echo -e "\033[31;5mInput parameter error, please input['空','disk']\033[0m"
    esac
    View Code
    #!/bin/bash
    
    home_path="/home/edr_auto_test/packet/platform"
    pkg_name=${home_path}/tools/.pkg_name.txt
    log_path=${home_path}/tools/clear.log
    disk_size_consum=$(df -h|grep -v grep|grep -A1 "/dev/mapper/ubuntu11-root"|awk '{print $4}'|sed 's/\%//g')
    disk_limit=90
    find ${home_path}/test_pkg -name "*pkg"|sed 's/.///g' > ${pkg_name}
    date_time=$(date +'%Y%m%d') 
    clear()
    {
         while read line
         do
            echo -e "当前清理PKG${line}"
            cd $(dirname ${line})
            build_num=`ls -t|grep 'pkg$'|wc -l`
        need_build=$((build_num-4))
        [ ${build_num} != 0 ] && rm_build=`ls -t|grep 'pkg$'|tail -${need_build}|xargs` && rm -rf ${rm_build} && echo -e "当前清理PKG${line}成功"
         done < ${pkg_name}
    }
    
    verify_disk()
    {
       if [ ${disk_size_consum} -ge ${disk_limit} ];then 
            echo -e "$(date +'%Y-%m-%d %H:%M:%S')-磁盘使用率为${disk_size_consum}%, 超过${disk_limit},执行清理"
            clear
       else 
           echo -e "$(date +'%Y-%m-%d %H:%M:%S')-磁盘使用率为${disk_size_consum}%, 未超过${disk_limit}" 
       fi   
    }
    main()
    {
       echo -e "\033[40;31mUsage: $0 [OPTION]...\033[0m"
       echo -e "\033[40;31mExample [1]:$0 直接执行清理脚本\033[0m"
       echo -e "        \033[40;31m[2]:$0 disk 校验磁盘大小是否大于等于90%,满足则清理,不满足不清理\033[0m"
       echo -e "        \033[40;31m查看日志:clear.log\033[0m"
    }
    case $1 in
        "")
            read -p "真的需要清理么?YES/NO:" v
            if [ $v == "YES" -o $v == "y" -o $v == "Y" -o $v == "yes" ];then
                   clear
            else
                 echo -e "Exit!!!"
            fi;;
            "disk")
        verify_disk | tee -a ${log_path};;
        "-help"|"-h")
            main;;
            *)
            echo -e "\033[31;5mInput parameter error, please input['空','disk']\033[0m"
    esac
    View Code

    #!/bin/bash
    home_path="/root/.jenkins/jobs"path_file=${home_path}/path.txtlog_path=${home_path}/clear.logdisk_size_consum=$(df -h|grep -v grep|grep "vg_control-lv_root"|awk '{print $5}'|sed 's/\%//g')disk_limit=90find ${home_path} -name "builds"|sed 's/.///g' > ${path_file}date_time=$(date +'%Y%m%d') clear(){     while read line     do        echo -e "当前清理工程${line}"        cd ${line}        build_num=`ls -t|grep '^[0-9]'|wc -l`need_build=$((build_num-6))[ ${build_num} != 0 ] && rm_build=`ls -t|grep '^[0-9]'|tail -${need_build}|xargs` && rm -rf ${rm_build} && echo -e "当前清理工程${line}成功"     done < ${path_file}}
    verify_disk(){   if [ ${disk_size_consum} -ge ${disk_limit} ];then clear   else        echo -e "$(date +'%Y-%m-%d %H:%M:%S')-磁盘使用率为${disk_size_consum}%, 未超过${disk_limit}"    fi   }main(){   echo -e "\033[40;31mUsage: $0 [OPTION]...\033[0m"   echo -e "\033[40;31mExample [1]:$0 直接执行清理脚本\033[0m"   echo -e "        \033[40;31m[2]:$0 disk 校验磁盘大小是否大于等于95%,满足则清理,不满足不清理\033[0m"   echo -e "        \033[40;31m查看日志:clear.log\033[0m"}case $1 in"")        read -p "真的需要清理么?YES/NO:" v        if [ $v == "YES" -o $v == "y" -o $v == "Y" -o $v == "yes" ];then       clear        else             echo -e "Exit!!!"        fi;;    "disk")verify_disk | tee -a ${log_path};;"-help"|"-h")        main;;        *)        echo -e "\033[31;5mInput parameter error, please input['空','disk']\033[0m"esac

    作者:gtea 博客地址:https://www.cnblogs.com/gtea
  • 相关阅读:
    Codeforces 919D:Substring(拓扑排序+DP)
    初学Javascript,写一个简易的登陆框
    学习数据结构之线性表
    用python实现的简易记牌器的demo
    Multiism四阶巴特沃兹低通滤波器的仿真实现
    用python来抓取“煎蛋网”上面的美女图片,尺度很大哦!哈哈
    用Python爬虫爬取“女神吧”上的照片。
    在linux操作系统上进行简单的C语言源码的gcc编译实验
    想学习linux操作系统,于是选择了在win8 虚拟机VM player 里装了Linux版本Centos7
    通过python的urllib.request库来爬取一只猫
  • 原文地址:https://www.cnblogs.com/gtea/p/13518282.html
Copyright © 2011-2022 走看看