Command-line scripts

Paul POULAIN

This document is related to Koha and is licensed to you under the GNU General Public License version 2 or later (http://www.gnu.org/licenses/gpl.html).

Koha-related documents may be reproduced and distributed in whole or in part, in any medium physical or electronic, as long as this copyright notice is retained on all copies.

You may create a derivative work and distribute it provided that you:

  1. License the derivative work with this same license, or the Linux Documentation Project License (http://www.tldp.org/COPYRIGHT.html). Include a copyright notice and at least a pointer to the license used.

  2. Give due credit to previous authors and major contributors.

Commercial redistribution is allowed and encouraged; however, the author would like to be notified of any such distributions.

No liability for the contents of this document can be accepted. Use the concepts, examples and information at your own risk. There may be errors and inaccuracies, that could be damaging to your system. Proceed with caution, and although this is highly unlikely, the author(s) do not take any responsibility.

All copyrights are held by their by their respective owners, unless specifically noted otherwise. Use of a term in this document should not be regarded as affecting the validity of any trademark or service mark. Naming of particular products or brands should not be seen as endorsements.

2005-05-15

Revision History
Revision 2.2.22005-05-13jlj

English translation by Jared Jennings

Revision 2.2.02005-02-25pp

Version initiale


1. Introduction
1.1. General things
1.2. Prerequisites
2. The scripts
2.1. overduenotice.pl
2.2. fines2.pl
2.3. notifys/fines.pl
2.4. merge_authorities.pl
2.5. migration_tools/build_marc_word.pl
2.6. migration_tools/bulkauthimport.pl
2.7. migration_tools/cleanmarcdb.pl
2.8. migration_tools/compare_iso_and_marc_parameters.pl
2.9. migration_tools/dumpmarc.pl
2.10. koha2marc.pl
2.11. rebuildnonmarc.pl
2.12. rebuildthesaurus.pl
2.13. update_marcsubjects.pl
2.14. migration_tools/buildLANG.pl
2.15. migration_tools/buildEDITORS.pl
2.16. migration_tools/build6xx.pl
2.17. migration_tools/bulkmarcimport.pl
2.18. migration_tools/check_marc_definition.pl

1. Introduction

1.1. General things

This document presents the different scripts furnished with Koha. It does not talk about the scripts you can use to migrate your library records, but the ones a library can use for its daily function.

For example, scripts to deal with late returns.

1.2. Prerequisites

Technical prerequisites:

  • Installation of Koha: we assume Koha to be installed. $KOHA is the directory where the library interface is found. If you type this command

    ls -l $KOHA

    You should see: cgi-bin htdocs modules scripts

  • The Koha configuration file is /etc/koha.conf. If not, you must specify where it is with this environment variable :

    export KOHA_CONF=/etc/mykoha.configfile
  • All the commands we're about to use are used in a shell on the server.

  • Open a shell (command line) and verify that Perl can find your modules:

    export PERL5LIB=$KOHA/modules
  • The scripts are found in the directory scripts/misc. You should move them outside the Koha directory tree if you modify them, because each update of Koha will clobber them. (Actually, they will be backed up, but they won't be run by the crontab anymore.)

  • All the scripts are suitable for placing in a table of periodic tasks (crontab). We will not deal with exactly how to do that here. For that, see the crontab documentation:

    man crontab

    and

    man 5 crontab
  • All of these scripts worked, at one time. This does not mean they still work, nor that they will work in the version of Koha that you have downloaded. You are warned!

2. The scripts

2.1. overduenotice.pl

This script looks for the patrons who have overdue items and sends notices.

It isn't called with any command line parameters: all that is customizable is at the beginning of the script.

It works this way :

  • Only the patrons who are in the "overduenoticerequired" category are dealt with. The others are ignored.

  • The script sends an email to all the patrons who have given an email address.

  • The script sends a list of all the overdue items to an internal email address, for going through manually.

Here are the parameters you can change :

  • the grace period before notification begins (7 days in the official version)

  • how long to send notices before giving up (30 days in the official version). Usually, after this number of days the patron is suspended, but the suspension is not managed by this script.

  • The "From" address that will appear in the emails to the patrons.

  • The subject of the email.

  • The body of the message. This is given in plain text, with 2 exceptions :

    • special characters like \n (newline) or \t (tab).

    • tags that will be replaced with their values by the script. These tags are surrounded by angle brackets:

      • <itemcount> (the number of items which are overdue)

      • <firstname> (the first name of the patron)

      • <lastname> (the last name of the patron)

      • <address1>

      • <address2>

      • <address3>

      • <city> (the address)

      • <postcode> (the postal code)

2.2. fines2.pl

This script calculates the overdue fines.

It probably doesn't work anymore in version 2.2.

2.3. notifys/fines.pl

This script calculates the overdue fines.

It probably doesn't work anymore in version 2.2.

2.4. merge_authorities.pl

This script merges two authorities passed as parameters.

It recognizes the following options :

  • -h (or no option) : explain command-line parameters

  • -f X (from), where X is an authority number. Combine X

  • -t Y (to), where Y is an authority number. Combine with Y

All the bibliographical fields that pointed to the authority X point to the authority Y after the execution of the script.

The script will:

  • Verify that the authorities are of the same kind.

  • Display the authorities for validation

  • Go ahead with the combination, if the user confirms it.

Upon confirmation, X becomes unused. It can be removed using Koha's graphical interface.

There are two optional parameters:

  • -b (batch). In batch mode, the script looks for all the authorities that will be modified, and modifies all the bibliographical entries that use them. The authority numbers that will be changed are stored in a specific directory.

  • -n (no confirmation), silent mode. If this switch is given, the script will not output anything and will do the merge without asking for confirmation.

Typically, the -b and -n switches are useful when the script is placed in the crontab, to update the bibliographical records that use an authority which has been modified.

Here is an example, which I have in my crontab:

SHELL=/bin/bash

*/5 * * * * export PERL5LIB=/home/httpd/koha;export KOHA_CONF=/etc/koha.conf;/home/httpd/koha/scripts/misc/merge_authorities.pl -b -n

2.5. migration_tools/build_marc_word.pl

A script which only concerns MARC21 installations. It reconstructs the marc_word table with only certain words, for better response times.

2.6. migration_tools/bulkauthimport.pl

A script that ought to migrate ISO2709 authority records, after the same model as bulkmarcimport.pl. It doesn't work in version 2.2.2.

2.7. migration_tools/cleanmarcdb.pl

Doesn't work at this writing (Koha 2.2.2) but ought to be simple to correct.

2.8. migration_tools/compare_iso_and_marc_parameters.pl

Prints the list of MARC subfields which are used in an ISO2709 file, but not declared in the cataloging table settings.

This script helps in detecting errors in the settings.

It accepts the following options:

  • -v or no option : print execution parameters.

  • -file file.iso : the ISO file to compare to the catalog structure.

  • -w : eliminates warnings if the ISO2709 file has format irregularities

  • -c codetable : cataloging table from which to get the MARC parameters. If this option is omitted, the script will use the default cataloging table.

2.9. migration_tools/dumpmarc.pl

This script prints an ISO2709 file in a readable format.

It takes the following options:

  • -v or no option : print execution parameters

  • -file file.iso : the file to print out

  • -n number : the record number to print (numbered by order in the file)

  • -w : activate or deactivate warnings given if the file is not strictly ISO2709. If the script fails without -w, try again with -w, but know that your file is not ISO2709! If it works with the -w option, the defect is not that big. If there's a serious error, even using -w will end in failure.

2.10. koha2marc.pl

Only useful for libraries with an ancient version of Koha (1.2) or libraries which have set MARC=OFF, which isn't the case in any French-speaking library.

This script reconstructs the MARC database from the non-MARC database.

Caution: NEVER run this script if you have MARC set to ON, because you will erase a good portion of your records!!!

2.11. rebuildnonmarc.pl

This script does the opposite of the previous one. It is only useful for libraries having MARC=ON.

It reconstructs Koha's non-MARC database from the MARC-Koha links settings and the MARC records.

It must be run whenever something is modified in the MARC-Koha links settings. This shouldn't be too often.

If you don't know whether you need to rerun this script, tell the Koha mailing list what you did, and we'll gladly tell you.

2.12. rebuildthesaurus.pl

A useless script, deprecated, it will be removed.

2.13. update_marcsubjects.pl

A script that updates the keywords in the MARC database. Only useful for libraries with MARC=OFF, which is not the case in any French-speaking library.

2.14. migration_tools/buildLANG.pl

A little script to reconstruct the list of language codes (authorized value list named LANG) from the contents of the database.

It takes these parameters :

  • -h or no parameter : print the command-line options

  • -s : the field/subfield containing the language codes (for example : "('101a','101b')" for UNIMARC)

  • -d : delete the existing table before reconstructing it

  • -l LANGUAGE : the language in which to generate the language codes. Only 'fr' and 'en' are available.

Note that in all cases the list of codes will be the ISO list, whether the language code is French or English.

You can complete the list after it has been automatically constructed, but if you migrate a database, a missing value after the execution of this script is an unused value in your database; therefore it will be useless (unless you put in new data, of course).

2.15. migration_tools/buildEDITORS.pl

A script that automatically constructs the "EDITORS" authority list, used by the 210$c and 225$a plugins to figure out the author and the list of possible collections from the ISBN.

For this script to work, the authority category must be defined, as indicated in the document "Set Parameters and Migrate your Data to Koha 2.2."

It takes the following parameters :

  • -c (confirm). The script doesn't need any parameters. To keep it from running too fast, start it with -c, and it will stop before doing anything. You must use -c to make it reconstruct the EDITORS authority.

  • -d : Erase the existing list before reconstructing it. Logically, you should use this option.

2.16. migration_tools/build6xx.pl

This script reconstructs the authorities lists from the records migrated into Koha. It doesn't work directly. You must modify the script to adapt it to the needs of your library, and the way you manage your authorities (authority structure: $a, $a and $b, $a and $x repeated, etc.)

The present script is just a starting point and must be adapted.

2.17. migration_tools/bulkmarcimport.pl

This script imports an ISO2709 file into the active Koha database. It's the principal migration script. It works, but you would do better to clean your data as it's being imported; it's generally a good idea. If you want to do this, you must modify the script to adapt it to your cataloging standards. It works rather simply: it reads record by record, puts aside item records, imports the bibliographic record, and then puts in the item records.

The details of this script's function are in the document "Set Parameters and Migrate Your Data to Koha 2.2."

2.18. migration_tools/check_marc_definition.pl

This script compares the records in the database and the cataloging structure. It prints a list of the fields which are in the database (probably imported by bulkmarcimport), but not used by the cataloging structure (Koha-MARC links), and a list of fields which are called for in the cataloging structure, but were never filled in.

In the first case, it's certainly an error in your cataloging structure settings. If not, you ought to remove the field while importing (bulkmarcimport).

In the second case, maybe it's an error, or maybe the field hasn't yet been used, and you want to start to use it.