Bash 获取网页内容并进行比较

Bash 获取网页内容并进行比较,bash,shell,Bash,Shell,有人能帮我/纠正我写一个shell脚本吗?以下是我正在尝试做的 获取网页内容 比较内容 如果内容相同,则返回0 如果不返回2 这是我的密码 for cluster in $CLUSTERS do for applis in $(eval echo \$${cluster}_APPLIS) do CONTENT=$(wget -q -O - "http://$server/$applis") if [ "$CONTENT" -eq 1 ]

有人能帮我/纠正我写一个shell脚本吗?以下是我正在尝试做的

  • 获取网页内容
  • 比较内容
  • 如果内容相同,则返回0
  • 如果不返回2
这是我的密码

for cluster in $CLUSTERS
do
    for applis in $(eval echo \$${cluster}_APPLIS)
    do
       CONTENT=$(wget -q -O - "http://$server/$applis")
       if [ "$CONTENT" -eq 1 ]
       then
       exit_code=0
       else
       exit_code=2
       fi
     done
done

[[ -z "$error_server" ]] && error_server="aucune"

case $exit_code in
    "2")
            echo "CRITICAL - App Version Mismatch"
            exit 2
            ;;
    "1")
            echo "WARNING - instance(s) indisponible(s)"
            exit 1
            ;;
    "0")
            echo "OK - All apps have the save version"
            exit 0
            ;;
    *)
            echo "CRITICAL - there's something wrong with this script ..."
            exit 2
            ;;
esac
任何帮助或建议都将不胜感激

问候
Fab

您可以使用diff来比较文件的两个版本。第一个变量用于获取网页的第一个版本。我不确定是应该在第一个循环内部还是外部初始化第一个循环

first=1
for cluster in $CLUSTERS
do
     for applis in $(eval echo \$${cluster}_APPLIS)
     do
        if [ $first -eq 1 ];then
             first=0
             PREV_CONTENT=$(wget -q -O - "http://$server/$applis")
        else
             CONTENT=$(wget -q -O - "http://$server/$applis")
             diff $PREV_CONTENT $CONTENT
             PREV_CONTENT=$CONTENT
             result=$?
        fi
        if [ "$result" -eq 0 ]
        then
           exit_code=0
        else
           exit_code=2
       fi
    done

完成

很抱歉标签错误,我已将其更改为正确的onethanks for you quick Response我想我在上一条消息中不是很清楚实际上我们有4台web服务器(群集)托管同一网页我需要做的是将我所有服务器的网页内容放入一个变量中,并检查它们是否匹配如果是返回0或返回2编辑脚本-不确定$(eval echo\$${cluster}\u applis)中的applis用于什么。也许可以简化。