Raspberry Pi - Cron Jobs for Lua scripts ?
-
Hi,
I’ve got a few Lua scripts that I’d like to run periodically on my Pi, and I’ve tried to get them to run via Cron, but I can’t seem to get them to work..
Does anyone have anything similar set up that works ?
Crontab -e
I’ve tried it a couple of ways based on the forum posts I’ve read, but neither have worked..
0 0 * * * home/pi/shared/TS_cabin_graph_email_24h.lua 0 0 * * * /usr/bin/lua /home/pi/shared/TS_cabin_graph_email_24h.lua
-
Look in /var/log/messages for errors logged by the cron daemon.
You can also add output redirection to your commands to capture any output or errors and use that for debugging:
0 0 * * * /usr/bin/lua /home/pi/shared/TS_cabin_graph_email_24h.lua >/home/pi/email.log 2>&1
The
>filename
addition redirects stdout (normal output/messages) to the given filename instead of whatever default console. The2>&1
redirects file descriptor #2, which is stderr (the error output stream), to file descriptor 1, which is stdout (that normal message stream, which is now your open file). -
Thanks @toggledbits that helped, and the error in the log is below.
usr/bin/lua: /home/pi/shared/TS_cabin_graph_email_24h.lua:10: home/pi/shared/feed24h.csv: No such file or directory stack traceback: ��������[C]: in function 'assert' ��������/home/pi/shared/TS_cabin_graph_email_24h.lua:10: in main chunk ��������[C]: ?
All my scripts worked before when they were being run manually from the root folder, how do I need to update them when run by the Cron daemon ?
-
It looks like you are missing the leading "/" from the pathname of your CSV file.
-
Thanks @toggledbits that was it..
Why would it not report an error when I was running the same script manually ?
-
If I had to guess, because you were testing it while in the root (/) directory. That would be pretty much the only way it could work.