From time to time, I find myself wanting to run BaseX server commands from a shell script. For example, if I have two or three documents I'd like to add to a database, it's easy enough to do so from the GUI interface, or from the interactive server prompt. But if it's five or ten documents (and even more so if it's a few hundred or a few thousand documents), entering the commands interactively can become tedious and error prone. When the files are available on the local file system, I can use wildcards and I can add a directory at a time. But when the files are on a remote server and identified by URI instead of file name, I guess that won't work.
What I think I'm looking for is the ability to specify a sequence of BaseX server commands and have it run that sequence of commands -- or some other way of being able to specify a list of filenames or URIs and have them all added to a given database.
For example
CREATE DATABASE demo OPEN demo ADD http://example.com/docs/a.xml ADD http://example.com/docs/b.xml ADD http://example.com/docs/c.xml ADD http://example.com/docs/d.xml ADD http://example.com/docs/e.xml ... ADD http://example.com/docs/z.xml
RENAME http://example.com/docs/ /
# I'd use ADD to a.xml http://example.com/docs/a.xml, but # that doesn't seem to have the effect I expect. But # RENAME works for what I need
There is certainly a lot of BaseX documentation I have not read, but I have not found any mention of this kind of thing. Have I overlooked it?
One technique that I guess would work would be to exploit the new REST interface (very nice, by the way!) and write a bash script that went something like this:
curl http://localhost:8984/rest?command=CREATE+DATABASE+demo
curl http://localhost:8984/rest/demo?command=ADD+http://example.com/docs/a.xml curl http://localhost:8984/rest/demo?command=ADD+http://example.com/docs/b.xml curl http://localhost:8984/rest/demo?command=ADD+http://example.com/docs/c.xml curl http://localhost:8984/rest/demo?command=ADD+http://example.com/docs/d.xml curl http://localhost:8984/rest/demo?command=ADD+http://example.com/docs/e.xml ... curl http://localhost:8984/rest/demo?command=ADD+http://example.com/docs/z.xml
curl http://localhost:8984/rest/demo?command=RENAME+http://example.com/docs/+/
or rather
CURL="curl --user X:secretpasswd" $CURL http://localhost:8984/rest?command=CREATE+DATABASE+demo etc.
But if there is s nicer way to handle this case, I'd be glad to learn about it.
Perhaps this is when I should buckle down and learn how to do this kind of thing with XQuery Update?
Thanks!
Michael Sperberg-McQueen