有时候一个个导入ip和域名很累,而且有的ip是禁ping的,需要手动查询端口,有点费时,所以写了这么个脚本,减轻工作负担,
前几行格式化域名和ip的可以根据自己的实际情况进行修改
hostmonitor需要建立对应的目录比如Root\HostMonitor\TCPorPing\
把整理好的域名(格式www.xxxx.com,不含http等),和ip(例如8.8.8.8)放入文件ip-ok.txt,
脚本判断域名是否含com,需要根据实际情况进行修改,比如含cn域名等
#!/bin/bash
DefaultFolderip="Root\\HostMonitor\\TCPorPing\\"
DefaultFolderweb="Root\\HostMonitor\\Website\\"
echo -e "\n" >> import.txt
#read -p "import URL file-path:" Infile
Infile="ip-ok.txt"
for i in `cat $Infile`
do
if [[ -n `echo $i |grep com` ]]
then
num=`grep -n $i $Infile | cut -d : -f 1`
echo ";------ test #$num------" >> import.txt
echo -e "\n" >> import.txt
echo "Method = Url" >> import.txt
echo ";--- Common properties ---" >> import.txt
echo "DestFolder = $DefaultFolderweb" >> import.txt
echo "Title = $i" >> import.txt
echo "Comment = http://$i" >> import.txt
echo "RelatedURL = " >> import.txt
echo "NamePattern = %object%" >> import.txt
echo "CmntPattern = %path%" >> import.txt
echo "ScheduleMode= Regular">> import.txt
echo "Schedule = ">> import.txt
echo "Interval = 600">> import.txt
echo "Alerts = " >> import.txt
echo "Alerts2 = " >> import.txt
echo "ReverseAlert= No" >> import.txt
echo "UnknownIsBad= Yes" >> import.txt
echo "WarningIsBad= Yes" >> import.txt
echo "UseCommonLog= Yes" >> import.txt
echo "PrivLogMode = Default" >> import.txt
echo "CommLogMode = Default" >> import.txt
echo ";--- Test specific properties ---" >> import.txt
echo "URL = http://$i" >> import.txt
echo "UrlUseMacros= No" >> import.txt
echo "is302ok = Yes" >> import.txt
echo "IgnoreUnknCA= No" >> import.txt
echo "UseFrames = No" >> import.txt
echo "UseImages = No" >> import.txt
echo -e "\n" >> import.txt
elif [ "`ping $i -c 1 | grep ttl | cut -c 1-2`" ]
then
echo $i-is-ok
num=`grep -n $i $Infile | cut -d : -f 1`
echo "; ------- Test #$num -------" >>import.txt
echo -e "\n" >> import.txt
echo "Method = Ping" >>import.txt
echo ";--- Common properties ---" >>import.txt
echo "DestFolder = $DefaultFolderip" >>import.txt
echo "Title = Ping: $i" >>import.txt
echo "Comment = Ping $i" >>import.txt
echo "RelatedURL = " >>import.txt
echo "NamePattern = %methodname%: %host%" >>import.txt
echo "CmntPattern = Ping %host%" >>import.txt
echo "ScheduleMode= Regular" >>import.txt
echo "Schedule = " >>import.txt
echo "Interval = 600" >>import.txt
echo "Alerts = " >>import.txt
echo "Alerts2 = " >>import.txt
echo "ReverseAlert= No" >>import.txt
echo "UnknownIsBad= Yes" >>import.txt
echo "WarningIsBad= Yes" >>import.txt
echo "UseCommonLog= Yes" >>import.txt
echo "PrivLogMode = Default" >>import.txt
echo "CommLogMode = Default" >>import.txt
echo ";--- Test specific properties ---" >>import.txt
echo "Host = $i" >>import.txt
echo "Timeout = 2000" >>import.txt
echo "Retries = 4" >>import.txt
echo "MaxLostRatio= 100" >>import.txt
echo "DisplayMode = time" >>import.txt
echo "DontFragment= No" >>import.txt
echo -e "\n" >> import.txt
port=`nmap $i --open -F -T4 | grep open | cut -d / -f 1 | head -n 1`
elif [ "$port" ]
then
echo $i-is-port=$port
num=`grep -n $i $Infile | cut -d : -f 1`
echo $i >> ip-ping-bad
echo "; ------- Test #$num -------" >>import.txt
echo -e "\n" >> import.txt
echo "Method = Tcp" >>import.txt
echo ";--- Common properties ---" >>import.txt
echo "DestFolder = $DefaultFolderip" >>import.txt
echo "Title = TCP $i" >>import.txt
echo "Comment = port: $port" >>import.txt
echo "RelatedURL = " >>import.txt
echo "NamePattern = TCP %host%" >>import.txt
echo "CmntPattern = port: %TargetPort%" >>import.txt
echo "ScheduleMode= Regular" >>import.txt
echo "Schedule = " >>import.txt
echo "Interval = 305" >>import.txt
echo "Alerts = " >>import.txt
echo "Alerts2 = " >>import.txt
echo "ReverseAlert= No" >>import.txt
echo "UnknownIsBad= Yes" >>import.txt
echo "WarningIsBad= Yes" >>import.txt
echo "UseCommonLog= Yes" >>import.txt
echo "PrivLogMode = Default" >>import.txt
echo "CommLogMode = Default" >>import.txt
echo ";--- Test specific properties ---" >>import.txt
echo "Host = $i" >>import.txt
echo "Port = $port" >>import.txt
else
echo $i-is-nogood
echo $i >> ip-ping-port-bad
fi
done
exit
hostmonitor
下载以后解压修改后缀为sh