簡體   English   中英

RDD bash腳本變量存在問題

[英]Problem with RDD bash script variable

我正在嘗試執行以下bash腳本,但是該腳本非常失敗,任何人都可以幫我一些建議...

#!/bin/bash
FILE='/var/www/router.rrd'
OUTPUT='/var/www/router.png'
RRDTOOL='rrdtool graph'
$RRDTOOL $OUTPUT \
        -t "192.168.10.1" -v "Time in ms" \
        --start="now-1d" \
        --end="now" \
        --height="120" \
        --width="440" \
        "DEF:ping_time=$FILE:ping:AVERAGE" \
        "CDEF:shading2=ping_time,0.98,*" "AREA:shading2#F90000:router" \
        "GPRINT:ping_time:LAST:Last\: %5.2lf ms" \
        "GPRINT:ping_time:MIN:Min\: %5.2lf ms" \
        "GPRINT:ping_time:MAX:Max\: %5.2lf ms" \
        "GPRINT:ping_time:AVERAGE:Avg\: %5.2lf ms" >/dev/null


錯誤消息就像以下
 hostname:/# sh -v /var/www/router.sh FILE='/var/www/router.rrd' OUTPUT='/var/www/router.png' RRDTOOL='rrdtool graph' HOST='hello' : command not foundre_retea/ping/router.sh: line 6: "$RRDTOOL" $OUTPUT \\ : command not foundre_retea/ping/router.sh: line 7: rrdtool graph -t "192.168.10.1" -v "Time in ms" \\ /var/www/router.sh: line 8: -t: command not found --start="now-1d" \\ /var/www/router.sh: line 9: --start=now-1d: command not found --end="now" \\ /var/www/router.sh: line 10: --end=now: command not found --height="120" \\ /var/www/router.sh: line 11: --height=120: command not found --width="440" \\ /var/www/router.sh: line 12: --width=440: command not found "DEF:ping_time=$FILE:ping:AVERAGE" \\ /var/www/router.sh: line 13: DEF:ping_time=/var/www/router.:ping:AVERAGE: No such file or directory "CDEF:shading2=ping_time,0.98,*" "AREA:shading2#F90000:router" \\ /var/www/monitorizare_retea/ping/100.100.100.6_graph.sh: line 14: CDEF:shading2=ping_time,0.98,*: command not found "GPRINT:ping_time:LAST:Last\\: %5.2lf ms" \\ .... and so on 

我的第一個猜測是它給您一個錯誤,提示“找不到命令”。 如果是這種情況,那是因為您要在變量中放入命令和參數。 不要那樣做 請參閱BashFAQ / 050

此外,看起來您的腳本文件可能帶有Windows行尾。 如果是這種情況,則在其上運行dos2unix將解決該問題。

dos2unix scriptname

另一種可能是行繼續反斜杠后可能會有空白。 刪除空格字符可能會有所幫助:

sed 's/\\[[:blank:]]\+$/\\/' scriptname

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM