Chapter 16. Cron Jobs

Table of Contents

1. Cron Jobs
1.1. Search
1.2. Circulation
1.3. Patrons
1.4. Notices
1.5. In Processing/Book Cart
1.6. Catalog
1.7. OPAC
1.8. System Administration
1.9. Acquisitions
1.10. Deprecated scripts

1. Cron Jobs

The locations below assume a dev install which puts the crons in misc/, if you have a standard install you may want to look in bin/ for these files if you cannot find them in misc/

1.1. Search

1.1.1. Rebuild Index

Script path: misc/migration_tools/

Does: Updates Zebra indexes with recently changed data.

Required by: Zebra

Frequency suggestion: every x minutes, (between 5-15 minutes) depending on performance needs

1.2. Circulation

1.2.1. Holds Queue

Script path: misc/cronjobs/holds/

Does: Updates holds queue report

Required by: Holds Queue Report

Frequency suggestion: every 1-4 hours


  • A script that should be run periodically if your library system allows borrowers to place on-shelf holds. This script decides which library should be responsible for fulfilling a given hold request.

    It's behavior is controlled by the system preferences StaticHoldsQueueWeight and RandomizeHoldsQueueWeight.

    If you do not want all of your libraries to participate in the on-shelf holds fulfillment process, you should list the the libraries that *do* participate in the process here by inputting all the participating library's branchcodes, separated by commas ( e.g. "MPL,CPL,SPL,BML" etc. ).

    By default, the holds queue will be generated such that the system will first attempt to hold fulfillment using items already at the pickup library if possible. If there are no items available at the pickup library to fill a hold, will then use the list of libraries defined in StaticHoldsQueueWeight. If RandomizeHoldsQueueWeight is disabled ( which it is by default ), the script will assign fulfillment requests in the order the branches are placed in the StaticHoldsQueueWeight system preference.

    For example, if your system has three libraries, of varying sizes ( small, medium and large ) and you want the burden of holds fulfillment to be on larger libraries before smaller libraries, you would want StaticHoldsQueueWeight to look something like "LRG,MED,SML".

    If you want the burden of holds fulfillment to be spread out equally throughout your library system, simply enable RandomizeHoldsQueueWeight. When this system preference is enabled, the order in which libraries will be requested to fulfill an on-shelf hold will be randomized each time the list is regenerated.

    Leaving StaticHoldsQueueWeight empty is contraindicated at this time. Doing so will cause the build_holds_queue script to ignore RandomizeHoldsQueueWeight, causing the script to request hold fulfillment not randomly, but by alphabetical order. Perl Documentation


my $biblionumber_aref = GetBibsWithPendingHoldRequests();

Return an arrayref of the biblionumbers of all bibs that have one or more unfilled hold requests.


my $requests = GetPendingHoldRequestsForBib($biblionumber);

Returns an arrayref of hashrefs to pending, unfilled hold requests on

the bib identified by $biblionumber. The following keys are present in each hashref:

  • biblionumber

  • borrowernumber

  • itemnumber

  • priority

  • branchcode

  • reservedate

  • reservenotes

  • borrowerbranch

The arrayref is sorted in order of increasing priority.


my $available_items =


Returns an arrayref of items available to fill hold requests for the bib identified by $biblionumber. An item is available to fill a hold

request if and only if:

  • it is not on loan

  • it is not withdrawn

  • it is not marked notforloan

  • it is not currently in transit

  • it is not lost

  • it is not sitting on the hold shelf


MapItemsToHoldRequests($hold_requests, $available_items);




Query system preferences to get ordered list of branches to use to fill hold requests.

1.2.2. Expired Holds

Script path: misc/cronjobs/holds/

Does: By default, this cron job will only automatically cancel holds where the user has set an expiration date. If the library is using the ExpireReservesMaxPickUpDelay and ExpireReservesMaxPickUpDelayCharge preferences then this script will also cancel holds that have been sitting on the hold shelf for too long and will (if the library does) charge the patron for not picking up the hold.

