GNUPLOTING issue

Need assistance in troubleshooting

I have written a script using GNUPLOT . It works great when i run manually but when i put in crontab it give me library file missing. Any inputs are highly appreciated.

#!/local/tools/monitoring/gnuplot-new/bin/gnuplot

set terminal png size 1024,768
set output 'graph.png'
set title "System monitoring"
set xlabel "time"
set key outside bottom
set ylabel "%"
set ytics format '%s%c'
set yrange [1:1024**2]
set autoscale
set grid
set xdata time
set format x "%H:%M"
set timefmt "%d-%m %H:%M:%S"
set ylabel "GB"
plot "testmemory.csv" using 1:3 title "used" with lines,\
"testmemory.csv" using 1:4 title "buffered" with lines,\
"testmemory.csv" using 1:5 title "cached" with lines,\
"testmemory.csv" using 1:6 title "free" with lines

When run through crontab this gives me below error.

gnuplot: error while loading shared libraries: libwx_gtk2u_xrc-3.0.so.0: cannot open shared object file: No such file
 or directory

Well, where is this file located on your system?

In scripts I run with cron I add a line like this...

# Because cron doesn't run in your local environs
source $HOME/.bash_profile >&/dev/null

You could try something like -- export PATH=$PATH:/your/libs/path

My shell is tcsh .

It is located not in the user directory in a different /var/tmp location .

---------- Post updated at 12:54 PM ---------- Previous update was at 12:44 PM ----------

ongoto: I dont have a .bash_profile under the $HOME directory.

GNUPLOT doesnt have a lib directory to export.

drwxrwxr-x. 2 weather weather 4096 Jan 12 17:26 bin
drwxrwxr-x. 3 weather weather 4096 Jan 12 17:26 libexec
drwxrwxr-x. 5 weather weather 4096 Jan 12 17:26 share

OK. I see you are using tcsh.
If you can locate libwx_gtk2u_xrc-3.0.so.0 on your system (as Corona688 posted earlier), I was thinking you could add the path to that file in the PATH env variable, and then export it from within your script. If you can't locate that lib file, then you have other issues with gnuplot itself or your distro.

Have you tested running your script directly ( not using cron )?

ongoto

running directly works without any errors .

Gnuplot doesnt have a lib directory. This lib file is located with other application called wx-widgets . That was also exported under .cshrc file . Gnuplot uses wx-widgets as well.

OK. Then it's a cron issue.
It's not about libwx_gtk2u_xrc-3.0.so belonging to gnuplot. It's a library shared by lots of applications like you said.
So I say again...help cron find the shared library file. Cron runs in a very minimal
environment and doesn't know where to search for files needed by other applications. Gnuplot will be running as a child process of Cron and will be running in Cron's 'blind' environment.
You'll have to edit your script and see if this works or not.
On my system this file is in /usr/lib64

#!/local/tools/monitoring/gnuplot-new/bin/gnuplot

export PATH="$PATH:/usr/lib?"     ## the directory where you found libwx_gtk2u_xrc-3.0.so.

set terminal png size 1024,768
set output 'graph.png'
...
...

ongoto

I tried all different ways. The location of the path is

/local/tools/wxpython/lib
setenv LD_LIBRARY_PATH $LD_LIBRARY_PATH:/local/tools/wxpython/lib

It still give me the same error

/local/tools/monitoring/gnuplot-new/bin/gnuplot: error while loading shared libraries: libwx_gtk2u_xrc-3.0.
so.0: cannot open shared object file: No such file or directory

What operating system are you on?

Although LD_LIBRARY_PATH works on many system it does not work some (HP-UX and AIX for example)

Is anything defined in $LD_LIBRARY_PATH when you first login?

Have you considered just copying (or linking) this library into the standard lib folder (eg /usr/lib)?

Its a RedHat Linux. No root access .

Does anybody know about "set loadpath " in gnuplot .

Can you give me an example

I don't think LD_LIBRARY_PATH works that way. I don't think you can cram multiple paths into it. Just export LD_LIBRARY_PATH=/local/tools/wxpython/lib

This just saves specifying a full path for you data files eg:

plot "/home/ajayram/sar_logs/29122014/datafile" using 1:3 title "used" with lines,\
"/home/ajayram/sar_logs/29122014/datafile" using 1:4 title "buffered" with lines,\
"/home/ajayram/sar_logs/29122014/datafile" using 1:5 title "cached" with lines,\
"/home/ajayram/sar_logs/29122014/datafile" using 1:6 title "free" with lines

Can become:

set loadpath '/home/ajayram/sar_logs/29122014'

plot "datafile" using 1:3 title "used" with lines,\
"datafile" using 1:4 title "buffered" with lines,\
"datafile" using 1:5 title "cached" with lines,\
"datafile" using 1:6 title "free" with lines
1 Like

Does gnuplot scripts work under crontab

Yes I have run gnuplot from cron a number of times without issue.

Try writing a shell script /local/tools/run_plot as follows:

#!/bin/bash

export LD_LIBRARY_PATH=/local/tools/wxpython/lib

/local/tools/monitoring/plot_mem

where /local/tools/monitoring/plot_mem above is the script you posted in #1 eg:

#!/local/tools/monitoring/gnuplot-new/bin/gnuplot

set terminal png size 1024,768
...

Test the run_plot script from a terminal and ensure it works OK. Once you are happy with this you can setup your cron entry something like this:

30 23 * * * /local/tools/run_plot

The above translates to at 11:30PM every night run the script /local/tools/run_plot

Chubler_XL : Thank you so much Chubler It worked like a charm . You are awsome...