我正在构建一个脚本,它检查服务器上的各种潜在问题,我有一个部分,它应该检查服务器上的所有域针对该服务器的摘要,并检查域是否指向服务器的IP。
当独立运行时,所有命令都按预期工作,但脚本输出的域仅根据一个IP进行检查。
以下是脚本的相关部分:
checkDomainDNS() {
if [ "$controlPanelVersion" == "Plesk" ]; then
serverIPs=()
for ips in $(ifconfig | grep "inet addr:" | cut -d":" -f2 | grep -Eo '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | grep -v '127.0.0.*\|0.0.0.0\|3.0.13.6');do
let count++
serverIPs[count - 1]+=$ips
done
domainsArray=()
for domain in $(MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql -u admin -Dpsa -e"SELECT dom.id, dom.name, ia.ipAddressId, iad.ip_address FROM domains dom LEFT JOIN DomainServices d ON (dom.id = d.dom_id AND d.type = 'web') LEFT JOIN IpAddressesCollections ia ON ia.ipCollectionId = d.ipCollectionId LEFT JOIN IP_Addresses iad ON iad.id = ia.ipAddressId" | cut -d"|" -f3 | awk '{print $2}'); do
let count++
domainsArray[count - 1]+=$domain
done
for domain in ${domainsArray[*]};do
dnsResult=()
for dnsResult in $(dig A $domain | grep $domain | awk '{print $5}' | grep -v "<<>>" | sed '/^$/d' | grep -v "ns");do
let count++
dnsResult[count - 1]+=$dnsResult
done
done
for i in ${serverIPs[*]};do
if [ "$dnsResult" == "$ips[*]" ]; then
echo "$domain is pointed correctly" >> $reportlog
elif [ "$dnsResult" != "$ips[*]" ]; then
echo "$domain is not pointed to $ips" >> $reportlog
fi
done
fi
}发布于 2017-05-24 18:31:20
对于任何对未来感兴趣的人,这里有一个解决方案:
checkDomainDNS() {
echo "Checking domain DNS records"
if [ "$controlPanelVersion" == "Plesk" ]; then
domainsArray=()
for domain in $(MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql -u admin -Dpsa -e"SELECT dom.id, dom.name, ia.ipAddressId, iad.ip_address FROM domains dom LEFT JOIN DomainServices d ON (dom.id = d.dom_id AND d.type = 'web') LEFT JOIN IpAddressesCollections ia ON ia.ipCollectionId = d.ipCollectionId LEFT JOIN IP_Addresses iad ON iad.id = ia.ipAddressId" | cut -d"|" -f3 | awk '{print $2}' | grep -Ev "name"); do
let count++
domainsArray[count - 1]+=$domain
done
serverIPs=()
for ips in $(ifconfig | grep "inet addr:" | cut -d":" -f2 | grep -Eo '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | grep -v '127.0.0.*\|0.0.0.0\|3.0.13.6');do
let count++
serverIPs[count - 1]+=$ips
done
for domain in ${domainsArray[*]};do
pointing="no"
dnsResult=$(dig A $domain | grep $domain | awk '{print $5}' | grep -v "<<>>" | sed '/^$/d' | grep -v "ns")
for i in ${serverIPs[*]};do
if [ "$dnsResult" == "$i" ]; then
pointing="yes"
break
fi
done
if [ $pointing == "no" ]; then
echo "$domain is not pointed towards this server" >> $reportlog
fi
done
else
echo "Checking dns only works on Plesk servers" >> $reportlog
fi
}https://stackoverflow.com/questions/44137211
复制相似问题