views:

444

answers:

1

Hi,

I'm running a slice of ubuntu hardy. I've installed sphinx, and I would like to run the sphinx indexer every x minutes. What is the best way to go about doing this?

+2  A: 

The standard Unix approach is cron, so you could for example edit /etc/crontab and add a line like

*/5 * * * *     root    sphynx [whatever other options you need]

which means

  • 'every five minutes' (for the */5 part)
  • of every hour (the * in position 2)
  • of every day of the month (the * in position 3)
  • of every month (the * in position 4)
  • of every day of the week (the final * in position 5)

Another example: '4 5 * * 6' amounts to 'at 5:04am (four minutes after five) on every Saturday (day of the week is 6).

You may need to or want to switch the user from root to, say, www-data is sphynx runs as that, and you obviously need to adjust the arguments.

Lastly, look into the directories

$ ls -1d /etc/cron.*
/etc/cron.d
/etc/cron.daily
/etc/cron.hourly
/etc/cron.monthly
/etc/cron.weekly

for examples --- other packages put their jobs there (and this mechanism is more general, and newer, than direct editing of /etc/crontab.

Dirk Eddelbuettel