您的位置:首页 > 运维架构 > Shell

shell下一个简单的程序

2007-06-17 14:11 127 查看
#! /bin/bash
# program: Using to study the [if... then ...fi] program
# Written by :Beyond
# date: 2007/06/15
# content: I will be using this program to show your services
# 1. print the program's work in your screen
echo "Now, the services of your Linux system will be detect!"
echo "The www, ftp, ssh, and sendmail + pop3 will be detect!"
echo " "
# 2. www
www=`netstat -an|grep LISTEN|grep :80`

if [ "$www" != "" ]; then
echo "www is running"
else
echo "www is not running"
fi
# 3. ftp
ftp=`netstat -an|grep LISTEN|grep :21`
if [ "$ftp" != "" ]; then
echo "FTP is running"
else
echo "FTP is NOT running"
fi
# 4. ssh
ssh=`netstat -an|grep LISTEN|grep :22`
if [ "$ssh" != "" ]; then
echo "SSH is running"
else
echo "SSH is NOT running"
fi
# 5. sendmail + pop3
smtp=`netstat -an|grep LISTEN|grep :25`
pop3=`netstat -an|grep LISTEN|grep :110`
if [ "$smtp" != "" ] && [ "$pop3" != "" ]; then
echo "sendmail is ok!"
elif [ "$smtp" != "" ] && [ "$pop3" = "" ]; then
echo "sendmail have some problem of your pop3"
elif [ "&smtp" = "" ] && [ "$pop3" != "" ]; then
echo "sendmail have some proble of your smtp"
else
echo "sendmail is NOT running"
fi

以上程序注意两点
第一:!=前后都要用空格;
第二:`与‘的区别;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: