Menu

Run with cron and anacron

Frederic Marchal Evgeniy Yakushev

Sarg must run periodically to generate new reports.

It is usually accomplished by anacron.

To set up a task to create a daily report, create the file /etc/cron.daily/sarg:

1
2
3
#!/bin/sh

/usr/bin/sarg -d day-1 -w /tmp/sarg.daily -o /var/www/squid-reports/Daily

The above command will produce yesterday's report in /var/www/squid-reports/Daily. Adjust the path to point somewhere inside your www root.

It is important to explicitly set the temporary directory to a path dedicated to this cron job or conflict may arise if two cron jobs runs at the same time.

Similarly, the weekly report is created by /etc/cron.weekly/sarg:

1
2
3
#!/bin/sh

/usr/bin/sarg -d week-1 -w /tmp/sarg.weekly -o /var/www/squid-reports/Weekly

And the monthly report is produced by /etc/cron.monthly/sarg:

1
2
3
#!/bin/sh

/usr/bin/sarg -d month-1 -w /tmp/sarg.monthly -o /var/www/squid-reports/Monthly

Set up configuration file for anacron (/etc/anacrontab) to be sure that the task will run at the right period of time. You can read more about anacron at the man page

Don't forget to set the execution bit on these scripts:

chmod 755 /etc/cron.daily/sarg /etc/cron.weekly/sarg /etc/cron.monthly/sarg

Note that the above scripts all use the same default sarg.conf. It means the daily, weekly and monthly reports will follow the same structure. This is not mandatory. It is possible to provide distinct sarg.conf files to tailor the reports according to your needs.

For instance, you could trim down the monthly report size by disabling the bulky report types and keep more reports. In that case, edit /etc/cron.monthly/sarg to call sarg like this:

1
2
3
4
#!/bin/sh

/usr/bin/sarg -d month-1 -w /tmp/sarg.monthly -o /var/www/squid-reports/Monthly \
 -f /etc/sarg/sarg.monthly.conf

To only produce the most active users and the most visited sites reports, create /etc/sarg/sarg.montly.conf and change report_type to keep the topusers and the topsites. You can also change the number of reported entries with topuser_num and topsites_num.

To keep more reports, increase the value of lastlog.


Related

Support Requests: #37
Wiki: Build on Windows
Wiki: Table of content