0

in a script bash, here is what I do:

  1. Every 3 minutes, I create binary data for one minute to get a waterfall. The following command creates two files: plot.met and plot.bin.

rtl_power_fftw -f 144100000:146100000 -b 500 -n 100 -g 350 -p 0 -e 1m -q -m plot

  1. Then, I parse the met file and I link the content of the .met file (number of bins, number of scans, etc.) with two variables: nb_bins and nb_scans.

  2. And I create my waterfall as a png image:

        gnuplot -persist << EOF
            plot 'plot.bin' binary array=${nb_bins}x${nb_scans} format='%float' with image
            set term png
            set output 'plot.png'
            replot
            set term wxt 
EOF

The problem is that my plot.png image is modified during the first start of my code (bash script.sh), but then, my code is running automatically with crontab * * * * * /my/directory/script.sh and the image is then updated without any content (size of 0 bytes). While my files plot.met and plot.bin are refreshed without any problem.

I tried different things already: using gnuplot -e "" instead of gnuplot persist, without set term wxt, trying different times for crontab, killing the gnuplot process, but nothing worked yet and I don't have any other ideas. Thanks a lot for your help!

10
  • cron usually runs in a different environment. Are you sure all the variables are correctly set in the cron job? Commented Nov 3, 2023 at 10:35
  • My variables are declared in my bash script and not in my cron job. Does it mean that I have to declare them in both files? Commented Nov 3, 2023 at 10:43
  • Without seeing how they are declared, I can't help you much. Note that environment variables like $PATH are also affected. Commented Nov 3, 2023 at 10:48
  • input="/my/directory/more_scans.met" n=1 while read -r "LINE$n"; do n=$((n+1)) done < "$input" for ((i=1; i<n; i++)); do nb_bins="LINE1" nb_scans="LINE2" ... done nb_freq=$(echo "${!nb_freq}" | grep -oE '[0-9]+([.][0-9]+)?') Commented Nov 3, 2023 at 10:51
  • The declaration is only valid for the script bash Commented Nov 3, 2023 at 10:53

1 Answer 1

0

Without knowing your detailed arrangement, here is a suggestion for letting gnuplot run in an endless loop (which you can stop by pressing x). My default terminal is also wxt.

The example script will plot a function every second with some random factor with a random color just for illustration purpose. Replace it with your plotting command.

I'm not sure if you need a PNG for something else or whether simply displaying the graph in a wxt terminal might be enough.

Actually, I have a simple setup in a lab where a program appends temperature and humidity every minute to a daily file. I run gnuplot completely independently from that and let it display the content of the file every minute.

Not sure if this solves your problem.

Script:

### endless loop for replotting after some waiting time
reset session

stop = 0
bind x "stop=1"

f(x) = sin(x)/x

while (!stop) {

    set title strftime("%Y-%m-%d %H:%M:%S",time(0))
    b0 = rand(0)+1
    plot f(x*b0) w l lw 3 lc rgb 0x1000000*rand(0)
    
    pause 1  # number of seconds
}
### end of script

Result: (screenshot from wxt terminal)

enter image description here

Addition:

If you simply need to create a PNG file from the data which is currently available, create a script file, e.g. plot.gp

set term png
set output 'plot.png'
plot 'plot.bin' binary array=${nb_bins}x${nb_scans} format='%float' with image
set output   # can be skipped if gnuplot will be terminated

and call gnuplot from console or bash. I wouldn't use -persist (which is maybe causing your problems), but then gnuplot will be started and ended again and again.

gnuplot -c "plot.gp"
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the idea, indeed I need to save my picture as a PNG file because then I send it to a web server, that's why I need to have the picture refreshed every X minutes. Right now, I have a picture on the web server that changes 1 time (when I do bash script.sh) and that do not change anymore after that. But at the end, I don't use wxt, I just wanted to go back to the default terminal wxt in case it is needed the next time my script launches the gnuplot command.
Okay, after the Addition it works! So I tried first to export my global variables from the bash script file to the gnuplot one but I think it was not working because I got the error "not enough columns for this style". So then I rearranged my gnuplot persist like yours, with set term png, set output 'plot.png', the plot and set output and it works perfectly! So it was just the position of the elements that were causing the problem :x a small error that I could have avoided... thanks^^

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.