脚本以自动测试网站是否可用


18

我是一个孤独的Web开发人员,拥有自己的Centos VPS,为我的客户托管了一些小型网站。今天,我发现我的httpd服务已停止(没有明显的原因-但这是另一个线程)。我重新启动了它,但是现在我需要找到一种方法,如果再次发生,可以通过电子邮件和/或SMS通知我-我不喜欢它,当我的客户打电话告诉我他们的网站不起作用时!

我知道可能有很多不同的可能性,包括服务器监视软件。我认为我真正需要的是一个脚本,该脚本可以作为我的开发主机(永久在我的办公室中运行)的cron作业运行,该脚本尝试从生产服务器加载页面,如果页面在30分钟内未加载,几秒钟后,它会向我发送电子邮件或短信。我在shell脚本编写方面非常垃圾,因此是这个问题。

任何建议将不胜感激。


3
您是否看过Nagios或Pingdom?他们内置了该功能(嗯,Pingdom内置了SMS,而Nagios需要一些时间,但是有可能)
涂抹

不,我现在要看一下,谢谢您的建议。
Xoundboy 2011年

Answers:


13

好吧...最简单的脚本,我可以这样写:

/usr/bin/wget "www.example.com" --timeout 30 -O - 2>/dev/null | grep "Normal operation string" || echo "The site is down" | /usr/bin/mail -v -s "Site is down" your@e-mail.address

将其添加到cron中:

* * * * * /usr/bin/wget "www.example.com" --timeout 30 -O - 2>/dev/null  | grep "Normal operation string" || echo "The site is down" | /usr/bin/mail -v -s "Site is down" your@e-mail.address

但是,告诉您问题出在哪儿太简单了。

UPD:现在,这种单线检查页面上的特定字符串(“正常操作字符串”),该字符串仅在正常操作时出现。

UPD2:一种在电子邮件中发送错误页面的简单方法:

/usr/bin/wget "www.example.com" --timeout 30 -O - 2>/dev/null | grep "Normal operation string" || /usr/bin/wget "www.example.com" --timeout 30 -O - 2>/dev/null | /usr/bin/mail -v -s "Site is down" your@e-mail.address

缺点是在第一次测试失败的情况下会重新请求页面。这次请求可能成功,您将不会看到错误。当然,可以存储输出并将其作为附件发送,但这会使脚本更加复杂。


看起来很有趣...。因此,如果该页面在30秒内未加载,就可以正确发送电子邮件了吗?如果页面加载但显示了错误消息,该怎么办?如何调整它以测试特定的输出?
Xoundboy 2011年

更新了答案。但是脚本仍然不会向您发送错误。
HUB

-嗨,谢谢您的更新-我正在努力使其在我的机器上运行-我认为命令的邮件部分无法正常工作-现在没有时间进行故障排除,但是会尝试明天还是尽快。
Xoundboy 2011年

好吧...尝试手动运行邮件程序并检查输出。另请参见“ / var / log / mail”以获取结果。检查防火墙设置(应允许访问远程端口25)。
HUB

8

看一下这个脚本:

curl是用于获取URL的命令行实用程序。该脚本检查退出代码($?表示shell脚本中最新命令的退出代码),如果它不是0,则报告错误(退出代码0通常表示成功)。如HUB的答案所述,||当第一个命令失败时,您也可以仅在命令行上运行第二个命令。

确定状态后,您只需要向自己发送一些邮件即可。这是一个使用mail命令从外壳脚本发送邮件的示例,假设您要测试的框具有SMTP设置:

顺便说一句:如果您不擅长使用Shell脚本,请不要将自己局限于Shell脚本。您可以使用ruby脚本,php脚本,服务器可以运行的任何类型的脚本!只需#!/path/to/executable在脚本开头添加该行-例如:

#!/usr/bin/php


感谢您的输入-一会儿,我将立即检查该解决方案。会尽快回报。
Xoundboy 2011年

6

