--- /dev/null
+#!/bin/bash
+
+WORKDIR="$PWD"
+PSQL="/usr/bin/psql"
+PSQL_USER="mydbuser"
+SQL_FILE="get_ids.sql"
+DB_HOST="mydbhostname"
+DB_NAME="mydbname"
+OUTDIR="bib_ids"
+OUTFILE="bib_ids_`date +%F`.out"
+BIBDATE=`cat last_export_date`
+EXPORT="pines_bib_update_`date +%F`.mrc"
+EXPORT_DIR="out"
+FTP_HOST="tld.example.com"
+FTP_USER="myftpuser"
+FTP_PASS="myftppath"
+FTP_PATH="myftpremotedirectory"
+ADMIN_EMAIL="my-sys-admins@example.com"
+
+CreateBibList () {
+if [ -z $BIBDATE ]; then
+ read -p "No last export date known. Please provide the date at which you want to begin export (YYYY-MM-DD): " BIBDATE
+ echo "$BIBDATE" | egrep '^20[0-9][0-9]-[0-1][0-9]-[0-3][0-9]$' > /dev/null
+ if [ $? -ne 0 ]; then
+ echo "$BIBDATE is not a valid date. Please start over."
+ exit 1;
+ fi
+fi
+
+$PSQL -U $PSQL_USER -h $DB_HOST -A -t -o $OUTDIR/$OUTFILE -v bibdate="'$BIBDATE'" -f $SQL_FILE $DB_NAME
+}
+
+
+ExportBibs () {
+cat $OUTDIR/$OUTFILE | /openils/bin/marc_export --items --encoding UTF-8 > $EXPORT_DIR/$EXPORT
+date +%F > last_export_date
+}
+
+FTPBibFile () {
+cd $EXPORT_DIR
+pftp -n -v $FTP_HOST <<EOT
+user $FTP_USER $FTP_PASS
+cd $FTP_PATH
+put $EXPORT
+bye
+EOT
+cd $WORKDIR
+}
+
+echo "GALILEO EDS bib export began at `date`." | mutt -s "GALILEO EDS Export Begun" $ADMIN_EMAIL
+CreateBibList
+ExportBibs
+FTPBibFile
+echo "GALILEO EDS bib export completed at `date`." | mutt -s "GALILEO EDS Export Completed" $ADMIN_EMAIL
--- /dev/null
+select distinct bre.id
+ from biblio.record_entry bre
+ join asset.call_number acn on (
+ acn.record = bre.id
+ ) join asset.copy acp on (
+ acp.call_number = acn.id and (
+ (
+ -- we want both bibs for newly created items since bibdate...
+ not acp.deleted
+ and acp.create_date::date > :bibdate
+ ) or (
+ -- ...and bibs for items deleted since bibdate
+ acp.deleted
+ and acp.edit_date > :bibdate
+ )
+ )
+ )
+ where bre.id > 0 -- we don't want -1
+ and not bre.deleted
+ order by id;