工作排程與守護行程

Koha 由若干背景工作支援。包括定期執行的工作 (工作排程) 或稱為 守護行程的持續執行的工作。

工作排程是安排自動伺服器裡的指令或腳本以完成指定工作的 Linux 指令。以工作排程方式執行的腳本通常是修改檔案或資料庫;然而,它們也可以執行其他不需修改伺服器資料的工作,像是送出電子郵件通知。

daemon 是 Linux 命令,系統啟動後就開始執行,並持續在背景執行若干功能。Koha 用到的資料庫 (MYSQL 或 MariaDB) 及網頁伺服器 (通常是 Apache),就是一種 daemon。

Koha 含有多個工作排程 (搜尋引擎索引、產生逾期通知、清除資料等) 及若干守護行程。本章將說明它們。

Crontab 範例

Koha crontab 在 misc/cronjobs/crontab.example

此範例包括 boilerplate 工作排程款目的樣本。

工作排程

工作排程應該在 misc/ 之下,若在 misc/ 之下找不到而且以標準方式安裝伺服器時則可能在 bin/

備份

每日備份

腳本路徑:misc/cronjobs/backup.sh

做:新增 Koha 資料庫逐日備份。

建議頻率:逐日

流通

預約佇列

腳本路徑:misc/cronjobs/holds/build_holds_queue.pl

做:更新預約順位報表

必須用到:預約順位報表

建議頻率:每 1-4 小時

說明:

  • 應定期執行腳本若您的圖書館系統允許讀者預約在架的館藏。此腳本決定負責滿足此預約的圖書館。

    由系統偏好 StaticHoldsQueueWeightRandomizeHoldsQueueWeight 共同控制其行為。

    不讓所有圖書館參與館藏滿足預約計畫,應列出*要*參加該計畫的圖書館,包括圖書館的條碼,並以逗點區隔(如:」MPL,CPL,SPL,BML」 等)。

    預設,預約順位將先列入提取圖書館。若無法滿足,則 build_holds_queue.pl 將取用 StaticHoldsQueueWeight 設定的圖書館。若停用 RandomizeHoldsQueueWeight (預設值為停用),則依 StaticHoldsQueueWeight 偏好設定的圖書館順序,逐一取用。

    例如,系統內有三個規模不一的圖書館(大型、中型與小型),希望由大型圖書館承擔較多的預約責任,StaticHoldsQueueWeight偏好應設為」LRG,MED,SML」。

    若期望各圖書館平均分擔預約的任務,應啟用RandomizeHoldsQueueWeight偏好,將隨機將預約分配給各圖書館。

    讓 StaticHoldsQueueWeight 空白是禁忌,將造成 build_holds_queue 腳本忽略 RandomizeHoldsQueueWeight,使該腳本要求不是隨機卻採用字順方式填入預約。

預約過期

腳本路徑:misc/cronjobs/holds/cancel_expired_holds.pl

做:預設,此工作排程僅自動執行使用者設定到期日的取消預約。若圖書館使用 ExpireReservesMaxPickUpDelayExpireReservesMaxPickUpDelayCharge 偏好則此腳本也取消在預約架太久的預約並將 (若圖書館要的) 向讀者收取未提取預約到館費用。

建議頻率:逐日

取消預約

腳本路徑:misc/cronjobs/holds/auto_unsuspend_holds.pl

做:若將 AutoResumeSuspendedHolds 偏好設為 『允許』 則此腳本檢查不需保留的預約並移除它們。此舉將讀者放回保留之前序列。

建議頻率:逐日

罰款

腳本路徑:misc/cronjobs/fines.pl

Does: calculates and charges (or increments) overdue fines per item to patron accounts. The fine calculation is done using the grace period, fine interval, fine amount and other parameters from the circulation and fines rules.

必備:finesMode 系統偏好

建議頻率:每晚

說明 若 Koha 系統偏好 『finesMode』 已設為 『production』,則向讀者收取罰款。若設為 『test』,則計算罰款但不收取。