检查此脚本。它会检查网站列表,并在出现问题时发送电子邮件(到电子邮件列表)(http响应不同于200)。该脚本会创建一个.temp文件来“记住”哪个网站最后一次检查失败,因此您不会收到多封电子邮件。网站再次运行时,.temp文件将被删除。

#!/bin/bash
# list of websites. each website in new line. leave an empty line in the end.
LISTFILE=/scripts/isOnline/websites.lst
# Send mail in case of failure to. leave an empty line in the end.
EMAILLISTFILE=/scripts/isOnline/emails.lst

# `Quiet` is true when in crontab; show output when it's run manually from shell.
# Set THIS_IS_CRON=1 in the beginning of your crontab -e.
# else you will get the output to your email every time
if [ -n "$THIS_IS_CRON" ]; then QUIET=true; else QUIET=false; fi

function test {
  response=$(curl --write-out %{http_code} --silent --output /dev/null $1)
  filename=$( echo $1 | cut -f1 -d"/" )
  if [ "$QUIET" = false ] ; then echo -n "$p "; fi

  if [ $response -eq 200 ] ; then
    # website working
    if [ "$QUIET" = false ] ; then
      echo -n "$response "; echo -e "\e[32m[ok]\e[0m"
    fi
    # remove .temp file if exist.
    if [ -f cache/$filename ]; then rm -f cache/$filename; fi
  else
    # website down
    if [ "$QUIET" = false ] ; then echo -n "$response "; echo -e "\e[31m[DOWN]\e[0m"; fi
    if [ ! -f cache/$filename ]; then
        while read e; do
            # using mailx command
            echo "$p WEBSITE DOWN" | mailx -s "$1 WEBSITE DOWN" $e
            # using mail command
            #mail -s "$p WEBSITE DOWN" "$EMAIL"
        done < $EMAILLISTFILE
        echo > cache/$filename
    fi
  fi
}

# main loop
while read p; do
  test $p
done < $LISTFILE

将以下行添加到crontab config($ crontab -e)

THIS_IS_CRON=1
*/30 * * * * /path/to/isOnline/checker.sh

在Github上可用


2

我知道上述所有脚本都是您所要求的,但是我建议您查看monit,因为如果apache关闭,它将向您发送电子邮件,但也会重新启动(如果关闭)。


这看起来也很有趣-我将尝试寻找时间尽快进行检查,并回馈我的发现。
Xoundboy 2011年

1

我建议为此。他们的免费服务使您可以检查1个站点,但这仅是检查1个服务器的全部。如果您有iPhone,他们可以免费向您发送消息,因此您无需从他们处购买SMS积分,并且可以使用多种设置。我的系统将在2次重试(10分钟)后通知我,此后每10分钟停机。很棒,因为它还会检查表明站点已关闭的HTTP 500消息。如果失败,它将立即从其他位置的其他服务器再次检查您的站点。如果那一次失败了,那将触发您对如何/何时收到通知的偏好。


我真的很喜欢这种Pingdom服务-只需设置免费帐户并测试支票和SMS到我的捷克手机号码-都可以使用-暂时可以尝试一下,看看效果如何。
Xoundboy 2011年

可悲的是,Pingdom似乎不再提供免费套餐。最便宜的计划是每月14.95美元。
本·约翰逊

您可以使用cronitor.io-他们提供了一个免费的网站进行检查,并且可以将通知推送到电子邮件,闲置邮件或任何其他Webhook。
黎兹

pingdom的另一种替代方法是uptimerobot,5分钟的监视间隔和免费计划中的50个受监视的网站。它也可以轻松地与松弛和电报集成(除了推送,短信或电子邮件通知等)。
trolologuy

1

以上内容略有变化。

用于每10秒检查网站是否可用的脚本。将失败的尝试记录到siteuptime.txt文件中,以便以后查看(或在excel中绘制)。