Frequency suggestion: daily

1.2.3. Unsuspend Holds

Script path: misc/cronjobs/holds/

Does: This script checks to find holds that should no longer be suspended and removes the suspension if the AutoResumeSuspendedHolds preference is set to 'allow'. This puts the patron back in to the queue where they were when the hold was suspended.

Frequency suggestion: daily

1.2.4. Fines

Script path: misc/cronjobs/

Required by: finesMode system preference

Frequency suggestion: nightly

1.2.5. Long Overdues

Script path: misc/cronjobs/

Does: allows one to specify delays for changing items to different lost statuses, and optionally charge for them using the replacement price listed on the item record.

Frequency suggestion: nightly Perl Documentation

NAME cron script to set lost statuses on overdue materials. Execute without options for help.

1.3. Patrons

1.3.1. Anonymize Patron Data

Script path: misc/cronjobs/

Does: Used to anonymize patron data. This will remove borrowernumbers from circulation history so that the stats are kept, but the patron information is removed for privacy reasons.

1.4. Notices

1.4.1. Message Queue

Script path: misc/cronjobs/

Does: processes the message queue to send the check out, check in and hold filled emails and SMS message to users and sends outgoing emails to patrons. requires EnhancedMessagingPreferences to be on

Frequency suggestion: 1-4 hours


Item due and Advanced due notices are controlled by the advance_notices cron.

1.4.2. Advanced Notice

Script path: misc/cronjobs/

Does: prepares "pre-due" notices and "item due" notices for patrons who request them prepares notices for patrons for items just due or coming due soon. requires EnhancedMessagingPreferences to be on

Frequency suggestion: nightly


This script does not actually send the notices. It queues them in the message queue for later Perl Documentation

NAME - cron script to put item due reminders into message queue


./ -c

or, in crontab: 0 1 * * * -c


This script prepares pre-due and item due reminders to be sent to patrons. It queues them in the message queue, which is processed by the cronjob. The type and timing of the messages can be configured by the patrons in their "My Alerts" tab in the OPAC.



1.4.3. Overdue Notice

Script path: misc/cronjobs/

Does: prepares messages to alert patrons of overdue messages (both via email and print)

Frequency suggestion: nightly


This script does not actually send the notices. It queues them in the message queue for later or generates the HTML for later printing Perl Documentation

NAME - prepare messages to be sent to patrons for overdue items

SYNOPSIS [ -n ] [ -library <branchcode> ] [ -library <branchcode>...] [ -max <number of days> ] [ -csv [ <filename> ] ] [-itemscontent <field list> ]


-help brief help message

-man full documentation

-n No email will be sent

-max <days> maximum days overdue to deal with

-library <branchname> only deal with overdues from this library (repeatable : several libraries can be given)

-csv <filename> populate CSV file

-html <filename> Output html to file

-itemscontent <list of fields> item information in templates

-borcat <categorycode> category code that must be included

-borcatout <categorycode> category code that must be excluded


-help Print a brief help message and exits.

-man Prints the manual page and exits.

-v Verbose. Without this flag set, only fatal errors are reported.

-n Do not send any email. Overdue notices that would have been sent to the patrons or to the admin are printed to standard out. CSV data (if the -csv flag is set) is written to standard out or to any csv filename given.

-max Items older than max days are assumed to be handled somewhere else, probably the script. They are therefore ignored by this program. No notices are sent for them, and they are not added to any CSV files. Defaults to 90 to match


select overdues for one specific library. Use the value in the branches.branchcode table. This option can be repeated in order to select overdues for a group of libraries.

-csv Produces CSV data. if -n (no mail) flag is set, then this CSV data is sent to standard out or to a filename if provided. Otherwise, only overdues that could not be emailed are sent in CSV format to the admin.


