best way to reindex sphinx in ubuntu hardy - linux

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?

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.

Here is what I do to reindex and then restart the search daemon once a day.
* * /1 * * root cd /home/sphinx && bin/indexer --all --rotate && bin/searchd --stop && bin/searchd

Related

how to specify multi time in cron expression

Is it possible to have one cron expression to run at 6am and 7:30pm every day?. I understand the following will will run 6am, 6:30am, 7:00pm and 7:30pm,
0,30 6,19 * * *
How will I schedule 6am and 7:30pm in one cron?
You can put more intelligence into the command that gets run, something like:
0,30 6,19 * * * t=T$(date +%H%M) ; [ ${t} = T0600 -o ${t} = T1930 ] && payload
This will actually run the crontab command four times a day (at 6am, 6:30am, 7pm and 7:30pm) but execute the payload proper only at 6am and 7:30pm as desired.
Some people opt to put this extra intelligence into a script that gets run and simply exits if the time isn't one of the desired ones, but I tend to prefer keeping all scheduling control in the crontab file itself.

Using a crontab to gzip a file

I need to make a crontab to gzip a file named mh located on my desktop every 2 minutes in the same path. I tried
2 * * * * gzip home/Desktop/mh >> home/Desktop
But it is not working, any help is greatly appreciated.
There are several errors here.
The gzip command should be simply gzip home/Desktop/mh. Remove the >> and everything afterwards.
Your current cron will only run on the second minute of every hour. Instead you want */30 * * * * ... to run 30 times per hour.
Note that gzip is "destructive" in the sense that your original file (mh) will disappear after each gzip. That would be bad if some other process is trying to write to it continually...
If you want to keep the content of mh and just update mh.gz from it periodically, you want to do
*/30 * * * * gzip < /home/Desktop/mh > /home/Desktop/mh.gz

Run a cron job hourly in a set window

My crontab file looks like this:
00 07-22 * * * /usr/bin/php /ab/c.php
but rather than running from 7am to 10pm, it runs at midnight as well. I want it strictly run every hour between 7 am to 10 pm.
Did you try to remove the leading 0s? They can cause you problems. Try
0 7-22 * * * /usr/bin/php /ab/c.php
Besides the 0s which sound strange to me (I never used them), the rest seems ok. Hope this help.

Creating a Named Cron Job

How do you create a cron job from the command line, so that it shows up with a name in gnome-schedule?
I know how to create a cron job using crontab. However, all my jobs show up with a blank name. I'd like to better document my jobs so I can easily identify them in gnome-schedule, or similar cron wrapper.
Well, just made a cronjob in Scheduler, and took a look at my crontab file, and it looked like this:
0 0 * * * ls >/dev/null 2>&1 # JOB_ID_1
Notice the JOB_ID_1 at the end.
I went into ~/.gnome/gnome-scheduler/, looked at the files there, and there was one named just 1 (as in the number "one") which had a bit of info, including the name
ver=3
title=Hello
desc=
nooutput=1
So, I made a second cronjob:
0 0 * * * ls -al >/dev/null 2>&1 # JOB_ID_2
Copied the file 1 to 2 to match the JOB_ID_2, changed the description, making the file as:
ver=3
title=This is a test
desc=
nooutput=1
Then I switched over to Gnome-Schedule, and it had added the cronjob, and had the name updated.
Follow the same steps, and you should be able to manually name any cronjob you want

Is there a special restriction on commands executed by cron? [duplicate]

This question already has an answer here:
How is % (percent sign) special in crontab?
(1 answer)
Closed 4 years ago.
I have a crontab that looks like
0 0 * * * pg_dump DB_NAME > /path/to/dumps/`date +%Y%m%d`.dmp
which works fine when I run it manually, but not when cron runs it. After digging through the logs, I see
Dec 12 00:00:01 localhost crond[17638]: (postgres) CMD (pg_dump DB_NAME > /path/to/dumps/`date +)
It looks like a problem with percent signs, but the man page doesn't even contain the percent character at all, so I thought they were alright.
You have to escape percent signs with a backslash:
0 0 * * * pg_dump DB_NAME > /path/to/dumps/`date +\%Y\%m\%d`.dmp
From man 5 crontab:
The ‘‘sixth’’ field (the rest of the line) specifies the command to
be
run. The entire command portion of the line, up to a
newline or %
character, will be executed by /bin/sh or by the shell specified in
the
SHELL variable of the crontab file. Percent-signs (%) in the
command,
unless escaped with backslash (\), will be changed into newline
characters, and all data after the first % will be sent to the command
as
standard input. There is no way to split a single command line
onto
multiple lines, like the shell’s trailing "\".
There's another characteristic problem that can affect programs run by cron as compared with the command line (other than the interpretation of '%' signs described by Robert Gamble).
That difference is in the environment. If the program run relies on special environment variables, then it will work when you run it from the command line, with the environment you normally use, and it will likely work if you run it with at because that captures the environment when you create the job. But cron does no special environment setting.
I habitually, therefore, configure cron to run scripts by absolute pathname, and that script does the environment setting that I need (adds my $HOME/bin directory to PATH, for example). I even have a standardized infrastructure for this - a shell script that sets the environment and runs other programs.
# #(#)$Id: crontab,v 4.2 2007/09/17 02:41:00 jleffler Exp $
# Crontab file for Home Directory for Jonathan Leffler (JL)
#-----------------------------------------------------------------------------
#Min Hour Day Month Weekday Command
#-----------------------------------------------------------------------------
0 * * * * /usr/bin/ksh /work1/jleffler/bin/Cron/hourly
1 1 * * * /usr/bin/ksh /work1/jleffler/bin/Cron/daily
23 1 * * 1-5 /usr/bin/ksh /work1/jleffler/bin/Cron/weekday
2 3 * * 0 /usr/bin/ksh /work1/jleffler/bin/Cron/weekly
21 3 1 * * /usr/bin/ksh /work1/jleffler/bin/Cron/monthly
The script in /work1/jleffler/bin/Cron sets the environment and then runs the script of the same name in /work1/jleffler/bin to do the real work. The names in the Cron sub-directory are actually all links to the same script.

Resources