#!/bin/bash # Script zum Download von Metadaten über SRU-Schnittstellen mit curl # sru-download.sh, Felix Lohmeier, v0.2, 16.03.2017 # https://github.com/felixlohmeier/seminar-praxis-der-digitalen-bibliothek # Variablen (bei Bedarf hier anpassen) url="http://sru.gbv.de/opac-de-960-3" query="pica.ppn=.*" format="marcxml" outputdir="download" filename="hsh_ksf" recordlimitperquery=100 # Weitere technische Variablen date="$(date +%F)" datelog="$(date +%Y%m%d_%H%M%S)" command="?operation=searchRetrieve" startrecord=1 let counter=startrecord+recordlimitperquery-1 # Verzeichnis erstellen (falls nicht vorhanden) mkdir -p $outputdir # Ausgabe parallel in eine Logdatei schreiben exec &> >(tee -a "$outputdir/${filename}_${datelog}.log") # Anzahl der Datensätze auslesen records=$(curl --silent "${url}${command}&query=${query}&recordSchema=${format}" | sed 's/ $outputdir/${filename}_${date}_$(printf "%.7i\n" ${startrecord})-$(printf "%.7i\n" ${counter}).xml # Sofortige Prüfung des Downloads, wenn Format marcxml if [ $format = "marcxml" ]; then echo "Ergebnis: "$(grep -c -H '' $outputdir/${filename}_${date}_$(printf "%.7i\n" ${startrecord})-$(printf "%.7i\n" ${counter}).xml)" records" fi echo "" let counter=counter+recordlimitperquery let startrecord=startrecord+recordlimitperquery done # Prüfung des Downloads, wenn Format marcxml if [ "$format" = "marcxml" ]; then echo "Gesamtanzahl der Records im Ordner download:" grep '' $outputdir/*.xml | wc -l echo "" echo "Dateien, die weniger als 10 Records enthalten:" testfiles=($(find "$outputdir" -type f -name '*.xml')) for i in "${testfiles[@]}" ; do testfilerecords="$(grep -c -h '' ${i})" if (("${testfilerecords}" < "10")); then echo 1>&2 "${i}: ${testfilerecords}" fi done echo "" fi # Prüfung, ob sich während des Downloads die Datenbank geändert hat recordsafterdownload=$(curl --silent "${url}${command}&query=${query}&recordSchema=${format}" | sed 's/&2 "Warnung: Die Suchabfrage an die SRU-Schnittstelle hat vor Beginn des Downloads eine andere Gesamtanzahl an Datensätzen ergeben (${records}) als nach dem Download (${recordsafterdownload}). Das ist ein Indiz dafür, dass die Datenbank zwischenzeitlich verändert wurde. Es ist wahrscheinlich, dass dadurch einzelne Datensätze im Download fehlen." fi # Endzeitpunkt ausgeben echo "Endzeitpunkt: $(date)" echo ""