#!/bin/bash
# Check site every 10 seconds, log failed connection attempts in siteuptime.txt
while true; do
echo "Checking site...";
/usr/bin/wget "http://www.mysite" --timeout 6 -O - 2>/dev/null | grep "My String On page" || echo "The site is down" | date --iso-8601=seconds >> siteuptime.txt;
sleep 10;
done;

1
#!/bin/bash

################Files to be created before starting exicution####################
# sudo apt-get install alsa alsa-utils                                                  #
# mkdir -p $HOME/scripts                                                                    #
# touch $HOME/scripts/URL_File                                                              #
# touch $HOME/scripts/alert_Data                                                            #
# touch /tmp/http                                                                               #
# touch /tmp/http_file                                                                        #
# Download alert.wav file and copy it into $HOME/scripts directory                #
#################################################################################

####### checking existing process and creating temp files for URLs###############
Proc=$(ps -ef | grep http_alerts.sh | wc -l)
number=$(ps -ef | grep http_alerts.sh)
if [ $Proc -gt 3 ]
then
    echo "Script Already Running. Please kill PID($number) and restart"
else
FILE="$HOME/scripts/URL_File"
myfileval=1
while read -r line_read; do
    echo $line_read > /tmp/http_file
    File_name=$(cat /tmp/http_file | awk -v "val=$myfileval" 'NR==val {print $2}')
    File_name_val=$(ls /tmp/$File_name 2>/dev/null | wc -l)
    File_name_val0=0
    if [ $File_name_val -eq $File_name_val0 ]
    then 
        touch /tmp/$File_name
    fi
done < "$FILE"
####### checking existing process and finding temp files for URLs###############
echo "############ SCRIPT STARTED WORKING ################"
echo "############ SCRIPT STARTED WORKING ################" >> $HOME/scripts/alert_Data
echo " " >> $HOME/scripts/alert_Data
####### Continues Loop to check the URLs without break           ###############
while true
do
#######  Reading file URLs                                       ###############
### URL formate- http or https URL; 
### remarks; if domain name 0 else 1; 
### domain without proto(http/https); 
### Public_1; Public_2; ########
filename="$HOME/scripts/URL_File" ### file path
while read -r line; do
        echo $line > /tmp/http ### inserting each line data to temparary file
### Checking Internet Connection #######
        while true
        do
            if ping -q -c 1 -W 1 8.8.8.8 >/dev/null; 
        then   
            break
        else 
            echo "You are not connected to internet. Please wait"
            sleep 5  
        fi
        done 
### Checking Internet Connection #######
    myval=1
    i=$((i+1))
    j=7
    k=$(shuf -i 1-${j} -n 1)
    l=30
    i=$(($l+$k)) ##### Color code 31 to 37
    echo ""
    echo ""
    URL=$(cat /tmp/http |  awk -v "val=$myval" 'NR==val {print $1}')  ### 1st paramater from file. example: http://myabcd.com
    Server_State=$(cat /tmp/http |  awk -v "val=$myval" 'NR==val {print $2}') ### 2nd paramater from file. example: this_is_myabcd_site
    val3=$(cat /tmp/http | awk -v "val=$myfileval" 'NR==val {print $3}') ### 3rd paramater from file. 0 or 1
    val4=$(cat /tmp/http | awk -v "val=$myfileval" 'NR==val {print $4}') ### 4rd paramater from file. example: myabcd.com
    val5=$(cat /tmp/http | awk -v "val=$myfileval" 'NR==val {print $5}') ### 5th paramater from file. example: 123.123.123.111
    val6=$(cat /tmp/http | awk -v "val=$myfileval" 'NR==val {print $5}') ### 6th paramater from file. example: 123.123.123.222
