【问题标题】:gnuplot and Shell script read many files and create graphsgnuplot 和 Shell 脚本读取许多文件并创建图形
【发布时间】:2012-11-13 17:47:48
【问题描述】:

好的,我正在尝试为一组不同的数据文件(总共 9 个)绘制图表,所以我创建了这个 shell 脚本:

!/bin/bash
datastorenum=9
PlotOutputLoc=/root/bin/SANscripts/graphs
PlotGname=datastore
Pfext=png
PlotInputName=desktop
PNext=dat
PlotInputLoc=/root/bin/SANscripts/inputdata

write_plotgraph()
{
        i=1
        while [ $datastorenum != $i ]
        do
        gnuplot <<- EOF
        set term png large size 1200,1024
        set output "$PlotOutputLoc/$PlotGname-$i.$Pfext"
        set xdata time
        set timefmt '%H:%M'
        set style data lines
        set ylabel "IOs-Avg-%-kb"
        set ytics 50
        set autoscale
        set xlabel "Hour"
        plot "$PlotInputLoc/$PlotInputName-$i.$PNext" using 1:2 title "Total IOs", "$PlotInputLoc/$PlotInputName-$i.$PNext " using 1:3 title "Read %", "$PlotInputLoc/$PlotInputName-$i.$PNext" using 1:4 title "CacheHit %", "$PlotInputLoc/$PlotInputName-$i.$PNext" using 1:5 title "Current Kb/sec", "$PlotInputLoc/$PlotInputName-$i.$PNext" using 1:6 title "Maximum Kb/sec", "$PlotInputLoc/$PlotInputName-$i.$PNext" using 1:7 title "Current IO/sec", "$PlotInputLoc/$PlotInputName-$i.$PNext" using 1:8 title "Maximum IO/sec"

        i=$(( $i + 1 ))
        EOF
        done
}

write_plotgraph

它不工作exaclty我得到一堆这个:

     line 0: warning: Skipping unreadable file "/root/bin/SANscripts/inputdata/desktop-1.dat "
     line 0: warning: Skipping unreadable file "/root/bin/SANscripts/inputdata/desktop-1.dat "
     line 0: warning: Skipping unreadable file "/root/bin/SANscripts/inputdata/desktop-1.dat "

感谢您的帮助

好的,如果我想传递另一个函数呢?我喜欢这个函数只绘制totalio?

write_plotTios()
{
        i=1
        while [ $datastorenum != $i ]
        do
        gnuplot <<- EOF
        set term png large size 1200,1024
        set output "$PlotOutputLoc/$PlotGname-$i-$TIOS.$Pfext"
        set xdata time
        set timefmt '%H:%M'
        set style data lines
        set ylabel "IOs-Avg-%-kb"
        set ytics 50
        set autoscale
        set xlabel "Hour"
        plot "$PlotInputLoc/$PlotInputName-$i.$PNext" using 1:2 title "Total IOs"

        EOF
        i=$(( $i + 1 ))
        done
}

write_plotTios

这不起作用,我收到一条错误消息:

 /plot_datastore1t.sh: line 54: warning: here-document at line 37 delimited by end-of-file (wanted `EOF')
./plot_datastore1t.sh: line 55: syntax error: unexpected end of file

【问题讨论】:

  • 都是desktop-1.dat吗? -- 另外,gnuplot 是什么版本?
  • 没关系我必须从 EOF 中删除它现在可以使用的空格

标签: shell gnuplot scripting-language


【解决方案1】:

传递给“plot”命令的参数之一后面有一个空格。这可能被解释为文件名的一部分。删除尾随空格,看看行为是否有所改善。

您多次使用构造“$PlotInputLoc/$PlotInputName-$i.$PNext”。您可能会发现将其存储为变量而不是一遍又一遍地复制/粘贴相同的内容更不容易出错(并且更具可读性)。

此外,增加i 变量的代码位于传递给 gnuplot 的脚本中。 bash 变量 i 永远不会被更新,因此您将不断循环。尝试交换您的 EOFi=$(( $i + 1 )) 行。

【讨论】:

  • 如何为 $PlotInputLoc/$PlotInputName-$i.$PNext 定义一个变量?
  • @user1814718- 与定义任何其他 shell 变量的方式相同。尝试在您的 while 循环内但在您的 here-doc 之外添加 infile="$PlotInputLoc/$PlotInputName-$i.$PNext"
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-19
  • 2014-02-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多