Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2235989
  • 博文数量: 533
  • 博客积分: 8689
  • 博客等级: 中将
  • 技术积分: 7046
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-26 10:00
文章分类

全部博文(533)

文章存档

2024年(2)

2023年(4)

2022年(16)

2014年(90)

2013年(76)

2012年(125)

2011年(184)

2010年(37)

分类: LINUX

2014-01-10 10:59:51




#!/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
#此脚本比较简单,效率比较低,不能并行的检查服务器端口!
#但是可以用于简单的外部服务器端口状态的检查



阅读(585) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~