comma separated list of fields that get substituted into templates in places of the <<items.content>> placeholder. This defaults to issuedate,title,barcode,author

Other possible values come from fields in the biblios, items, and issues tables.

-borcat Repetable field, that permit to select only few of patrons categories.


Repetable field, permis to exclude some patrons categories.

-t | --triggered

This option causes a notice to be generated if and only if an item is overdue by the number of days defined in a notice trigger.

By default, a notice is sent each time the script runs, which is suitable for less frequent run cron script, but requires syncing notice triggers with the cron schedule to ensure proper behavior. Add the --triggered option for daily cron, at the risk of no notice being generated if the cron fails to run on time.


Default items.content lists only those items that fall in the range of the currently processing notice. Choose list-all to include all overdue items in the list (limited by -max setting).


This script is designed to alert patrons and administrators of overdue items.


This script pays attention to the overdue notice configuration performed in the "Overdue notice/status triggers" section of the "Tools" area of the staff interface to Koha. There, you can choose which letter templates are sent out after a configurable number of days to patrons of each library. More information about the use of this section of Koha is available in the Koha manual.

The templates used to craft the emails are defined in the "Tools: Notices" section of the staff interface to Koha.

Outgoing emails

Typically, messages are prepared for each patron with overdue items. Messages for whom there is no email address on file are collected and sent as attachments in a single email to each library administrator, or if that is not set, then to the email address in the "KohaAdminEmailAddress" system preference.

These emails are staged in the outgoing message queue, as are messages produced by other features of Koha. This message queue must be processed regularly by the misc/cronjobs/ program.

In the event that the "-n" flag is passed to this program, no emails are sent. Instead, messages are sent on standard output from this program. They may be redirected to a file if desired.


Templates can contain variables enclosed in double angle brackets like <<this>>. Those variables will be replaced with values specific to the overdue items or relevant patron. Available variables are:


the name of the library


one line for each item, each line containing a tab separated list of title, author, barcode, issuedate


any field from the borrowers table


any field from the branches table

CSV output

The "-csv" command line option lets you specify a file to which overdues data should be output in CSV format.

With the "-n" flag set, data about all overdues is written to the file. Without that flag, only information about overdues that were unable to be sent directly to the patrons will be written. In other words, this CSV file replaces the data that is typically sent to the administrator email address.


"" - In this most basic usage, with no command line arguments, all libraries are processed individually, and notices are prepared for all patrons with overdue items for whom we have email addresses. Messages for those patrons for whom we have no email address are sent in a single attachment to the library administrator's email address, or to the address in the KohaAdminEmailAddress system preference.

" -n -csv /tmp/overdues.csv" - sends no email and populates /tmp/overdues.csv with information about all overdue items.

" -library MAIN max 14" - prepare notices of overdues in the last 2 weeks for the MAIN library.


The misc/cronjobs/ program allows you to send messages to patrons in advance of their items becoming due, or to alert them of items that have just become due.


These methods are internal to the operation of


parses the letter template, replacing the placeholders with data specific to this patron, biblio, or item

named parameters:

letter - required hashref

borrowernumber - required integer

substitute - optional hashref of other key/value pairs that should be substituted in the letter content

returns the "letter" hashref, with the content updated to reflect the substituted keys and values.


returns a string of text appropriate for printing in the event that an overdue notice will not be sent to the patron's email address. Depending on the desired output format, this may be a CSV string, or a human-readable representation of the notice.

required parameters:



optional parameters:


1.4.4. Print Hold Notices

Script path: misc/cronjobs/

Does: looks through the message queue for hold notices that didn't go through because the patron didn't have an email address and generates a print notice

Frequency suggestion: nightly

1.4.5. Talking Tech

To learn more about setting up this third party product view the Talking Tech Appendix. Sending Notices File

Script path: misc/cronjobs/thirdparty/

Does: Script to generate Spec C outbound notifications file for Talking Tech i-tiva phone notification system.

