Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graph not working when run in script via cronjob ? #45

Open
nodecentral opened this issue Mar 31, 2021 · 19 comments
Open

Graph not working when run in script via cronjob ? #45

nodecentral opened this issue Mar 31, 2021 · 19 comments

Comments

@nodecentral
Copy link

nodecentral commented Mar 31, 2021

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 ?

@mcastorina
Copy link
Owner

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.

@nodecentral
Copy link
Author

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?

@mcastorina
Copy link
Owner

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

@nodecentral
Copy link
Author

nodecentral commented Mar 31, 2021

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") 

@nodecentral
Copy link
Author

nodecentral commented Apr 1, 2021

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) - #39

@mcastorina
Copy link
Owner

Correct, that AttrbitueError is a python2 issue. I'll have a fix for it today

@mcastorina
Copy link
Owner

v0.1.11 should fix the attribute error now.

@nodecentral
Copy link
Author

Great many thanks - How best do I update my Pi with the latest version ?

@mcastorina
Copy link
Owner

pip install graph-cli --upgrade

Assuming you used pip originally. If you used pip2 then upgrade with pip2

@nodecentral
Copy link
Author

Assuming you used pip originally. If you used pip2 then upgrade with pip2

Great many thanks - How can I find out which version of pip I used originally?

@mcastorina
Copy link
Owner

You can see what was installed with pip using pip freeze

pip freeze | grep graph-cli

That will also tell you the version installed.

@nodecentral
Copy link
Author

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 ?

@mcastorina
Copy link
Owner

That means it was installed with pip, so you can go ahead and do

pip install graph-cli --upgrade

@nodecentral
Copy link
Author

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

@mcastorina
Copy link
Owner

Sounds like a network issue.. I can't help you there 😕

@nodecentral
Copy link
Author

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.

@nodecentral
Copy link
Author

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 ...

@nodecentral
Copy link
Author

nodecentral commented Apr 4, 2021

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.. #47

@mcastorina
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants