0
votes

The top part of the following script works great, the .dat files are created via the MySQL command, and work perfectly with gnu plot (via the command line). The problem is getting the bottom (gnuplot) to work correctly. I'm pretty sure I have a couple of problems in the code: variables and the array. I need to call each .dat file (plot), have the title in the graph (from title in customers.txt)and name it (.png)

any guidance would be appreciated. Thanks a lot -- 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 example line- 192.168.179.222 pacsdbgibsonia "Gibsonia Animal Hospital"

Error output.....

+ for database in '"${databases[@]}"'
+ gnuplot
     line 0: warning: Skipping unreadable file ".dat"
     line 0: No data in plot
+ exit 0
1
dbName is undefined outside while loop. - ztik

1 Answers

2
votes

to initialise databases array:

databases=()

to append $dbName.dat to databases array:

databases+=("$dbName.dat")

to retrieve dbName, remove suffix pattern .dat

dbName=${database%.dat}