Required by: TalkingTechItivaPhoneNotification

Frequency suggestion: nightly Perl Documentation

USAGE --type=OVERDUE -w 0 -w 2 -w 6 --output=/tmp/talkingtech/outbound.csv --type=RESERVE --type=PREOVERDUE --lang=FR

Script to generate Spec C outbound notifications file for Talking Tech i-tiva phone notification system.

--help -h

Prints this help

-v Provide verbose log information.

--output -o

Destination for outbound notifications file (CSV format). If no value is specified, output is dumped to screen.


Sets the language for all outbound messages. Currently supported values are EN, FR and ES. If no value is specified, EN will be used by default.


REQUIRED. Sets which messaging types are to be used. Can be given multiple times, to specify multiple types in a single output file. Currently supported values are RESERVE, PREOVERDUE and OVERDUE. If no value is given, this script will not produce any outbound notifications.

--waiting-hold-day -w

OPTIONAL for --type=RESERVE. Sets the days after a hold has been set to waiting on which to call. Use switch as many times as desired. For example, passing "-w 0 -w 2 -w 6" will cause calls to be placed on the day the hold was set to waiting, 2 days after the waiting date, and 6 days after. See example above. If this switch is not used with --type=RESERVE, calls will be placed every day until the waiting reserve is picked up or canceled.

--library-code --code -c

OPTIONAL The code of the source library of the message. The library code is used to group notices together for consortium purposes and apply library specific settings, such as prompts, to those notices. This field can be blank if all messages are from a single library. Receiving Notices File

Script path: misc/cronjobs/thirdparty/

Does: Script to process received Results files for Talking Tech i-tiva phone notification system.

Required by: TalkingTechItivaPhoneNotification

Frequency suggestion: nightly Perl Documentation

USAGE -v --input=/tmp/talkingtech/results.csv

Script to process received Results files for Talking Tech i-tiva phone notification system.

--help -h

Prints this help

-v Provide verbose log information.

--input -i

REQUIRED. Path to incoming results file.

1.5. In Processing/Book Cart

Script path: misc/cronjobs/

Does: Updates all items with a location of CART to the item's permanent location.

Required by: NewItemsDefaultLocation, InProcessingToShelvingCart, & ReturnToShelvingCart system preferences

Frequency suggestion: hourly

1.5.1. Perl Documentation

NAME cron script to set items with location of CART to original shelving location after X hours. Execute without options for help.

1.6. Catalog

1.6.1. Check URLs

Script path: misc/cronjobs/

Does: checks URLs in 856$u field. Script output can now be formatted in CSV or HTML. The HTML version links directly to MARC biblio record editor.

Frequency suggestion: monthly

Learn more: Perl Documentation


C4::URL::Checker - base object for checking URL stored in Koha DB


use C4::URL::Checker;

        my $checker = C4::URL::Checker->new( );
        $checker->{ host_default } = '';
        my $checked_urls = $checker->check_biblio( 123 );
        foreach my $url ( @$checked_urls ) {
            print "url:        ", $url->{ url       A }, "\n",
                  "is_success: ", $url->{ is_success }, "\n",
                  "status:     ", $url->{ status     }, "\n";



Create a URL Checker. The returned object can be used to set default host variable :

my $checker = C4::URL::Checker->new( );
        $checker->{ host_default } = ''; 


Check all URL from a biblio record. Returns a pointer to an array containing all URLs with checking for each of them.

 my $checked_urls = $checker->check_biblio( 123 ); 

With 2 URLs, the returned array will look like that:

             'url' => '',
             'is_success' => 1,
             'status' => 'ok'
             'url' => '',
             'is_success' => 0,
             'status' => '404 - Page not found'

NAME - Check URLs from 856$u field.

USAGE [--verbose|--help] [--host=http://default.tld]

Scan all URLs found in 856$u of bib records and display if resources are available or not.



Server host used when URL doesn't have one, ie doesn't begin with 'http:'. For example, if --host=, then when 856$u contains 'img/image.jpg', the url checked is:'.


Outputs both successful and failed URLs.


Formats output in HTML. The result can be redirected to a file accessible by http. This way, it's possible to link directly to biblio record in edit mode. With this parameter --host-pro is required.


Server host used to link to biblio record editing page.


Print this help page.

1.6.2. Merge Authorities

Script path: misc/migration_tools/

Does: Updates biblio data with changes to authorities records

Required by: dontmerge system preference

Frequency suggestion: nightly

1.6.3. Serials Update

Script path: misc/cronjobs/

Does: checks if there is a "late" issue on active subscriptions, and if there is, the script will set it as late, and add the next one as expected.

Frequency suggestion: nightly

1.7. OPAC

1.7.1. RSS Feeds

Script path: misc/cronjobs/rss/

Does: Produces an RSS XML document for any SQL query (not used for search results RSS feed). Learn more.

Frequency suggestion: hourly

1.7.2. Authorities Browser

Script path: misc/cronjobs/

Does: Generate content for authorities browse in OPAC

Required by: OpacBrowser system preference


This preference and cron job should only be used on French systems.

1.7.3. Subject/Author Clouds

Script path: misc/cronjobs/

Does: Generates HTML keywords clouds from Koha Zebra indexes. misc/cronjobs/cloud-sample.conf has a sample of how this script operates.

Frequency: This is the type of script you can run once a month or so, the content generated isn't going to change very much over time. Perl Documentation

NAME - Creates HTML keywords clouds from Koha Zebra Indexes

USAGE [--verbose|--help] --conf=cloud.conf

Creates multiple HTML files containing keywords cloud with top terms sorted by their logarithmic weight. cloud.conf is a YAML configuration file driving cloud generation process.


--conf=configuration file

Specify configuration file name


Enable script verbose mode.


Print this help page.


Configuration file looks like that:

         # Koha configuration file for a specific installation
         # If not present, defaults to KOHA_CONF
         KohaConf: /home/koha/mylibray/etc/koha-conf.xml
         # Zebra index to scan
         ZebraIndex: Author
         # Koha index used to link found kewords with an opac search URL
         KohaIndex: au
         # Number of top keyword to use for the cloud
         Count: 50
         # Include CSS style directives with the cloud
         # This could be used as a model and then CSS directives are
         # put in the appropriate CSS file directly.
         Withcss: Yes
         # HTML file where to output the cloud
         Output: /home/koha/mylibrary/koharoot/koha-tmpl/cloud-author.html
         KohaConf: /home/koha/yourlibray/etc/koha-conf.xml
         ZebraIndex: Subject
         KohaIndex: su
         Count: 200
         Withcss: no
         Output: /home/koha/yourlibrary/koharoot/koha-tmpl/cloud-subject.html


Generated top terms have more informations than those outputted from the time being. Some parameters could be easily added to improve this script:


In order to output terms with the number of occurrences they have been found in Koha Catalogue by Zebra.


Number of levels in the cloud. Now 24 levels are hardcoded.


Weighting method used to distribute terms in the cloud. We could have two values: Logarithmic and Linear. Now it's Logarithmic by default.


Now terms are outputted in the lexical order. They could be sorted by their weight.

1.8. System Administration

1.8.1. Clean up Database

Script path: misc/cronjobs/

Does: Truncates the sessions table, cleans out old zebraqueue entries, action logs and staged MARC files.

1.9. Acquisitions

1.9.1. Clean up old suggestions

Script path: misc/cronjobs/

Does: Removes old (defined by you) suggestions from the suggestion management area.

1.10. Deprecated scripts

These should not be run without modification:

Script path: misc/cronjobs/

Script path:misc/cronjobs/

Script path:misc/cronjobs/

Script path:misc/cronjobs/

Script path:misc/cronjobs/

Script path:misc/cronjobs/