最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to pass a query (postgres) to gnuplot - Stack Overflow

programmeradmin2浏览0评论

I have a table in postgres (named tempdata with columns logtime and value) From the command line (linux) I can write

echo "select logtime::timestamp , values from tempdata where logtime BETWEEN '2024-04-02 00:00:00' AND '2024-07-01 00:00:00'; " | psql -A -F$'\t' -t -q -d temp

And I get data like

2024-04-02 02:00:00    -1
2024-04-03 02:00:00    -1.5
2024-04-04 02:00:00    -1.4
2024-04-05 02:00:00    1.1
2024-04-06 02:00:00    2.7
2024-04-07 02:00:00    10.1
2024-04-08 02:00:00    11.4
2024-04-09 02:00:00    11.9
2024-04-10 02:00:00    8.6
2024-04-11 02:00:00    8.7
2024-04-12 02:00:00    9.6
2024-04-13 02:00:00    10.1
2024-04-14 02:00:00    6.6
...

I would like to put the query on the commandline for a gnuplot script so that I can write

plott.sh "select logtime::timestamp , values from tempdata where logtime BETWEEN '2024-04-02 00:00:00' AND '2024-07-01 00:00:00';"

#!/bin/bash
gnuplot <<EOF
set title 'Boo - Utetemp'
set xlabel 'Tid'
set ylabel 'Temp'
set xdata time
set timefmt '%Y-%m-%d %H:%M:%S'
set format x "%m"

set style line 12 lc rgb 'blue' lt 1 lw 1
set style line 13 lc rgb 'gray' lt 0 lw 1
set grid xtics ytics mxtics mytics ls 12, ls 13
                                                                                  
set yrange [-20:40]
set timestamp "generated on %Y-%m-%d by `whoami`"
set xtics 60*60*24*30

set datafile separator "#"

plot '< echo "$1" | psql -A -F# -t -q -d temp' using 1:2 with lines lw 3 title "test"

pause mouse
EOF

I can't get the quoting to work.

发布评论

评论列表(0)

  1. 暂无评论