Note Fines will not be applied on a holiday.

Static fines

腳本路徑:misc/cronjobs/staticfines.pl

Does: charges a single static fine for any/all overdues a patron currently has outstanding. The charge amount is either defined on the command line per borrower category or will use the circulation rules associated with the oldest overdue item the patron has currently checked out (for the first fine period only) Once charged, the fine is static: No new fines will be added until the existing fine is paid off in full.

建議頻率:每晚

說明 若 Koha 系統偏好 『finesMode』 已設為 『production』,則向讀者收取罰款。若設為 『test』,則計算罰款但不收取。

說明 假日不計入罰款。

逾期太久

腳本路徑:misc/cronjobs/longoverdue.pl

做:允許更改不同程度的遺失館藏,並向讀者收取館藏記錄內的重置價格。

建議頻率:每晚

說明

Staff can control some of the parameters for the longoverdue cron job with the DefaultLongOverdueLostValue and DefaultLongOverdueChargeValue preferences.

追蹤借出總數

腳本路徑:misc/cronjobs/update_totalissues.pl

做:以最新的借出現況更新資料庫內 biblioitems.totalissues 欄位的內容。

建議頻率:每晚

警示

需考量資料庫伺服器與 Koha 伺服器的時間不同步的狀況,並使用 –since 參數取代 –interval 參數做為新增性更新的依據。

說明

可以使用此工作排程。也可使用 UpdateTotalIssuesOnCirc 系統偏好。

產生讀者檔供離線流通之用

腳本路徑:misc/cronjobs/create_koc_db.pl

做:從 Koha 離線流通 工具產生 borrowers.db 檔案

建議頻率:每週

自動續借

腳本路徑:misc/cronjobs/automatic_renewals.pl

Does: renews items if you’re allowing automatic renewal with your circulation and fines rules.

建議頻率:每晚

讀者

批次刪除讀者

腳本路徑:misc/cronjobs/delete_patrons.pl

做:依照未曾借出日期、到期日、上網日期、屬性、或所屬圖書館,批次刪除讀者紀錄。

說明

應採用 ISO 格式的日期,如 2013-07-19,可以用指令產生 date -d 『-3 month』 「+%Y-%m-%d」。

重要

The options to select the patron records to delete are cumulative. For example, supplying both –expired_before and –library specifies that patron records must meet both conditions to be selected for deletion.

PARAMETERS

  • –not_borrowed_since Delete patrons who have not borrowed since this date.

  • –expired_before Delete patrons with an account expired before this date.

  • –last_seen Delete patrons who have not been connected since this date. The system preference TrackLastPatronActivity must be enabled to use this option.

  • –category_code Delete patrons who have this category code.

  • –library Delete patrons in this library.

  • -c|–confirm This flag must be provided in order for the script to actually delete patron records. If it is not supplied, the script will only report on the patron records it would have deleted.

  • -v|–verbose Verbose mode.

Unverified registrations

腳本路徑:misc/cronjobs/delete_expired_opac_registrations.pl

Does: deletes patron registrations that were submitted via the OPAC but not reviewed by the library within the number of days entered in the PatronSelfRegistrationExpireTemporaryAccountsDelay preference.

建議頻率:每晚

Unconfirmed registrations

腳本路徑:misc/cronjobs/delete_unverified_opac_registrations.pl

Does: deletes patron self registrations that were submitted via the OPAC but not confirmed via email within 24 hours. This is only necessary if you are requiring patrons to confirm their registrations via email with the PatronSelfRegistrationVerifyByEmail preference.

建議頻率:每小時

Anonymize patron data

腳本路徑:misc/cronjobs/batch_anonymise.pl

Does: removes borrowernumbers from circulation history so that the stats are kept, but the patron information is removed for privacy reasons.

Update child to adult patron type

腳本路徑:misc/cronjobs/j2a.pl

Does: converts juvenile/child patrons from juvenile patron category and category code to corresponding adult patron category and category code when they reach the upper age limit defined in the Patron Categories.

建議頻率:每晚

DESCRIPTION

此腳本係供青少年讀者類型昇級至成人讀者類型之用,移除保證人,到讀指定讀者類型的年齡下限時昇級至適合的代碼。

USAGE EXAMPLES

「juv2adult.pl」

「juv2adult.pl」 -b=<branchcode> -f=<categorycode> -t=<categorycode> (處理單一分館,並逐一更新讀者類型)

「juv2adult.pl」 -f=<categorycode> -t=<categorycode> -v -n (處理所有分館、顯示全部訊息、報告受影響的讀者。不修改資料庫)

通知

Message queue

腳本路徑:misc/cronjobs/process_message_queue.pl

做:處理訊息佇列納入發送給讀者的借出、還入與預約歸檔電子郵件與簡訊以及送給讀者的電子郵件。必須將 EnhancedMessagingPreferences 偏好設為開啟

建議頻率:1-4小時

重要

到期館藏與到期提前通知由 advance_notices cron 控制。

Advanced notice

腳本路徑:misc/cronjobs/advance_notices.pl

做:應讀者的要求提供 「到期提前」 通知與 「到期館藏」 通知給需要的讀者。需將 EnhancedMessagingPreferences 偏好設為開啟

建議頻率:每晚

說明

此腳本不會真的送出通知。祗把通知置於 訊息佇列 供以後使用

Overdue notice

腳本路徑:Script path: misc/cronjobs/overdue_notices.pl

做:準備讀者逾期的訊息 (經電子郵件或列印)

建議頻率:每晚

說明

此腳本不會真的送出通知。它把通知列入 訊息佇列 內供列印之用

參見

此 misc/cronjobs/advance_notices.pl 程式允許您送出訊息給逾期的讀者,或警示他們即將逾期。

Talking Tech

設定此第三方產品的詳情參見 Talking Tech

Sending notices file

腳本路徑:misc/cronjobs/thirdparty/TalkingTech_itiva_outbound.pl

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

必備於:TalkingTechItivaPhoneNotification

建議頻率:每晚

Receiving notices file

腳本路徑:misc/cronjobs/thirdparty/TalkingTech_itiva_inbound.pl

Does: processes received results files for Talking Tech i-tiva phone notification system.

必備於:TalkingTechItivaPhoneNotification

建議頻率:每晚

Notify patrons of expiration

腳本路徑:misc/cronjobs/membership_expiry.pl

做:把借書證到期的警示通知置於 訊息佇列 工作排程。

必備:MembershipExpiryDaysNotice

頻率:每天

In processing/book cart

腳本路徑:misc/cronjobs/cart_to_shelf.pl

Does: updates all items with a location of CART to the item’s permanent location.

Required by: NewItemsDefaultLocation, InProcessingToShelvingCart, and ReturnToShelvingCart system preferences

建議頻率:每小時

目錄

Import webservice batch

腳本路徑:misc/cronjobs/import_webservice_batch.pl

Does: processes import bach queues of type 『webservice』. Batches can also be processed through the UI.

說明

此腳本適用於 OCLC Connexion

Connexion import daemon

腳本路徑:misc/bin/connexion_import_daemon.pl

Does: listens for OCLC Connexion requests and is compliant with OCLC Gateway specification. It takes requests with MARC XML and import batch parameters from a configuration file and forwards it to svc/import_bib

說明

此腳本適用於 OCLC Connexion

Batch item deletion

腳本路徑:misc/cronjobs/delete_items.pl

Does: generates a query against the items database and deletes the items matching the criteria specified in the command line arguments.

PARAMETERS

  • –verbose Send the 「WHERE」 clause generated by the collected C<–where> arguments, as well as items affected to Standard Out.

  • –where The C<–where> option may called multiple times. The following argument must be a syntactically valid SQL statement which is part of the C<WHERE> clause querying the items table. These are joined by C<AND>.

  • –commit No items will be deleted unless the C<–commit> flag is present.

EXAMPLES

The following are examples of this script:

delete_items.pl –where 「items.withdrawn ! 0」 –where 「items.withdrawn_on < $(date –date=」13 month ago」 –rfc-3339=date)」 –commit

delete_items.pl –where 「itemlost >= 『1』」 –where 「itemlost <=』4』」 –where 「itemlost_on < 『2014-04-28』」 –commit

Check URL quick

腳本路徑:misc/cronjobs/check-url-quick.pl

Does: checks URLs from biblio records; scans all URLs found by default in 856$u of bibliographic records and displays if resources are available or not.

說明

此腳本用以重置 check-url.pl

PARAMETERS

  • –host=http://default.tld Server host used when URL doesn’t have one, ie doesn’t begin with 『http:』. For example, if –host=mylib.com, then when 856$u contains 『img/image.jpg』, the url checked is: http://www.mylib.com/image.jpg.

  • –tags Tags containing URLs in $u subfields. If not provided, 856 tag is checked. Multiple tags can be specified, for example:

    check-url-quick.pl –tags 310 410 856

  • –verbose|v Outputs both successful and failed URLs.

  • –html Formats output in HTML. The result can be redirected to a file accessible by http. This way, it’s possible to link directly to the bibliographic record in edit mode. With this parameter –host-intranet is required.

  • –host-intranet=http://koha-pro.tld Server host used to link to bibliographic record editing page in Koha intranet interface.

  • –timeout=10 Timeout for fetching URLs. By default 10 seconds.

  • –maxconn=1000 Number of simulaneous HTTP requests. By default 200 connexions.

檢查 URL

腳本路徑:misc/cronjobs/check-url.pl

做:檢查 856$u 欄位裡的 URL。腳本的輸出是 CSV 或 HTML 格式。HTML 版本直接連結至 MARC 書目記錄編輯器。

建議頻率:每月

詳情見:http://wiki.koha-community.org/wiki/Check-url_enhancements

Delete records via leader

腳本路徑:misc/cronjobs/delete_records_via_leader.pl

Does: attempts to delete any MARC records where the leader character 5 equals 『d』.

PARAMETERS

  • -c|–confirm Script will do nothing without this parameter

  • -v|–verbose Verbose mode

  • -t|–test Test mode, does not delete records. Test mode cannot determine if a record/item will be deleted successfully, it will only tell you what records and items the script will attempt to delete.

  • -i|–delete-items Try deleting items before deleting record. Records with items cannot be deleted.

Update authorities

腳本路徑:misc/cronjobs/merge_authorities.pl

Does: updates biblio data with changes to authorities records

說明

此腳本的名稱是誤導。此腳本並未合併權威記錄反而合併與其連結的書目記錄。執行腳本時編輯權威記錄將適用於使用權威記錄的書目記錄。

必備於: AuthorityMergeLimit 系統偏好

建議頻率:每晚

Serials update

腳本路徑:misc/cronjobs/serialsUpdate.pl

做:檢查訂閱中的期刊是否有 「遲到」 的刊期,若有,此腳本設定它為遲到,並把下一期列為期待簽收。

建議頻率:每晚

自動更新館藏

腳本路徑:misc/cronjobs/automatic_item_modification_by_age.pl

做:根據在 依年齡自動修改館藏 工具的規則更新館藏

使用到的是:依年齡自動修改館藏

建議頻率:每晚

OPAC

RSS feeds

腳本路徑:misc/cronjobs/rss/rss.pl

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

建議頻率:每小時

Authorities browser

腳本路徑:misc/cronjobs/build_browser_and_cloud.pl

Does: generates content for authorities browse in OPAC

必備於:OpacBrowser 系統偏好

重要

此偏好與工作排程應祗適用於法語系統。

Subject/author clouds

腳本路徑:misc/cronjobs/cloud-kw.pl

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

頻率:這是您可每月執行一次的腳本類型,其內容並不常變動。

System administration

Services throttle

腳本路徑:misc/cronjobs/services_throttle.pl

做:重設 xISBN 服務量