echo "\e[1;${i}m-------------------------------------------------------------------\e[0m"
echo "\e[1;${i}m| Cheking URL :   $URL                             \e[0m"
echo "\e[1;${i}m-------------------------------------------------------------------\e[0m" >> $HOME/scripts/alert_Data
echo "\e[1;${i}m| Cheking URL :   $URL                             \e[0m" >> $HOME/scripts/alert_Data
DATA=$(date) ### time stamp 
code=$(curl -s -o /dev/null -w "%{http_code}" $URL) ### getting URL response code
if [ $code -eq 200 -o $code -eq 301 -o $code -eq 302 ] ### checking with sucessful response codes
then 
    echo "\e[1;${i}m-------------------------------------------------------------------\e[0m"
    echo "\e[1;${i}m| UP TIME     :   $DATA                            \e[0m"
    echo "\e[1;${i}m-------------------------------------------------------------------\e[0m"
    echo "\e[1;${i}m| Server State:   $Server_State                    \e[0m" 
    echo "\e[1;${i}m-------------------------------------------------------------------\e[0m" 
    echo "\e[1;${i}m-------------------------------------------------------------------\e[0m" >> $HOME/scripts/alert_Data
    echo "\e[1;${i}m| UP TIME     :   $DATA                            \e[0m" >> $HOME/scripts/alert_Data
    echo "\e[1;${i}m-------------------------------------------------------------------\e[0m" >> $HOME/scripts/alert_Data
    echo "\e[1;${i}m| Server State:   $Server_State                    \e[0m" >> $HOME/scripts/alert_Data
    echo "\e[1;${i}m-------------------------------------------------------------------\e[0m" >> $HOME/scripts/alert_Data
elif [ $code -eq 404 -o $code -eq 500 ] ### checking with error response codes
then 
    echo "\e[1;${i}m-------------------------------------------------------------------\e[0m"
    echo "\e[1;${i}m| URL IS DOWN :   $URL                             \e[0m"
    echo "\e[1;${i}m-------------------------------------------------------------------\e[0m"
    echo "\e[1;${i}m| DOWN TIME   :   $DATA                            \e[0m"
    echo "\e[1;${i}m-------------------------------------------------------------------\e[0m"
    echo "\e[1;${i}m| HTTP TIME   :   $code                            \e[0m"
    echo "\e[1;${i}m-------------------------------------------------------------------\e[0m"
    echo "\e[1;${i}m| Server State:   $Server_State                    \e[0m"
    echo "\e[1;${i}m-------------------------------------------------------------------\e[0m" >> $HOME/scripts/alert_Data
    echo "\e[1;${i}m| URL IS DOWN :   $URL                             \e[0m" >> $HOME/scripts/alert_Data
    echo "\e[1;${i}m-------------------------------------------------------------------\e[0m" >> $HOME/scripts/alert_Data
    echo "\e[1;${i}m| DOWN TIME   :   $DATA                            \e[0m" >> $HOME/scripts/alert_Data
    echo "\e[1;${i}m-------------------------------------------------------------------\e[0m" >> $HOME/scripts/alert_Data
    echo "\e[1;${i}m| HTTP CODE   :   $code                            \e[0m" >> $HOME/scripts/alert_Data
    echo "\e[1;${i}m-------------------------------------------------------------------\e[0m" >> $HOME/scripts/alert_Data
    echo "\e[1;${i}m| Server State:   $Server_State                    \e[0m" >> $HOME/scripts/alert_Data
    echo "\e[1;${i}m-------------------------------------------------------------------\e[0m" >> $HOME/scripts/alert_Data
    aplay $HOME/scripts/alert.wav 2> /dev/null ### On failure buzzer will sound
    /usr/bin/truncate -s 0 /tmp/$Server_State  ### truncate the file with server failure count data
    echo " Dear Admin Team \n The $URL is DOWN for the State $Server_State. The HTTP response code is $code " | mail -s "$Server_State is down" -a "From: from@mail.com" yourmail1@mail.com,yourmail2@mail.com >> /dev/null   ### On failure sending mail
