3

In my root crontab (sudo crontab -e) I have this job to generate Go Access log reports:

* * * * * goaccess /var/log/nginx/access.log -o /home/me/some/path/report.html

It works just fine. I also have this job to generate a report that spans multiple days:

* * * * * sudo zcat -f /var/log/nginx/access.log* | goaccess -o /home/me/some/path/bigger_report.html

Cron says it runs but it doesn't actually seem to run. I've looked around and tried a bunch of things (including following the list here - https://stackoverflow.com/a/22744360/3761310) but still can't get this job to run. If I run the command myself it generates the file as expected. I also tried just the part before the pipe, outputting into a txt file and that worked. So I suspect it's some interaction with Go Access.

When I enabled cron logging, this is what it says when that job runs:

(root) CMD (sudo zcat -f /var/log/nginx/access.log* | goaccess -o /home/me/some/path/bigger_report.html)

Any pointers? Thanks!

DukeSilver
  • 458
  • 1
  • 6
  • 22
  • this may help https://askubuntu.com/questions/173924/how-to-run-a-cron-job-using-the-sudo-command – 0xedb Sep 22 '20 at 03:28
  • @theBashShell thanks for the response. I actually started my night there, which is why I'm putting these commands in `sudo crontab -e`. Am I missing something from that post? – DukeSilver Sep 22 '20 at 03:33
  • You claim it's specific to `goaccess` and/or `zcat`, is that actually the case? What did you observe to conclude that "it doesn't actually seem to run"? When and why are you using `sudo`? Is that relevant to this problem even? – Ulrich Eckhardt Sep 22 '20 at 19:43

1 Answers1

8

You need to let goaccess know you are piping data using the -. e.g.,

* * * * * sudo zcat -f /var/log/nginx/access.log* | goaccess - -o /home/me/some/path/bigger_report.html
Mike
  • 96
  • 1
  • 1
    thanks, that seems to have set it straight. I didn't know that was the case, since the command worked fine when run manually, but for anyone in the future, the relevant doc seems to be here under "Multiple Log Files" - https://goaccess.io/man#examples – DukeSilver Sep 22 '20 at 19:53
  • 1
    This saved the day. @DukeSilver of course, but why spend 10 minutes on reading documentation instead of trying out random things for 2 hours to fix the issue? I always prefer the later. – cherouvim Jun 15 '21 at 07:12
  • same here. It's so odd that it works without this when on the command line and not as a cron job. I'd love to understand why that is. – kevincw01 Jun 10 '23 at 16:42