Chinaunix首页 | 论坛 | 博客
  • 博客访问: 116899
  • 博文数量: 38
  • 博客积分: 2111
  • 博客等级: 大尉
  • 技术积分: 395
  • 用 户 组: 普通用户
  • 注册时间: 2010-02-06 13:04
文章分类

全部博文(38)

文章存档

2012年(4)

2010年(34)

我的朋友

分类: LINUX

2010-05-22 23:06:45

Linux下基于端口的服务检查脚本
#!/bin/bash
#program:Usingtostudythe[if...then...fi]program
#dsk2007/10/83:00
#content:Iwillusingthisprogramtoshowyousevices
#1.printtheprogram''sworkinyourscreen
echo "Now,the service of your Linux system will be detect!"
echo "The www,ftp,ssh,and sendmail pop3 will be detect!"
echo ""
#2.www
www=`netstat -ntlp | awk '{print $4}' | grep :80$`
if [ "$www" != "" ]; 
then
echo $www
echo "WWW is runing"
else
echo $www
echo "WWW is NOT runing"
killall -9 httpd
/usr/sbin/apachectl start
#service httpd start
fi
#3.ftp
ftp=`netstat -an | grep LISTEN | grep :21`
if [ "$ftp" != "" ]; then
echo $ftp
echo "FTP is runing "
else
echo "FTP is not runing"
killall -9 vsftpd
#service vsftpd start
/etc/init.d/vsftpd start
fi
#4.ssh
ssh=`netstat -ntlp | awk '{print $4}' | grep :22$`
#ssh=`netstat -an | grep LISTEN | grep :22`
if [ "$ssh" != "" ]; then
echo $ssh
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 "Send mail is OK!"

elif [ "$smtp" != "" ] && [ "$pop3" = "" ]; then
echo " Send mail have some problems of your pop3!"
elif [ "$smtp" = "" ] && [ "$pop3" != "" ]; then
echo "Send mail have so me problems of your smtp!"
else
echo "Send mail is NO Trunning!"
fi 
阅读(1002) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~