RRDTool图形命令插入变量

时间:2014-02-15 07:57:11

标签: shell rrdtool

我使用sh(1)shell脚本为日,周,月和年生成RRDTool。我的问题是,如何在不重复相同代码的情况下使此代码更有效?我试过这样但总是出错,使用尾随转义字符等:

NEWVAR="-a PNG -v "Interrupts/s" -h 130 -w 576 \
    --watermark "`hostname`:`date "+%H:%M:%S - %d/%m/%Y"`" --font TITLE:15: \
    --font LEGEND:7: --font UNIT:7: --font AXIS:5: -c CANVAS#000000 -c BACK#D8D8D8 \
    DEF:DI="$RRDFDI":DI:AVERAGE \
    CDEF:DIx=DI,8000,LT,DI,UNKN,IF \
    AREA:DIx#FFDD44:"" \
    LINE1.2:DIx#31B404:"Device Interrupts" \
    GPRINT:DIx:MIN:"Min\:%6.0lf" \
    GPRINT:DIx:AVERAGE:"Avg\:%6.0lf" \
    GPRINT:DIx:MAX:"Max\:%6.0lf" \
    GPRINT:DIx:LAST:"Cur\:%6.0lf\l""

$RRDBIN graph $NEWVAR -t "Device Interrupts Days Statistic (Interrupts)" --start -1d
$RRDBIN graph $NEWVAR -t "Device Interrupts Weeks Statistic (Interrupts)" --start -1w 
$RRDBIN graph $NEWVAR -t "Device Interrupts Months Statistic (Interrupts)" --start -1m 
$RRDBIN graph $NEWVAR -t "Device Interrupts Years Statistic (Interrupts)" --start -1y 

提前感谢!

2 个答案:

答案 0 :(得分:0)

使用for循环,类似于以下内容。

NEWVAR="-a PNG -v "Interrupts/s" -h 130 -w 576 \
  --watermark "`hostname`:`date "+%H:%M:%S - %d/%m/%Y"`" --font TITLE:15: \
  --font LEGEND:7: --font UNIT:7: --font AXIS:5: -c CANVAS#000000 -c BACK#D8D8D8 \
  DEF:DI="$RRDFDI":DI:AVERAGE \
  CDEF:DIx=DI,8000,LT,DI,UNKN,IF \
  AREA:DIx#FFDD44:"" \
  LINE1.2:DIx#31B404:"Device Interrupts" \
  GPRINT:DIx:MIN:"Min\:%6.0lf" \
  GPRINT:DIx:AVERAGE:"Avg\:%6.0lf" \
  GPRINT:DIx:MAX:"Max\:%6.0lf" \
  GPRINT:DIx:LAST:"Cur\:%6.0lf\l""

for c in d w m y ; do
  $RRDBIN graph $NEWVAR -t "Device Interrupts Days Statistic (Interrupts)" --start -1$c output.file.$c
done

答案 1 :(得分:0)

使用此代码时出现错误的最明显原因是您未能在NEWVAR声明中转义嵌入式双引号。

您无法同时生成所有三个图形;您编写它的方式是最佳的,但您需要在NEWVAR声明中修复对嵌入式引号的使用。你还需要双重冒出冒号和\ l endof line sequence ...

  

NEWVAR =“ - 一个PNG -v \”中断/ s \“ - h 130 -w 576 \     --watermark \“”`hostname`“:”`date'+%H:%M:%S - %d /%m /%Y'`“\” - 字体标题:15:\     --font LEGEND:7: - 不要UNIT:7: - 刚刚AXIS:5:-c CANVAS#000000 -c BACK#D8D8D8 \
    DEF:DI = $ RRDFDI:DI:AVERAGE \
    CDEF:DIx = DI,8000,LT,DI,UNKN,IF \     区域:DIx#FFDD44:\“\”\
    LINE1.2:DIx#31B404:'设备中断'\\     GPRINT:DIx:MIN:'Min \:%6.0lf'\     GPRINT:DIx:AVERAGE:'Avg \:%6.0lf'\\     GPRINT:DIx:MAX:'Max \:%6.0lf'\     GPRINT:DIX:LAST: '姜黄素\:%6.0lf \ L'“