zoukankan      html  css  js  c++  java
  • 【shell】if语句

    单分支:

    #!/bin/bash
    
    rate=$(df -h|grep vg_andon-lv_root |awk '{print $5}'| cut -d "%" -f1)
    #echo $rate
    if [ $rate -ge 8  ]
            then
                    echo "root partition is full"
    fi
    

      

    双分支:

    #!/bin/bash
    status=$(nmap -sT 192.168.69.20 |grep tcp | grep '<http>' |awk '{print $2 }') ##扫描远程目标机器开启的服务  若用ps 或者netstat不准确,会出现进行还在但是D住的状态
    echo $status
    if [ $status == open ]
            then
                    echo "apache is running at $(date)" >> /root/apache-acc.log
            else
                    service httpd start & > /dev/null
                    echo "apache is restarting at $(date)" >> /root/apache-err.log
    fi
    

    多分支:

    read -p  "please input filename:" file
    if [ -z $file ]
            then
                    echo "your input is null"
                    exit 1
    elif [ ! -e $file ]
            then
                    echo "file  not exist"
                    exit 2
    elif [ -f $file ]
            then
                    echo 'file is file'
    elif [  -d $file ]
            then
                    echo 'file is directory'
    else
            echo "file is other "
    fi
    

      

  • 相关阅读:
    c++的socket编程 tcp
    qt下载
    定义数组类型
    虚析构函数
    运算符重载
    友元函数
    const成员函数
    静态成员变量,静态成员函数
    linux安装mysql
    智能指针
  • 原文地址:https://www.cnblogs.com/paulwinflo/p/5600614.html
Copyright © 2011-2022 走看看