zoukankan      html  css  js  c++  java
  • shell3

    例一:监控httpd是否正常运行并自动开启

    #!/bin/bash
    port=$(nmap -sT localhost | grep 'http$' |awk '{print $2}')
    riqi=$(date +"%Y-%m-%d %H:%M")
    if [ "$port" == "open" ];then
            echo "$riqi http is ok" >>/tmp/httpok.txt
    else
            /usr/local/apache2/bin/apachectl start
            echo "$riqi httpd is restart" >>/tmp/httperror.txt
    fi

    例二:多台服务器查看内存

    #!/bin/bash
    
    while read server;do
            ssh -n $server "$@" 2>&1 |sed "s/^/$server: /" &
    done
    wait

    ./bunsan2.sh free -m < servers.txt 

     例三:磁盘使用率

    #!/bin/bash
    Location=/dev/sda5
    Disk_Used_Rate=$(df -h | grep $Location | awk '{print $5}')
    echo $Disk_Used_Rate >> /var/www/cipangshiyonglv.txt

    例四:内存使用率

    #!/bin/bash
    total=$(free -m|grep Mem|awk '{print $2}')
    used=$(free -m|grep Mem|awk '{print $3}')
    echo "$used/$total"|bc -l >> /var/www/neicunshiyonglv.txt
  • 相关阅读:
    使用Delphi调用条形码控件BarTender打印标签
    我看过的书
    语法规则
    智能家居
    HAL库ADC的DMA采集
    HAL库串口中断接收
    触动心灵的一句话
    摄影技巧
    中国茶道
    单片机延时函数
  • 原文地址:https://www.cnblogs.com/bluewelkin/p/4389477.html
Copyright © 2011-2022 走看看