我正在尝试实现以下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
答案 0 :(得分:1)
我的第一个猜测是它会给你一个错误,上面写着“找不到命令”。如果是这样的话,那是因为你在一个变量中放了一个命令和一个参数。不要那样做。请参阅BashFAQ/050。
此外,您的脚本文件可能具有Windows行结尾。如果是这种情况,那么在其上运行dos2unix
将解决这个问题。
dos2unix scriptname
另一种可能性是你的线条延续反斜杠后可能有空格。删除空格字符可能会有所帮助:
sed 's/\\[[:blank:]]\+$/\\/' scriptname