Chinaunix

标题: linux脚本检查外部服务器端口状态 [打印本页]

作者: didonglin    时间: 2009-12-29 12:17
标题: linux脚本检查外部服务器端口状态
#!/bin/bash#ts4.sh
clear
[color="#ff0000"]#脚本存放路径
PWD="/root/shell/ts"
echo `date`
[color="#ff0000"]#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"
[color="#ff0000"]#将没有运行的端口,写入到service_status这个文件中
  echo "this service is not running $x : $y" >>$PWD/service_status
  fi
  done /dev/null
if [ $? -ne 0 ]
  then
  echo "service all running"
else
  echo "some service is down"
[color="#ff0000"]#将没有运行的服务器端口,发送到你的邮箱里!
  mail -s "servie checking"
[color="#0000ff"]lyfyou@gmail.com

#ip_list文件内容:
#192.168.0.1 80
#192.168.0.12 80
#此脚本比较简单,效率比较低,不能并行的检查服务器端口!
#但是可以用于简单的外部服务器端口状态的检查
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/94754/showart_2134199.html




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2