Contribute to the DSpace Development Fund

The newly established DSpace Development Fund supports the development of new features prioritized by DSpace Governance. For a list of planned features see the fund wiki page.

#!/bin/sh
#
# Retrieves all pages from the OAI interface. With XOAI, this warms up the cache of XML responses.
# Usage: oai-warmup.sh http://localhost:8080/oai/request oai_dc
# (both parameters are optional, the above values are default)
#
# Dependencies: sh, curl, head, tail, awk, xmllint (Debian packages: curl coreutils gawk libxml2-utils)
#
# Author: Ivan Masar, 2014. Released into public domain.
 
oaibase="http://localhost:8080/oai/request"
format="oai_dc"
tmpfile=/tmp/oai.xml
 
export LC_ALL=C
 
if [ "$#" -ge 1 ]; then
        oaibase="$1"
fi
 
if [ "$#" -eq 2 ]; then
        format="$2"
fi
 
echo "OAI base URL = $oaibase"
echo "metadata format = $format"

curl -s "$oaibase?verb=ListRecords&metadataPrefix=$format" > $tmpfile
size=`printf "setns x=http://www.openarchives.org/OAI/2.0/\nxpath string(//x:OAI-PMH/x:ListRecords/x:resumptionToken/@completeListSize)" | xmllint --shell $tmpfile | tail -n 2 | head -n 1 | awk '{print $6}'`
echo "completeListSize = $size"
perpage=`printf "setns x=http://www.openarchives.org/OAI/2.0/\nxpath count(//x:OAI-PMH/x:ListRecords/x:record)" | xmllint --shell $tmpfile | tail -n 2 | head -n 1 | awk '{print $6}'`
echo "records per page = $perpage"

token=`printf "setns x=http://www.openarchives.org/OAI/2.0/\nxpath string(//x:OAI-PMH/x:ListRecords/x:resumptionToken/text())" | xmllint --shell $tmpfile | tail -n 2 | head -n 1 | awk '{print $6}'`
page=0
until [ "$token" = "" ]; do
        page=$(($page+1))
        record=$(($page*$perpage))
        echo "record $record, $token"
        curl -s "$oaibase?verb=ListRecords&resumptionToken=$token" > $tmpfile
        token=`printf "setns x=http://www.openarchives.org/OAI/2.0/\nxpath string(//x:OAI-PMH/x:ListRecords/x:resumptionToken/text())" | xmllint --shell $tmpfile | tail -n 2 | head -n 1 | awk '{print $6}'`
done
  • No labels