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.

2
  • 1
    show the errors/messages thrown please, also what's in $1 Commented Feb 9 at 14:17
  • For testing/debugging, replace gnuplot with cat <<EOF You may even want cat -vet <<EOS... . Consult man cat as there may be other options that would help you see what is being passed thru. Good luck. Commented Feb 10 at 3:59

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.