亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 1682 | 回復: 3
打印 上一主題 下一主題

檢測主機存在的shell,測試不通過 [復制鏈接]

論壇徽章:
1
2015年辭舊歲徽章
日期:2015-03-03 16:54:15
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2012-06-25 14:19 |只看該作者 |倒序瀏覽
在讀一本書的時候看到有一個檢測主機存在的shell腳本,并且可以生成html報告,覺得不錯就照著寫了些,書上的一些小錯誤自己也改正過來了,但是寫完后發(fā)現(xiàn)就是無法生成內(nèi)容,用echo 命令測試都可以運行到那行腳本,就是無法輸出到文件,請各位大拿來看看,腳本內(nèi)容如下
  1. #!/bin/bash
  2. shopt -s -o nounset
  3. HostList=${1:?'please inpute host ip address!'}
  4. [ ! -f $HostList ] && echo 'the file not exist' && exit 1
  5. Date=$(date +"%Y%m%d%H%M")
  6. Date_for_man=$(date +"%Y-%m-%d %Hhour %M minutes")
  7. #the counts of ping
  8. pno=2
  9. #path file to save
  10. padir="/var/www/html/pa"
  11. pahtml="$padir/index.html"
  12. pahtml_now="$padir/pa-$Date.html"

  13. #functions

  14. function html_head(){
  15.   [ ! -e $padir ] && mkdir -p $padir
  16.   cat >$pahtml_now<<HEAD
  17.   <html>
  18.   <head>
  19.   <title>ping alive check result</title>
  20.   <meta HTTP-EQUIV="Refresh" CONTENT="900">
  21.   <meta HTTP-EQUIV="Pragma" CONTENT="no-cache">
  22.   <meta HTTP-EQUIV="Content-type" content="text/html; charset=UTF8">
  23.   </head>
  24.   <body bgcolor="white">
  25.   <div align=center><font size=6><b>***my hosts monitor</b></font></div>
  26.   <div align=center>check time: $Date_for_man</div>
  27.   <p>
  28.     <table width="60%" align=center border=3>
  29.       <tr>
  30.         <td nowrap>hostname</td>
  31.         <td>IP</td>
  32.         <td nowrap>min time</td>
  33.         <td nowrap>max time</td>
  34.         <td nowrap>avg time</td>
  35.       </tr>
  36. HEAD

  37. }
  38. html_tr(){
  39.   if [ "$1" -eq "PingError" ]
  40.   then
  41.     echo "fuck tr=========================================================="
  42.     cat <<TR >>$pahtml_now
  43.     <tr>
  44.       <td>$host</td>
  45.       <td>$ip</td>
  46.       <td colspan=3><font color=red><b>cant reachable!!!</b></font></td>
  47.     </tr>
  48. TR
  49.   else
  50.     echo "fuck second tr================================================="
  51.     cat <<TR >>$pahtml_now
  52.       <tr>
  53.         <td> "$host"</td>
  54.         <td>"$ip"</td>
  55.         <td>$rt_min ms</td>
  56.         <td>$rt_max ms</td>
  57.         <td>$rt_avg ms</td>
  58.       </tr>
  59. TR

  60.     fi
  61. }
  62. html_end(){
  63.   cat >>$pahtml_now<<END
  64.     </table>
  65.   </body>
  66.   </html>
  67. END
  68.   ln -sf $pahtml_now $pahtml
  69. }
  70. #the main of the shell

  71. #check up the webpage head
  72. html_head

  73. while read ip
  74. do
  75.   rt_min=
  76.   rt_avg=
  77.   rt_max=
  78.   ping -c $pno $ip|while read r
  79.   do
  80.   echo "$r"|grep rtt
  81.   if [ $? -eq 0 ]
  82.   then
  83.     echo "fuck you hackers---------------------======================"
  84.       rt_min=$(echo $r | awk '{print $4}'|awk -F/ '{print $1}')
  85.       rt_avg=$(echo $r | awk '{print $4}'|awk -F/ '{print $2}')
  86.       rt_max=$(echo $r | awk '{print $4}'|awk -F/ '{print $3}')
  87.       html_tr $rt_min $rt_avg $rt_max
  88.    fi
  89.   done
  90.   if [ -z $rt_min ]
  91.   then
  92.     html_tr PingError
  93.   fi
  94. done<$HostList
  95. html_end
復制代碼

論壇徽章:
1
2015亞冠之吉達阿赫利
日期:2015-09-09 16:42:38
2 [報告]
發(fā)表于 2012-06-25 15:02 |只看該作者
復制代碼

論壇徽章:
1
辰龍
日期:2014-05-22 11:38:58
3 [報告]
發(fā)表于 2012-06-25 16:35 |只看該作者
1、
  1. if [ "$1" -eq "PingError" ] --> if [ "$1" == "PingError" ]
復制代碼
2、變量host未定義

論壇徽章:
1
2015年辭舊歲徽章
日期:2015-03-03 16:54:15
4 [報告]
發(fā)表于 2012-06-25 16:52 |只看該作者
回復 3# winway1988


    非常感謝,host那塊我還在研究如何轉(zhuǎn)換,后面那條語句改后就ok了
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP