0

以下脚本的顶部效果很好,.dat 文件是通过 MySQL 命令创建的,并且可以与 gnu plot 完美配合(通过命令行)。问题是让底部(gnuplot)正常工作。我很确定我在代码中有几个问题:变量和数组。我需要调用每个 .dat 文件(绘图),在图中有标题(来自customers.txt 中的标题)并将其命名为(.png)

任何指导将不胜感激。非常感谢——RichR

#!/bin/bash
set -x

databases=""
titles=""
while read -r ipAddr dbName title; do
    dbName=$(echo "$dbName" | sed -e 's/pacsdb//')
    rm -f "$dbName.dat"
    touch "$dbName.dat"
    databases=("$dbName.dat")
    titles="$titles $title"
    while read -r period; do
    mysql -uroot -pxxxx -h "$ipAddr" "pacsdb$dbName" -se \
    "SELECT COUNT(*) FROM tables WHERE some.info BETWEEN $period;" >> "$dbName.dat"
    done < periods.txt
done < customers.txt

for database in "${databases[@]}"; do
gnuplot << EOF
        set a bunch of options
        set output "/var/www/$dbName.png"
        plot "$dbName.dat" using 2:xtic(1) title "$titles"
EOF 
done
exit 0

customers.txt 示例行 - 192.168.179.222 pacsdbgibsonia “Gibsonia Animal Hospital”

错误输出.....

+ for database in '"${databases[@]}"'
+ gnuplot
     line 0: warning: Skipping unreadable file ".dat"
     line 0: No data in plot
+ exit 0
4

1 回答 1

2

初始化数据库数组:

databases=()

将 $dbName.dat 附加到数据库数组:

databases+=("$dbName.dat")

要检索 dbName,请删除后缀模式 .dat

dbName=${database%.dat}
于 2013-10-02T20:22:20.433 回答