I, Librarian BibTeX export via command line

In case you use your I, Librarian database together with BibTeX, you will most probably will be annoyed by the recurring task to export your current literature database to a bibfile. Here is a short script that dumps all entries from a I, Librarian instance to your command line. So all you have to do in the future is to type

librariandump.sh > local.bib

to update your local BibTeX data.

#!/bin/bash

# configuration
LIBRARIAN_URL="http://url.to-host.example.com/librarian" # without trailing slash
HTTP_AUTH_USER="" # leave empty to disable HTTP Basic Authentication
HTTP_AUTH_PASS=""
LIBRARIAN_AUTH_USER="username"
LIBRARIAN_AUTH_PASS="password"

# sign in
COOKIEJAR=$(mktemp)
HTTP_AUTH=""
if [ "$HTTP_AUTH_USER" != "" ]
then
        HTTP_AUTH="--user $HTTP_AUTH_USER:$HTTP_AUTH_PASS"
fi
RESPONSE=$(curl -s $HTTP_AUTH -b $COOKIEJAR -c $COOKIEJAR --data "form=signin&user=$LIBRARIAN_AUTH_USER&pass=$LIBRARIAN_AUTH_PASS" "$LIBRARIAN_URL/index2.php")
if [ "$RESPONSE" != "OK" ]
then
        echo "Authentication failed. Response: $RESPONSE"
        exit 1
fi

# fetch
curl -s $HTTP_AUTH -b $COOKIEJAR -c $COOKIEJAR "$LIBRARIAN_URL/display.php?select=library&browse\[\]=all" > /dev/null
curl -s $HTTP_AUTH -b $COOKIEJAR -c $COOKIEJAR "$LIBRARIAN_URL/export.php?export_files=session&export=1&column%5B%5D=Unique+ID&column%5B%5D=Authors&column%5B%5D=Title&column%5B%5D=Journal&column%5B%5D=Year&column%5B%5D=Volume&column%5B%5D=Pages&column%5B%5D=Issue&column%5B%5D=Secondary+Title&column%5B%5D=DOI&format=BibTex&latex=1&style=text&encoding=utf-8&output=inline" | sed 's/<html><body><pre>//;s/<\/pre><\/body><\/html>//'

# cleanup
rm $COOKIEJAR

Update, 15/10/2014: For newer releases, the script needs a small modification: change the data argument of the next to last curl command from

--data "form=signin&user=$LIBRARIAN_AUTH_USER&pass=$LIBRARIAN_AUTH_PASS" 

to

--data "form=signin&user=$LIBRARIAN_AUTH_USER&pass=$LIBRARIAN_AUTH_PASS&keepsigned=1" 

You may also like...

2 Responses

  1. Hugo Stig says:

    Hi. After updating my install to http://i-librarian.net/, the script does not work any more, it only says signed_out. Do you hav a fix? Thanx

Leave a Reply

Your email address will not be published.