Skip to content

Instantly share code, notes, and snippets.

@jpstroop
Created April 22, 2012 11:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpstroop/2463821 to your computer and use it in GitHub Desktop.
Save jpstroop/2463821 to your computer and use it in GitHub Desktop.
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