graph-cli
graph-cli copied to clipboard
Graph not working when run in script via cronjob ?
Hi
I have a Lua script that I’m trying to run via crontab below.
# m h dom mon dow command
0 8 * * * /usr/bin/lua /home/pi/shared/TS_cabin_graph_watts_12h.lua >/home/pi/shared/watts.log 2>&1
1 8 * * * /usr/bin/lua /home/pi/shared/TS_cabin_graph_temp_12h.lua >/home/pi/shared/temp.log 2>&1
The whole script does a lot of different things, but here’s the specific os.execute graph request below.
print("Start : graph command")
local x = os.execute('graph /home/pi/shared/feed12hr.csv -y 9,10 --ylabel Temp --title CabinTemp --figsize 1600x1000 --output /home/pi/shared/cabingraph12hr.png')
print(x)
print("End : graph command")
When I run it manually at the command line it works fine - see output below.
Start : graph command
/usr/local/lib/python2.7/dist-packages/pandas/plotting/_converter.py:129: FutureWarning: Using an implicitly registered datetime converter for a matplotlib plotting method. The converter was registered by pandas on import. Future versions of pandas will require you to explicitly register matplotlib converters.
To register the converters:
>>> from pandas.plotting import register_matplotlib_converters
>>> register_matplotlib_converters()
warnings.warn(msg, FutureWarning)
0
End : graph command
but when I check the logs after running it via a cronjob, it fails and reports the following
Part 4
Start : graph command
32512
End : graph command
Any idea of the cause and required fix ?
Hm, so when you execute the lua script manually it works, but executing the lua script from cron it does not?
My first thought is a permissions issue.
Yes, exactly it’s very strange
I was thinking it could be something like permissions, but I have no idea how that works with cron ? Any ideas/suggestions?
I found your SO post: https://stackoverflow.com/questions/66885493/lua-error-running-script-via-crontab-with-os-execute-command-exit-code-325
Did you try the suggested answer? Seems plausible to me that cron has a minimal PATH
Thanks - I had not noticed someone had responsed..
Using ‘whereis graph’, it returns the following.
graph: /usr/local/bin/graph
Which suggests I would need to update the graph part of my Lua code to this, I’ll give it a go..
print("Start : graph command")
local x = os.execute('/usr/local/bin/graph /home/pi/shared/feed12hr.csv -y 9,10 --ylabel Temp --title CabinTemp --figsize 1600x1000 --output /home/pi/shared/cabingraph12hr.png')
print(x)
print("End : graph command")
Well I tried the full path, and while it still works when I run it manually (as pi user) - it sadly still doesn’t work via crontab, although this time I now receive a 256 error/exit code, which at least suggests something has changed,
Also rather than call it with os.execute(), I also tried it with io.popen , which is another option with Lua, but that gave me a very specific graph error - any ideas ?.
Start : graph command
Traceback (most recent call last):
File "/usr/local/bin/graph", line 11, in <module>
sys.exit(main.main())
File "/usr/local/lib/python2.7/dist-packages/graph_cli/main.py", line 10, in main
graphs = get_graph_defs(args)
File "/usr/local/lib/python2.7/dist-packages/graph_cli/graph.py", line 171, in get_graph_defs
graphs, globals = read_chain(args)
File "/usr/local/lib/python2.7/dist-packages/graph_cli/graph.py", line 194, in read_chain
data = stdin.buffer.read()
AttributeError: 'file' object has no attribute 'buffer'
End : graph command
which ties back to this one (I think) - https://github.com/mcastorina/graph-cli/issues/39
Correct, that AttrbitueError is a python2 issue. I'll have a fix for it today
v0.1.11 should fix the attribute error now.
Great many thanks - How best do I update my Pi with the latest version ?
pip install graph-cli --upgrade
Assuming you used pip originally. If you used pip2 then upgrade with pip2
Assuming you used
piporiginally. If you usedpip2then upgrade withpip2
Great many thanks - How can I find out which version of pip I used originally?
You can see what was installed with pip using pip freeze
pip freeze | grep graph-cli
That will also tell you the version installed.
Great, ok, I’ve done that, and this is what it returned..
pi@raspberrypi:~ $ pip freeze | grep graph-cli
graph-cli==0.1.7
How do I work out the pip version ?
That means it was installed with pip, so you can go ahead and do
pip install graph-cli --upgrade
Thanks - not sure if you can help with this, but for some reason every attempt I’ve made to do the upgrade it fails on my raspberry pi - it gets part way through, but then I’m exited out of the terminal and it returns the following.
Connection closed with error: connection reset by peer
Sounds like a network issue.. I can't help you there 😕
I’ve google’d the hell out of this and no luck fixing it. - so I’m going to try and do a whole new Rasp Pi build and install graph_cli from scratch.
Wow, I forgot how long it takes to install :-)
This part took ages, why is that ?
Building wheels for collected packages: pandas, subprocess32, kiwisolver
Running setup.py bdist_wheel for pandas ...
Hi, quick update, the Installation claimed to have been successful, but I now receive a new error whenever I run graph..
I’ve posted it as a new issue.. https://github.com/mcastorina/graph-cli/issues/47
pandas is a pretty big data processing library that needs to be compiled (also relies on numpy). That's the reason for the long install time.