脚本如下
#!/bin/bash
source /etc/bashrc >/dev/null 2>&1
source /etc/profile >/dev/null 2>&1
WEB_SITE_discovery () {
WEB_SITE=($(grep -v "^#" /home/pop/zabbix/http/http.txt))
printf '{\n'
printf '\t"data":[\n'
for((i=0;i<${#WEB_SITE[@]};++i))
{
num=$(echo $((${#WEB_SITE[@]}-1)))
if [[ "$i" != ${num} ]]
then
printf "\t\t{ \n"
printf "\t\t\t\"{#SITENAME}\":\"${WEB_SITE[$i]}\"},\n"
else
printf "\t\t{ \n"
printf "\t\t\t\"{#SITENAME}\":\"${WEB_SITE[$num]}\"}]}\n"
fi
}
}
web_site_code () {
host=$1
host_url=$(echo "$host"|awk -F ":" {'print $1}')
host_uri=$(echo ${host#http://})
if [ $host_url == http ];then
/usr/bin/curl --connect-timeout 3 -m 3 -H "Host:$host_uri" -o /dev/null -s -w %{http_code} $host_uri
else
/usr/bin/curl --connect-timeout 3 -m 3 -s -o /dev/null -k -w %{http_code} $host
fi
}
case "$1" in
web_site_discovery)
WEB_SITE_discovery
;;
web_site_code)
web_site_code $2
;;
*)
echo "Usage:$0 {web_site_discovery|web_site_code URL}"
;;
esac