Solved Goaccess Script is not executed via cron

hbauer

Member

Reaction score: 4
Messages: 28

I am trying to setup a shell script that creates goaccess reports with cron. When running the script manually it is working. I can see that the shell script is started via cron in cron.log.

Code:
root@p:~ # more /etc/crontab
# /etc/crontab - root's crontab for FreeBSD
#
# $FreeBSD$
#
SHELL=/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
#
#minute hour    mday    month   wday    who     command

51 * * * * root /root/create-goaccess-stats-hb.sh
Unfortunately something within the script is not working. Nothing is written to cron.log or a logfile that the crontask should write to

Any ideas what is wrong with this shell script for cron?
Code:
#!/bin/sh

/usr/bin/more /usr/local/www/www-hb/logs/nx-access.log* | /usr/local/bin/goaccess -  --log-format='%h %^[%d:%t %^]%^"%r" %s %b "%R" "%u" %^' --date-format=%d/%b/%Y --time-format=%T -o  /var/data/www-hb-goaccess/index.html
 
OP
hbauer

hbauer

Member

Reaction score: 4
Messages: 28

switching from /usr/bin/more to /bin/cat doesnt help :-(
 

SirDice

Administrator
Staff member
Administrator
Moderator

Reaction score: 12,696
Messages: 39,295

What does /var/log/cron tell you? Also check root's mail, any errors or output from cron scripts are mailed to the user that ran the cronjob.
 
OP
hbauer

hbauer

Member

Reaction score: 4
Messages: 28

/var/log/cron doesnt tell anything. I finally found some errors in roots spam folder :-(

The error is goaccess specific but it seems that when telling goaccess to use the input via the pipe within cron it is causing trouble to use the rest of the configuration. I will try to find a different way to pipe the logs into goaccess
 

SirDice

Administrator
Staff member
Administrator
Moderator

Reaction score: 12,696
Messages: 39,295

The error is goaccess specific but it seems that when telling goaccess to use the input via the pipe within cron it is causing trouble to use the rest of the configuration. I will try to find a different way to pipe the logs into goaccess
There might be some issues because a cronjob doesn't run on a TTY. I'd just feed the logs to goaccess as an argument, there shouldn't be a need to pipe anything.

goaccess /usr/local/www/www-hb/logs/nx-access.log* will do what you expect it to do.
 
OP
hbauer

hbauer

Member

Reaction score: 4
Messages: 28

I have now moved all configurations to the default goaccess.conf in /usr/local/etc/goaccess.conf. The script is reduced to
Code:
#!/bin/sh

/usr/local/bin/goaccess -p /usr/local/etc/goaccess/goaccess.conf -o /var/data/www-hb-goaccess/index.html /usr/local/www/www-hb/logs/nx-access.log*
Commandline is working. Cron not

The error is telling me that goaccess from cron doesnt like some formats that are configured in the goaccess.conf.

I currently believe its something wrong with goaccess. I will try to change th subject
 

covacat

Aspiring Daemon

Reaction score: 316
Messages: 642

try setting locale in the script
set |grep ^LC_ and set those in the script
 
OP
hbauer

hbauer

Member

Reaction score: 4
Messages: 28

no luck :-(

Code:
 set |grep ^LC_
LC_ALL=C.UTF-8


Code:
 more /root/create-goaccess-stats-hb.sh
#!/bin/sh
LC_ALL=C.UTF-8
echo $LC_ALL
/usr/local/bin/goaccess -p /usr/local/etc/goaccess/goaccess.conf -o /var/data/www-rc-goaccess/index.html /usr/local/www/www-rc/logs/nx-access.log*
 

SirDice

Administrator
Staff member
Administrator
Moderator

Reaction score: 12,696
Messages: 39,295

The error is telling me that goaccess from cron doesnt like some formats that are configured in the goaccess.conf.
What is the exact error you're getting?
 

covacat

Aspiring Daemon

Reaction score: 316
Messages: 642

no luck :-(

Code:
 set |grep ^LC_
LC_ALL=C.UTF-8


Code:
 more /root/create-goaccess-stats-hb.sh
#!/bin/sh
LC_ALL=C.UTF-8
echo $LC_ALL
/usr/local/bin/goaccess -p /usr/local/etc/goaccess/goaccess.conf -o /var/data/www-rc-goaccess/index.html /usr/local/www/www-rc/logs/nx-access.log*
export LC_ALL
 

SirDice

Administrator
Staff member
Administrator
Moderator

Reaction score: 12,696
Messages: 39,295

export LC_ALL
Or
Code:
#!/bin/sh

env LC_ALL=C.UTF-8 /usr/local/bin/goaccess -p /usr/local/etc/goaccess/goaccess.conf -o /var/data/www-rc-goaccess/index.html /usr/local/www/www-rc/logs/nx-access.log*
 
OP
hbauer

hbauer

Member

Reaction score: 4
Messages: 28

THATS IT!!!

Code:
#!/bin/sh
LC_ALL=C.UTF-8
export LC_ALL

/usr/local/bin/goaccess -p /usr/local/etc/goaccess/goaccess.conf -o /var/data/www-hb-goaccess/index.html /usr/local/www/www-hb/logs/nx-access.log*

IS WORKING !!!

Thank you very much
 
Top