Title photo
frugal technology, simple living and guerrilla large-appliance repair
Fri, 07 Mar 2014

Script to sync and/or reindex your Indexette-enabled Ode site in Unix/Linux systems

I decided to script my blog updates via a Bash script for Unix/Linux that runs both my Unison sync and the Indexette reindexing necessary to to make those entries live.

You're probably not running Unison like I am (and I still need to write up my Unison tutorial), but the reindexing line is worth sharing because I find it very useful to reindex the blog without using the web browser.

First of all, you need to install wget on your Unix/Linux system. It's available in just about every distribution. Use your favorite package manager to install it.

There are two ways to run this line. One is verbose (with output to the screen), the other silent (no output).

Here is the "verbose" script:

#! /bin/bash

# Use this line to update your site if you can do that
# from the command line. I use Unison. The line is commented
# out so you can see it and replace it with what you use, or just
# leave it commented out.
# Note on Unison switches: -batch syncs the sites with no user 
# intervention in the console. It won't do anything that absolutely
# requires the user to make a choice between server and client
# copies of a file.

# unison ode -batch

# This is the wget line. Replace path/to/your/blog
# with the actual URL of your site. Do not add http://
# as it is not needed for wget to do its thing 

# Note on wget: The --spider switch allows you to
# access the site but not actually download the
# HTML as a file on your computer

wget --spider path/to/your/blog/?reindex=y
exit 0

Here is the "quiet" script:

<code>#! /bin/bash

# Use this line to update your site if you can do that
# from the command line. I use Unison. The line is commented
# out so you can see it and replace it with what you use, or just
# leave it commented out.
# Note on Unison switches: -batch syncs the sites with no user 
# intervention in the console. It won't do anything that absolutely
# requires the user to make a choice between server and client
# copies of a file. -silent keeps any output from going to the console.

# unison ode -batch -silent

# This is the wget line. Replace path/to/your/blog
# with the actual URL of your site. Do not add http://
# as it is not needed for wget to do its thing 

# Note on wget: The --spider switch allows you to
# access the site but not actually download the
# HTML as a file on your computer.
# The -q switch "quiets" the output to the console.

wget --spider -q path/to/your/blog/?reindex=y
exit 0

Remember, you can run this script without the Unison line and just do the wget portion. I use this script after I write an entry on my local drive. I write the entry, then run the script, which syncs my file to the server and then runs an Indexette reindexing.

You can also just run the wget on the command line:

$ wget --spider -q path/to/your/blog/?reindex=y

I prefer to do this as a script. I have named these odeupdatesilent and odeupdateloud.

I find that writing these little two-line scripts are both an exercise in easy programming as well as a way to automate repetitive tasks.

If you don't write a lot of scripts, it's a good idea to do a bit of Googling on how to make a script executable:

$ chmod a+x scriptname

Then you can run it like this:

$ ./scriptname

If you stash the script in a directory that allows you to run executables (I use /usr/local/bin, which is usually in your path, but not always -- I had to add this in Fedora), you can run the script without ./

$ scriptname

It's definitely worth looking in a beginning Linux/Unix command line book to see how scripts are created and run. I'm lazy enough that I just Google when I need to remember something, but a good book doesn't hurt.

I promise to write up my Unison tutorial soon. Rsync is another great way to update a site, but it's still a one-way push, whereas Unison is a syncing application that allows for updates on either side (client or server) to be pushed in the other direction.

Before Unison, I was working over SFTP (in my case within various Linux/Unix file managers), which is still a great way to work on an Ode site. But I like Unison better.

And I like using wget better than entering the reindex=y line in the browser. That's why I cooked up this easy 1-line script (with an extra line for my syncing before that).

Update: Using curl instead of wget (making it easier for Macintosh users):

Same scripts with curl and Unison line commented out:

Verbose:

#! /bin/bash

# Uncomment next line to use Unison, or replace with your own file-pushing line
# unison ode -batch
curl  path/to/your/ode/blog/?reindex=y > /dev/null
exit 0

Silent:

#! /bin/bash

# Uncomment next line to use Unison, or replace with your own file-pushing line
# unison ode -batch -silent
curl -s path/to/your/ode/blog/?reindex=y > /dev/null
exit 0

Notes: Curl is available in all OS X systems, so you don't have to find, compile and install wget if you don't want to.

Switches and redirected output for curl: -s quiets the command's output. To keep the HTML output off the screen in the console, I am sending it to where all things we never want to see go in Unix: /dev/null.