elif [ $code -eq 000 ]
then
   LNUM=$(cat /tmp/$Server_State | wc -l)
   LNUM0=0
   oval=0
    if [ $val3 -eq $oval ] ### checking Domain or Public IP
    then
    dname=$(nslookup $val4 | awk '/^Address: /{print $2}') ### getting domain name Public IPs
        for dname_i in $dname
        do
            dname_url="http://$dname_i/" ### Making Public IP as http URL
            dname_code=$(curl -s -o /dev/null -w "%{http_code}" $dname_url)  ### getting public IP response
            if [ $dname_code -eq 200 -o $dname_code -eq 301 -o $dname_code -eq 302 ]  ### If success response
            then
            echo "\e[1;${i}m---------------------------------------------------\e[0m"
            echo "\e[1;${i}m| UP TIME     :   $DATA                            \e[0m"
            echo "\e[1;${i}m---------------------------------------------------\e[0m"
            echo "\e[1;${i}m| Server State:   $Server_State                    \e[0m" 
            echo "\e[1;${i}m---------------------------------------------------\e[0m" 
            echo "\e[1;${i}m---------------------------------------------------\e[0m" >> $HOME/scripts/alert_Data
            echo "\e[1;${i}m| UP TIME     :   $DATA                            \e[0m" >> $HOME/scripts/alert_Data
            echo "\e[1;${i}m---------------------------------------------------\e[0m" >> $HOME/scripts/alert_Data
            echo "\e[1;${i}m| Server State:   $Server_State                    \e[0m" >> $HOME/scripts/alert_Data
            echo "\e[1;${i}m---------------------------------------------------\e[0m" >> $HOME/scripts/alert_Data
            else #### if did not success response 
                    if [ $LNUM -eq $LNUM0 ] ### If no failure count, then add the failure count from 1
                        then
                        echo "$Server_State 0" > /tmp/$Server_State
                        else 
                        ALT=$(cat /tmp/$Server_State |  awk -v "val=$myval" 'NR==val {print $2}')  ### server failure count
                        ALT5=5
                        if [ $ALT -eq $ALT5 ] ### If failure count is 5 then alert with sound and send mail
                        then
                        echo "\e[0;${i}m---------------------------------------------------\e[0m"
                        echo "\e[0;${i}m| URL IS DOWN :   $URL                             \e[0m"
                        echo "\e[0;${i}m---------------------------------------------------\e[0m"
                        echo "\e[0;${i}m| DOWN TIME   :   $DATA                            \e[0m"
                        echo "\e[0;${i}m---------------------------------------------------\e[0m"
                        echo "\e[0;${i}m| HTTP CODE   :   $code                            \e[0m"
                        echo "\e[0;${i}m---------------------------------------------------\e[0m"
                        echo "\e[0;${i}m| Server State:   $Server_State                    \e[0m"
                        echo "\e[0;${i}m---------------------------------------------------\e[0m" >> $HOME/scripts/alert_Data
                        echo "\e[0;${i}m| URL IS DOWN :   $URL                             \e[0m" >> $HOME/scripts/alert_Data
                        echo "\e[0;${i}m---------------------------------------------------\e[0m" >> $HOME/scripts/alert_Data
                        echo "\e[0;${i}m| DOWN TIME   :   $DATA                            \e[0m" >> $HOME/scripts/alert_Data
                        echo "\e[0;${i}m---------------------------------------------------\e[0m" >> $HOME/scripts/alert_Data
                        echo "\e[0;${i}m| HTTP CODE   :   $code                            \e[0m" >> $HOME/scripts/alert_Data
                        echo "\e[0;${i}m---------------------------------------------------\e[0m" >> $HOME/scripts/alert_Data
                        echo "\e[0;${i}m| Server State:   $Server_State                    \e[0m" >> $HOME/scripts/alert_Data
                        echo "\e[0;${i}m---------------------------------------------------\e[0m" >> $HOME/scripts/alert_Data
                        aplay $HOME/scripts/alert.wav 2> /dev/null  ### On failure buzzer will sound
                        /usr/bin/truncate -s 0 /tmp/$Server_State   ### truncate the file with server failure count data
                        echo " Dear Admin Team \n The $URL is DOWN for the State $Server_State. The HTTP response code is $code " | mail -s "$Server_State is down" -a "From: from@mail.com" yourmail1@mail.com,yourmail2@mail.com >> /dev/null   ### On failure sending mail 
                        else
                        ALT=$((ALT+1)) ### increase server failure count
                        echo "$Server_State $ALT" > /tmp/$Server_State
                        fi
                        fi
                    fi
                    done
                    oval1=1
                    elif [ $val3 -eq $oval1 ]   ### No domain name backup public IPs are there
                    then
                        if [ "$val5" != "" ]  ### first Public IP of diffrent ISP
                        then 
                        dname_url="http://$val5/" ### making URL with public IP
                        dname_code=$(curl -s -o /dev/null -w "%{http_code}" $dname_url)   ### getting response code
                        if [ $dname_code -eq 200 -o $dname_code -eq 301 -o $dname_code -eq 302 ] ### validating response code
                        then
                        echo "\e[1;${i}m---------------------------------------------------\e[0m"
                        echo "\e[1;${i}m| UP TIME     :   $DATA                            \e[0m"
                        echo "\e[1;${i}m---------------------------------------------------\e[0m"
                        echo "\e[1;${i}m| Server State:   $Server_State                    \e[0m" 
                        echo "\e[1;${i}m---------------------------------------------------\e[0m" 
                        echo "\e[1;${i}m---------------------------------------------------\e[0m" >> $HOME/scripts/alert_Data
                        echo "\e[1;${i}m| UP TIME     :   $DATA                            \e[0m" >> $HOME/scripts/alert_Data
                        echo "\e[1;${i}m---------------------------------------------------\e[0m" >> $HOME/scripts/alert_Data
                        echo "\e[1;${i}m| Server State:   $Server_State                    \e[0m" >> $HOME/scripts/alert_Data
                        echo "\e[1;${i}m---------------------------------------------------\e[0m" >> $HOME/scripts/alert_Data
                        elif [ "$val6" != "" ]  ### second Public IP of diffrent ISP
                        then 
                        dname_url="http://$val6/" ### making URL with public IP
                        dname_code=$(curl -s -o /dev/null -w "%{http_code}" $dname_url)   ### getting response code
                        if [ $dname_code -eq 200 -o $dname_code -eq 301 -o $dname_code -eq 302 ] ### validating response code
                        then
                        echo "\e[1;${i}m---------------------------------------------------\e[0m"
                        echo "\e[1;${i}m| UP TIME     :   $DATA                            \e[0m"
                        echo "\e[1;${i}m---------------------------------------------------\e[0m"
                        echo "\e[1;${i}m| Server State:   $Server_State                    \e[0m" 
                        echo "\e[1;${i}m---------------------------------------------------\e[0m" 
                        echo "\e[1;${i}m---------------------------------------------------\e[0m" >> $HOME/scripts/alert_Data
                        echo "\e[1;${i}m| UP TIME     :   $DATA                            \e[0m" >> $HOME/scripts/alert_Data
                        echo "\e[1;${i}m---------------------------------------------------\e[0m" >> $HOME/scripts/alert_Data
                        echo "\e[1;${i}m| Server State:   $Server_State                    \e[0m" >> $HOME/scripts/alert_Data
                        echo "\e[1;${i}m---------------------------------------------------\e[0m" >> $HOME/scripts/alert_Data
                        else
                        if [ $LNUM -eq $LNUM0 ]
                        then
                        echo "$Server_State 0" > /tmp/$Server_State
                        else
                        ALT=$(cat /tmp/$Server_State |  awk -v "val=$myval" 'NR==val {print $2}')  ### server failure count
                        ALT5=5
                        if [ $ALT -eq $ALT5 ]
                        then
                        echo "\e[0;${i}m---------------------------------------------------\e[0m"
                        echo "\e[0;${i}m| URL IS DOWN :   $URL                             \e[0m"
                        echo "\e[0;${i}m---------------------------------------------------\e[0m"
                        echo "\e[0;${i}m| DOWN TIME   :   $DATA                            \e[0m"
                        echo "\e[0;${i}m---------------------------------------------------\e[0m"
                        echo "\e[0;${i}m| HTTP CODE   :   $code                            \e[0m"
                        echo "\e[0;${i}m---------------------------------------------------\e[0m"
                        echo "\e[0;${i}m| Server State:   $Server_State                    \e[0m"
                        echo "\e[0;${i}m---------------------------------------------------\e[0m" >> $HOME/scripts/alert_Data
                        echo "\e[0;${i}m| URL IS DOWN :   $URL                             \e[0m" >> $HOME/scripts/alert_Data
                        echo "\e[0;${i}m---------------------------------------------------\e[0m" >> $HOME/scripts/alert_Data
                        echo "\e[0;${i}m| DOWN TIME   :   $DATA                            \e[0m" >> $HOME/scripts/alert_Data
                        echo "\e[0;${i}m---------------------------------------------------\e[0m" >> $HOME/scripts/alert_Data
                        echo "\e[0;${i}m| HTTP CODE   :   $code                            \e[0m" >> $HOME/scripts/alert_Data
                        echo "\e[0;${i}m---------------------------------------------------\e[0m" >> $HOME/scripts/alert_Data
                        echo "\e[0;${i}m| Server State:   $Server_State                    \e[0m" >> $HOME/scripts/alert_Data
                        echo "\e[0;${i}m---------------------------------------------------\e[0m" >> $HOME/scripts/alert_Data
                        aplay $HOME/scripts/alert.wav 2> /dev/null
                        /usr/bin/truncate -s 0 /tmp/$Server_State
                        echo " Dear Admin Team \n The $URL is DOWN for the State $Server_State. The HTTP response code is $code " | mail -s "$Server_State is down" -a "From: from@mail.com" yourmail1@mail.com,yourmail2@mail.com >> /dev/null   ### On failure sending mail
                        else
                        ALT=$((ALT+1))
                        echo "$Server_State $ALT" > /tmp/$Server_State
                        fi
                    fi
                fi
            fi
        fi
    fi
