zoukankan      html  css  js  c++  java
  • 跑Linux内存占用率的shell脚本

    #!/bin/bash
    ################################################################
    #       Mem Used Script
    #       eg. ./mem.sh 10G & to start testing
    #       eg. ./mem.sh stop  to stop testing and clear env
    #       update: 2020-04-21  Nobita
    ################################################################
    num=$1
    user=`whoami`
     
    start()
    {
    if [ -d /tmp/memory ];then
            echo "the dir "/tmp/memory" is already exist!, use it." >> mem.log
    else
            sudo mkdir /tmp/memory
            mount -t tmpfs -o size=$num tmpfs /tmp/memory
    fi
    dd if=/dev/zero of=/tmp/memory/block >> mem.log 2>&1
    }
     
    stop()
    {
     
    rm -rf /tmp/memory/block
    umount /tmp/memory
    rmdir /tmp/memory
    if [ -d /tmp/memory ];then
            echo "Do not remove the dir "/tmp/memory", please check "
    else
            echo "clear env is done!"
    fi
    }
    main()
    {
    if [ $num == 'stop' ];then
            stop
    elif [ $user != "root" ];then
            echo "please use the "root" excute script!"
            exit 1
    else
            start
    fi
    }
     
    if [ $# = 2 -o $# = 1 ];then
            main
    else
            echo 'Usage: <./mem.sh 10G &> to start  or <./mem.sh stop>  to clear env'
    fi
  • 相关阅读:
    openstack配置增加节点
    OpenStack基本应用
    OpenStack
    zabbix(客户端自动发现,自动添加)
    zabbix 邮件报警(以网易邮箱为例)
    数据库原理
    网页设计与制作
    质量管理与质量保证
    比较行政学【0717】
    企业管理学[9053]
  • 原文地址:https://www.cnblogs.com/chenshengkai/p/12745583.html
Copyright © 2011-2022 走看看