开发者

Problem with RDD bash script variable

开发者 https://www.devze.com 2023-02-06 17:49 出处:网络
I have the folowing bash script i\'m trying to implement, but it fails awfully, can anyone help me with some advice...

I have the folowing bash script i'm trying to implement, but it fails awfully, can anyone help me with some advice...

#!/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="开发者_如何学Python440" \
        "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


The error mesages are like the folowing


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


My first guess is that it gives you an error that says "command not found". If that's the case it's because you're putting a command and an argument in a variable. Don't do that. Please see BashFAQ/050.

Additionally, it looks like your script file may have Windows line endings. If that's the case then running dos2unix on it will fix that.

dos2unix scriptname

Another possibility is that you may have white space after your line-continuation backslashes. Removing the white space characters may help:

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

精彩评论

暂无评论...
验证码 换一张
取 消