建議頻率:每晚

Clean up database

腳本路徑:misc/cronjobs/cleanup_database.pl

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

Share usage stats

路徑腳本:misc/cronjobs/share_usage_with_koha_community.pl

Does: sends your info to the Hea website if you’re sharing information via the UsageStats feature

頻率:每月

採訪

清除舊的建議

腳本路徑:misc/cronjobs/purge_suggestions.pl

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

說明

系統偏好 PurgeSuggestionsOlderThan 設定在腳本使用的日數

將建議以電郵送入程序

腳本路徑:misc/cronjobs/notice_unprocessed_suggestions.pl

Does: generates a notice to the fund owner that there are suggestions in need of processing

EDI message processing

腳本路徑:misc/cronjobs/edi_cron.pl

Does: sends and received EDI messages

頻率:每 15 分鐘

Remove temporary EDI files

腳本路徑:misc/cronjobs/remove_temporary_edifiles.pl

做:移除 5 天前的暫存 EDI 檔案

報表

Run report

腳本路徑:misc/cronjobs/runreport.pl

Does: runs pre-existing saved reports

PARAMETERS

  • -v|–verbose Verbose output

  • –format=s Selects format. Choice of text, html, csv or tsv

  • -e|–email Whether or not to use e-mail (implied by –to or –from)

  • -a|–attachment Attach the report as a file. Cannot be used with html format

  • –username Username to pass to the SMTP server for authentication

  • –password Password to pass to the SMTP server for authentication

  • –method The type of authentication. Ie. LOGIN, DIGEST-MD5, etc.

  • –to=s E-mail address to send report to

  • –from=s E-mail address to send report from

  • –subject=s Subject for the e-mail

  • –store-results Store the result of the report

  • –csv-header Add column names as first line of csv output

ARGUMENTS

  • reportID Report ID Number from saved_sql.id, multiple ID’s may be specified

挪威讀者資料庫

NL 同步於 Koha

腳本路徑:misc/cronjobs/nl-sync-to-koha.pl

Does: syncs patrons from the Norwegian national patron database (NL) to Koha

說明 回應 NorwegianPatronDBUsername 與 NorwegianPatronDBPassword 系統偏好

NL 同步自 Koha

腳本路徑:misc/cronjobs/nl-sync-from-koha.pl

Does: syncs patrons from Koha to the Norwegian national patron database (NL)

說明 回應 NorwegianPatronDBUsername 與 NorwegianPatronDBPassword 系統偏好

社會資料

取得社會資料報表

腳本路徑:misc/cronjobs/social_data/get_report_social_data.pl

做:從 Babelthèque 下載資料加入 OPAC 紀錄

建議頻率:每晚

更新社會資料

腳本路徑:misc/cronjobs/social_data/update_social_data.pl

做:以 Babelthèque 資料更新 OPAC 紀錄

Daemons

Daemons are continuously running tasks that help support Koha operation. Your database and webserver are run as daemons. Newer versions of Koha start two different daemons for most koha instances:

  • zebra - this is the index server

  • koha-indexer - this daemon updates the index server with new and modified data (biblios and authorities)

These daemons are started by the script /etc/init.d/koha-common.

Zebra indexer daemon

Script path: /usr/sbin/koha-indexer (invoked from /etc/init.d/koha-common)

The koha-indexer script invokes rebuild_zebra.pl in daemon mode. In this mode, the script will run continuously and check the database for new or modified data every 30 seconds. New or modified records are then sent to Zebra for indexing, which only takes a second or so. The advantage of this approach is a search system which is much more responsive to changes, compared to the cron job approach.

不適用的腳本

不應在未修改前執行這些:

腳本路徑:misc/cronjobs/update_items.pl

腳本路徑:misc/cronjobs/smsoverdues.pl

腳本路徑:misc/cronjobs/notifyMailsOp.pl

腳本路徑:misc/cronjobs/reservefix.pl

腳本路徑:misc/cronjobs/zebraqueue_start.pl