I try to generate a report from a bash script which is called by a cron job on Debian 8.
The following bash script produces no html file at all when executed by cron. When executed manually via ssh it works fine.
#!/bin/bash
[...]
goaccess --keep-db-files --load-from-disk --db-path=/path/to/db/ -a -d -o /tmp/report.html
[...]
If i change the command to the following it produces an empty html file when executed by cron. Again, it works fine when executed manually.
#!/bin/bash
[...]
goaccess --keep-db-files --load-from-disk --db-path=/path/to/db/ -a -d -o html > /tmp/report.html
[...]
Did i misunderstood the -o parameter?
I installed goaccess with apt-get from deb.goaccess.io.
$ goaccess -V
GoAccess - 1.1.1.
For more details visit: http://goaccess.io
Copyright (C) 2009-2016 by Gerardo Orellana
$ goaccess -s
Built using Tokyo Cabinet On-Disk B+ Tree.
I'd try making the script executable:
chmod +x /path/goaccess_script.sh
Also, please try using absolute paths, e.g. (assuming goaccess is under: /usr/bin):
#!/bin/bash
/usr/bin/goaccess --keep-db-files --load-from-disk --db-path=/path/to/db/ -a -d -o /tmp/report.html
or you can also try _not_ using -f in goacces and pipe the data using cat:
#!/bin/bash
cat access.log | /usr/bin/goaccess --keep-db-files --load-from-disk --db-path=/path/to/db/ -a -d -o /tmp/report.html
The script is executable.
$ ls -l goaccess_script.sh
-rwxr-xr-x 1 morph morph 286 Feb 1 16:30 goaccess_script.sh
Changing the paths to absolute ones had no effect. (So still from command line both versions work, from cron the first version generates no output file and the second version an empty one).
I do not use -f in this script, just load the persistent db and generate a report.
In fact, i have another script which is also executed by cron which uses -f (but generates no report) and works fine.
#!/bin/bash
[...]
goaccess --keep-db-files --load-from-disk --db-path=/path/to/db/ -f "${LOG}"
[...]
Could it be a problem, that the db is updated by using -f when i try to generate a report, even if both commands are executed independently from each other (and the update works)?
It seems it does expect -f, I'll look into this and post back. Thanks.
same issue here.
It can't be solely that -f is expected, or else it wouldn't work from normal commandline. It only doesn't work from cron.
Thanks for reporting it as well. In this case, it does expect -f, however, cron certainly doesn't give a TTY so isatty(3) fails when no filename is passed. I'm working on some command line changes, so I'll probably add a --from-cron option before pushing out the upcoming release.
Alternative: -f is never expected (like when empty file is supplied) and in worst case output with no data is created. When storage backend is used it will yield normal results (without any changes).
--from-cron strikes me as rather ungainly.
I've pushed a commit that should fix this issue. It should now allow you to simply load data from the db files. e.g.,
goaccess --load-from-disk --keep-db-files -o /tmp/report.html
However, if you need to read new data from a pipe inside the cron, make sure to use a single dash (per convention)
cat access.log | goaccess --load-from-disk --keep-db-files -o /tmp/report.html -
Feel free to build from master to test this out, otherwise it will be pushed out in the upcoming release. Thanks.
Works perfectly fine for me now.
Thanks for your effort.