Chinaunix首页 | 论坛 | 博客
  • 博客访问: 515791
  • 博文数量: 230
  • 博客积分: 5726
  • 博客等级: 大校
  • 技术积分: 2765
  • 用 户 组: 普通用户
  • 注册时间: 2009-04-21 13:51
文章分类

全部博文(230)

文章存档

2011年(33)

2010年(40)

2009年(157)

分类: LINUX

2009-12-29 12:17:12

#!/bin/bash#ts4.sh
clear
#脚本存放路径
PWD="/root/shell/ts"
echo `date`
#ip_list 文件是需要检查的服务器和服务器端口
ls $PWD/ip_list 2> /dev/null
if [ $? -eq 0 ]
  then
  echo "this is file is ture!"
  NUM=`wc -l $PWD/ip_list | awk '{print $1}'`

  while read LINE
  do
  echo $LINE >$PWD/temp.ip
  x=`awk '{printf $1}' $PWD/temp.ip`
  y=`awk '{printf $2}' $PWD/temp.ip`
  result=`nmap -sT $x -p $y | grep open`
  if [ "$result" != "" ]; then
  echo "this service is running $x : $y"
  else
  echo "this service is not running $x : $y" 
#将没有运行的端口,写入到service_status这个文件中
  echo "this service is not running $x : $y" >>$PWD/service_status

  fi
  done<$PWD/ip_list

else
  echo "this file is no!"
fi

ls $PWD/service_status 2> /dev/null
if [ $? -ne 0 ]
  then
  echo "service all running"
else
  echo "some service is down"
#将没有运行的服务器端口,发送到你的邮箱里!
  mail -s "servie checking" < $PWD/service_status -- -f longy

  echo #?
fi

rm -rf $PWD/temp.ip
rm -rf $PWD/service_status
exit 0

#ip_list文件内容:
#192.168.0.1 80
#192.168.0.12 80
#此脚本比较简单,效率比较低,不能并行的检查服务器端口!
#但是可以用于简单的外部服务器端口状态的检查
阅读(1881) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~