web站点检查简易shell脚本

1.web样式

<h4>THE STATUS OF RS:</h4>
<meta http-equiv="refresh" content="1">
<table border="1">
<tr>
<th>NO:</th>
<th>IP:</th>
<th>STATUS</th>
</tr>

<tr>
<td bgcolor="green">0</td>
<td bgcolor="green">192.168.100.175</td>
<td bgcolor="green">up</td>
</tr>

<tr>
<td bgcolor="red">1</td>
<td bgcolor="red">192.168.100.169</td>
<td bgcolor="red">down</td>
</tr>

</table>

2.shell脚本

#!/bin/bash

rs_arr=(
    192.168.100.175
    192.168.100.169
)

model_file=./test.html

function web_result {
    rs=`curl -o /dev/null -s -w %{http_code} $1`
    return $rs
}

function new_row {
cat >> $model_file <<eof
<tr>
<td bgcolor="$4">$1</td>
<td bgcolor="$4">$2</td>
<td bgcolor="$4">$3</td>
</tr>

eof
}

function auto_html {
    web_result $2
    rs=$?
    if [ $rs -eq 200 ]
    then
    new_row $1 $2 up green
    else
    new_row $1 $2 down red
    fi
    
}

while true
do

cat >> $model_file <<eof
<h4>THE STATUS OF RS:</h4>
<meta http-equiv="refresh" content="1">
<table border="1">
<tr>                 
<th>NO:</th>        
<th>IP:</th>
<th>STATUS</th>
</tr>

eof

for ((i=0;i<${#rs_arr[*]};i++));do
    auto_html $i ${rs_arr[$i]}
done

cat >> $model_file <<eof
</table>

eof

sleep 2
>$model_file

done

#<meta http-equiv="refresh" content="1">

3.预览

 

posted on 2016-05-16 14:21  vijayfly  阅读(406)  评论(0编辑  收藏  举报

导航