Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
cron script for keeping eXist in sync with a filesystem
#!/bin/bash
#
# Load incremental changes since the last load. This script maintains a
# hidden file that keeps track of this information.
#
# UTILS
DATE="/bin/date"
CURL="/usr/bin/curl"
ECHO="/bin/echo"
FIND="/usr/bin/find"
TOUCH="/usr/bin/touch"
TIMESTAMP_FILE=".last_load"
DATE_LOG_FMT="+[%c] "
DB_USER="user:pw"
# Below resolves to a small xq that does a few checks on the record before it loads it into the db
SERVICE="http://localhost:8080/exist/loader"
# Source data
DATA_HOME="/path/to/my/data"
# FUNCTIONS
BODY=
post_to_exist() {
resp=
resp=$($CURL -X POST \
--data-binary @$BODY \
-H "Content-type: application/xml" \
-u "$DB_USER" "$SERVICE" \
-o "/dev/null" \
-sS -w "%{http_code}\n")
$ECHO $resp
}
findcmd="$FIND $DATA_HOME -name "*.xml" -newer $TIMESTAMP_FILE" # -newer is the magic!
for record in $($findcmd); do
BODY=$record
response_code=$(post_to_exist)
$ECHO $($DATE $DATE_LOG_FMT) $record ":" $response_code
response_code=
BODY=
done
$TOUCH $TIMESTAMP_FILE
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment