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