The truth is rarely pure and never simple

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<code class="tex2jax_ignore">\[\]</code>=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" 

Leave a comment

Your email address will not be published.

2 thoughts on “I, Librarian BibTeX export via command line”