[root@hddcluster2 script]
SITES=(
"http://10.0.0.2"
"http://www.163.com"
)
NOTICE_EMAIL=
'me@example.com'
DATE=$(
date
+%Y-%m-%d
' '
%H:%M:%S)
function
SENDMAIL()
{
echo
$1
}
function
CHECK_SITE_CODE()
{
for
site
in
${SITES[*]};
do
printf
"start to access ${site}\n"
site_code=$(curl -o
/dev/null
-s -w %{http_code}
"${site}"
)
printf
"$(date '+%Y-%m-%d %H:%M:%S')\n"
printf
"site http code return:${site_code}\n\n"
if
[ ${site_code} != 200 ];
then
echo
"Subject: ${site} can't access ${DATE}"
| SENDMAIL ${NOTICE_EMAIL}
fi
done
}
function
MAX_ACCESS_TIME()
{
for
site
in
${SITES[*]};
do
site_access_time=$(curl -o
/dev/null
-s -w
"time_connect: %{time_connect}\ntime_starttransfer: %{time_starttransfer}\ntime_total: %{time_total}"
"${site}"
)
echo
"$site"
time_total=${site_access_time
printf
"site access time\n${time_total}\n"
var=${time_total%.*}
if
[ ${var} -
ge
2 ];
then
echo
"Subject: ${site} can't access ${DATE} "
| SENDMAIL ${NOTICE_EMAIL}
fi
done
}
function
SEND_MAIL()
{
/usr/local/python
}
echo
"check the httpd code"
CHECK_SITE_CODE
echo
"-----------------------------------------"
\n
echo
"check max access time"
MAX_ACCESS_TIME