Schedule a Report to Run Via A Cron

Schedule a Report to Run via a Cron Job

Once a report is created and saved into a library’s Koha system, this report can be run via the Schedule tool or scheduled through a cron job.

The scheduling tool found in Koha currently can be used to schedule a report to run at a specific time on a specific day. Alternatively, a cron job can schedule to run a saved report on a more regular basis (daily, monthly, etc).

Cron Details

When a library has a saved report that they would like to schedule as a cron job,  a ticket can be sent to ByWater to set it up. A few more key details are required for the ByWater team to set up the cron report:

  1. What Report Number would your library like schedule via the cron?
  2. What email would you like this report emailed to when run?
  3. What format would your library like this report to be sent to your library?
  4. What email subject you would like to have to alert you of the email?
  5. In addition to all this, we will need to know when you would like this run and how often.

An Example Cron

If a library wanted report #42 scheduled to run and the library would like the report sent as a CSV with headers and emailed to library@library.com. The subject of the email should read “Weekly Circulation Report”.

An example of this cron file would be:

Info
$KOHA_CRON_PATH/runreport.pl --to=”library@library.com” --subject=”Weekly Circulation Report” --format=csv --csv-header -a 42

Parameters

A report that a library would like to be scheduled through a cron cannot have parameters. Report parameters would be a date range or shelving location selected from a dropdown list. If a library does have a report that they would like to schedule and it does have parameters, we can help with the adjustment of the report.

For example, if the report asked for a date range, the report can be manipulated to look at the last 30 days:

Info
SELECT *

FROM items

WHERE homebranch = <<Pick your branch|branches>>

Instead, the report would need to be changed to specifically say what branch the home branch should be equal to:

Info
SELECT *

FROM items

WHERE homebranch =’EAST’

If your library had a report to show new items in a date range such as this one:

Info
SELECT items.dateaccessioned,biblio.title,items.itemcallnumber

FROM items

LEFT JOIN biblioitems ON (items.biblioitemnumber=biblioitems.biblioitemnumber)

LEFT JOIN biblio ON (biblioitems.biblionumber=biblio.biblionumber)

WHERE DATE (items.dateaccessioned) BETWEEN <<Between (yyyy-mm-dd)|date>> AND <<and (yyyy-mm-dd)|date>>

ORDER BY items.itemcallnumber ASC

An adjustment could be and this would provide the library with a list of new items in the last 30 days:

Info
SELECT items.dateaccessioned,items.itemcallnumber,biblio.title,biblio.author

FROM items

LEFT JOIN biblioitems ON (items.biblioitemnumber=biblioitems.biblioitemnumber)

LEFT JOIN biblio ON (biblioitems.biblionumber=biblio.biblionumber)

WHERE DATE_SUB(CURDATE(),INTERVAL 30 DAY) <= items.dateaccessioned

ORDER BY biblio.title ASC