fi
sleep 4
vl=1
pdate=$(ls -l $HOME/scripts/alert_Data | awk -v "val=$vl" 'NR==val {print $7}')   ### getting file created day
ddate=$(date | awk -v "val=$vl" 'NR==val {print $3}') ### current day count
if [ $pdate -gt $ddate ]  ### validating file created day and current
then 
d=`date +%m-%d-%Y`
mv $HOME/scripts/alert_Data $HOME/scripts/alert_Data$d  ### taking backup of existing file with time stamp
touch $HOME/scripts/alert_Data ### creating new file
fi
done < "$filename"
done
fi
#######################################################################################################################################################
#The content of $HOME/scripts/URL_File is as below
#Please remove "#" and Headline titles. Each parameter will be read by the difrence of spaces.
#URLoftheSite           Remarks         Domain(0)/IPstatus(1)   Domain_name(without protocol)   PublicIP_1      PublicIP_2  
#http://myexamplesite.com   this_is_myexamplesite   1           myexamplesite.com       123.123.123.111     123.123.123.222

0

由于您的VPS上有许多网站,因此我建议您可以使用网站监视网站(例如host-tracker.com)开设帐户。除了提醒您网站是否关闭以外,它们还为您提供每周,每月和每年的正常运行时间。Whish对于管理和性能非常有帮助。


0

这个怎么样:

#!/bin/bash
/etc/init.d/httpd status
if [[ $? == 3 ]]; then
   echo "Httpd is down `date`" | mail support@example.com
   exit 1
fi
exit 0

1
我喜欢这种简单性,但这不会测试该网站是否可以通过Internet获得。该服务可能正在运行,但实际上并未为客户端提供服务。我曾经爱上了那个。
John Gardeniers

2
同意,但是,如果要确保可以从Internet访问它,则必须通过Internet进行测试。即使在服务器的外部网络接口上运行wget也不是Internet可以访问它的准确测试。
frogstarr78 2011年
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.