linux shell编程if条件判断

# 多个条件判断 (if ... elif ... elif ... else) 分多种不同情况运行
if [ 条件判断式一 ]; then
	当条件判断式一成立时,可以进行的命令工作内容;
elif [ 条件判断式二 ]; then
	当条件判断式二成立时,可以进行的命令工作内容;
else
	当条件判断式一与二均不成立时,可以进行的命令工作内容;
fi

#!/bin/bash

echo "check the apache ssh ftp status......"


apache_status=$(netstat -tunl | grep ":80")
if [ "$apache_status" != "" ];then
        echo "apache is running"
fi


ssh_status=$(netstat -tunl | grep ":22")
if  [ "$ssh_status" != "" ];then
        echo "ssh is running"
fi


ftp_status=$(netstat -tunl | grep ":21")
if  [ "$ftp_status" != "" ];then
        echo "ftp is running"
fi

你可能感兴趣的:(linux)