I'm trying to get this simple bash script to work within a cronjob. It's used to generate static nginx webserver statistic pages using GoAccess.

I tried everything I know to resolve this issue, it just won't work as a cronjob. It's executed perfectly in console. It's even working as cronjob when I remove the call to goaccess (e.g. put an echo there to see if the call is built correctly).

Any help on this? The script runs for every file but the resulting files only contain the "how to use" instructions from goaccess which appear when you call it without arguments.

System is a vServer running Debian 6.0. I use GoAccess 0.5 and nginx 1.2.1

Here's the script:



for logfile in $_logfiles; do
        # All these commands work flawless
        #echo "$logfile" >> /home/debug.log
        #echo "$_curfilename" >> /home/debug.log
        #echo "goaccess -a -f $logfile > /srv/www/stats/${_curfilename}.html" >> /home/debug.log;

        # This one fails
        goaccess -a -f "${logfile}" > "/srv/www/stats/${_curfilename}.html";

Here's the crontab line for once an hour (i used * * * * * for debugging):

0 * * * * /bin/bash /home/run_webstats_update.sh

Error output in cron.log:

/USR/SBIN/CRON[26099]: (root) CMD (/bin/bash /home/update_webstats.sh)
/USR/SBIN/CRON[26098]: (CRON) error (grandchild #26099 failed with exit status 1)
  • 2
    You might want to hardcode the relative path for "goaccess", example: /usr/local/bin/goaccess. Cron may not be familiar with the same paths that you use. – Tim Jun 22 '12 at 19:10
  • I assume you have tried specifying SHELL=/bin/bash in crontab to totally eliminate dash. Does appending make any difference? Now you use >, try >>. – Jari Laamanen Jun 22 '12 at 20:05
  • Redirect standard error somewhere by adding something like 2>/some/file to the command line. If goaccess is printing an error, it should end up in that file. – James Sneeringer Jun 22 '12 at 21:55
  • 1
    Check your local mail for the error messages. Cron sends error output from jobs in a local mail. (This implies that you've set up local mail properly; if you haven't, do this then try again.) – Gilles Jun 23 '12 at 0:18
  • Thanks for the hints. I'll try your tips as well, but at the moment I got it working using Josh's answer. – Manuel Jun 23 '12 at 10:31

This should do it. Just make sure you got the right paths. BTW, GoAccess is nifty.



for logfile in $_logfiles; do
   cat "${logfile}" | goaccess -a > "/srv/www/stats/${_curfilename}.html"

You could even parse compressed data files:

zcat -f access.log* | goaccess -a > "/srv/www/stats/${_curfilename}.html"

  • I've modified the PATH variable, by setting the variable like you did any exisitng directory was removed. By appending a directory to the path you increase the change that goaccess is found. It's still better to use the full path to goaccess (or any other tool) in a script though. – Bram Jun 23 '12 at 9:34
  • Using the "cat" command did the trick. Thanks a lot! – Manuel Jun 23 '12 at 10:29
  • Just stumbled upon this problem. Not being able to use the -f flag with GoAccess from within cron just cost me an hour of my life. – Jeff Sep 2 '13 at 18:21

What is goaccess? it is not a standard command nor a function you have already defined, you need to declare it in the beginning or source the file that has the function

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.