How to schedule an offline report with email delivery on Debian
This article will describe how to setup a scheduled report in LogAnalyzer on a Debian Linux system. I will assume the following criterias:
- Latest Apache and PHP installed
- Latest LogAnalyzer Version installed
- UserDB System enabled and installed
- At least one configured and working report
- mail command installed ( mailutils package)
- Login into your LogAnalyzer and switch to the Admin Panel Report Modules. In my Example I have a Syslog Summary report configured showing all syslog messages from the last 24 hours. The report is saved into the file /tmp/report.html, so make sure the user you use for the cronjob has write access to the tmp directory. When you view the details of this report, you will notice the Local Report command at the bottom.
- Save this command, or copy it into a textdocument, we will need it for our cronjob later. In my case, I will use the following command:
- /usr/bin/php /home/user/www/loganalyzer/cron/cmdreportgen.php runreport syslogsummary 1.
- Run this command once in your open ssh session, to verify that the report generation works well (Check if the file /tmp/report.html is created and properly filled).
- Login into your server using ssh shell and run the crontab -e command. If you want to run the report once a day, maybe at 8 am in the morning, add the following configuration line: 0 8 * * * /usr/bin/php /home/user/www/loganalyzer/cron/cmdreportgen.php runreport syslogsummary 1 && mail -s "LogAnalyzer|Daily Syslog Summary" -a "Content-type: text/html;" firstname.lastname@example.org < /tmp/report.html
- You need to replace email@example.com with your actual email recipient.
- You are done, you should receive a daily report from now.
Report generation can take much more memory than usual php pages. If you receive an error message like this "Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 80 bytes)", you properly need to increase the php cli memory limit. To do so, edit the /etc/php5/cli/php.ini file and set memory_limit = 512M for example.