<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sean Behan&#039;s Web Development Portfolio and Blog &#187; cron</title>
	<atom:link href="http://seanbehan.com/tag/cron/feed/" rel="self" type="application/rss+xml" />
	<link>http://seanbehan.com</link>
	<description>Web Development, Wordpress, Moodle, Ruby on Rails and Design in Burlington, Vermont</description>
	<lastBuildDate>Fri, 30 Jul 2010 17:17:12 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Use a Cron Job to Automate Sphinx Index Refresh from Rails Rake Task</title>
		<link>http://seanbehan.com/ruby-on-rails/use-a-cron-job-to-automate-sphinx-index-refresh-from-rails-rake-task/</link>
		<comments>http://seanbehan.com/ruby-on-rails/use-a-cron-job-to-automate-sphinx-index-refresh-from-rails-rake-task/#comments</comments>
		<pubDate>Sun, 12 Jul 2009 03:56:36 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[rake]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=436</guid>
		<description><![CDATA[If using Sphinx, you need to refresh indexes when you add new content to your database. This is fairly easy to do by hand 

rake thinking_sphinx:index RAILS_ENV=production

But if you want to automate this and use a cron, remember to set the PATH, SHELL and RAILS_ENV variables for your job. The environment isn&#8217;t the same when [...]


Related posts:<ol><li><a href='http://seanbehan.com/programming/set-cron-job-to-run-every-five-minutes-for-a-ruby-on-rails-rake-task/' rel='bookmark' title='Permanent Link: Set Cron Job to Run Every Five Minutes for a Ruby on Rails Rake Task'>Set Cron Job to Run Every Five Minutes for a Ruby on Rails Rake Task</a></li>
<li><a href='http://seanbehan.com/programming/installing-sphinx-search-engine-on-mac-os-x-or-ld-library-not-found-for-lmysqlclient/' rel='bookmark' title='Permanent Link: Installing Sphinx Search Engine on Mac OS X&#8230; or ld: library not found for -lmysqlclient'>Installing Sphinx Search Engine on Mac OS X&#8230; or ld: library not found for -lmysqlclient</a></li>
<li><a href='http://seanbehan.com/linux/how-to-get-your-users-shell-and-path-information/' rel='bookmark' title='Permanent Link: How to Get Your User&#8217;s SHELL and PATH Information'>How to Get Your User&#8217;s SHELL and PATH Information</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>If using Sphinx, you need to refresh indexes when you add new content to your database. This is fairly easy to do by hand </p>
<pre>
rake thinking_sphinx:index RAILS_ENV=production
</pre>
<p>But if you want to automate this and use a cron, remember to set the PATH, SHELL and RAILS_ENV variables for your job. The environment isn&#8217;t the same when you&#8217;re doing it by hand and your index will fail silently <img src='http://seanbehan.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>You find your specific PATH and SHELL info like so </p>
<pre>
echo $PATH
echo $SHELL
</pre>
<p>To get into the cron and set your schedule</p>
<pre>
crontab -e
</pre>
<pre>
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
SHELL=/bin/bash
RAILS_ENV=production

# re-index production sphinx every 15 minutes
*/15 * * * * root cd /var/www/rails_app &#038;&#038; /usr/local/bin/rake thinking_sphinx:index >> /dev/null 2>&#038;1
</pre>
<p>More information available here</p>
<p>http://heimdull.blogspot.com/2009/05/journey-with-thinking-sphinx-and-crond.html</p>
<p>http://groups.google.com/group/thinking-sphinx/browse_thread/thread/5451458fae7d6124</p>


<p>Related posts:<ol><li><a href='http://seanbehan.com/programming/set-cron-job-to-run-every-five-minutes-for-a-ruby-on-rails-rake-task/' rel='bookmark' title='Permanent Link: Set Cron Job to Run Every Five Minutes for a Ruby on Rails Rake Task'>Set Cron Job to Run Every Five Minutes for a Ruby on Rails Rake Task</a></li>
<li><a href='http://seanbehan.com/programming/installing-sphinx-search-engine-on-mac-os-x-or-ld-library-not-found-for-lmysqlclient/' rel='bookmark' title='Permanent Link: Installing Sphinx Search Engine on Mac OS X&#8230; or ld: library not found for -lmysqlclient'>Installing Sphinx Search Engine on Mac OS X&#8230; or ld: library not found for -lmysqlclient</a></li>
<li><a href='http://seanbehan.com/linux/how-to-get-your-users-shell-and-path-information/' rel='bookmark' title='Permanent Link: How to Get Your User&#8217;s SHELL and PATH Information'>How to Get Your User&#8217;s SHELL and PATH Information</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/ruby-on-rails/use-a-cron-job-to-automate-sphinx-index-refresh-from-rails-rake-task/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Set Cron Job to Run Every Five Minutes for a Ruby on Rails Rake Task</title>
		<link>http://seanbehan.com/programming/set-cron-job-to-run-every-five-minutes-for-a-ruby-on-rails-rake-task/</link>
		<comments>http://seanbehan.com/programming/set-cron-job-to-run-every-five-minutes-for-a-ruby-on-rails-rake-task/#comments</comments>
		<pubDate>Tue, 21 Apr 2009 00:12:58 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[rake]]></category>

		<guid isPermaLink="false">http://bseanvt.wordpress.com/?p=188</guid>
		<description><![CDATA[First off you&#8217;ll need to edit your cron file. Normally, the cron files are kept under /etc/cron.daily or /etc/cron.hourly but we can just use the command line tool, crontab and pass it the -e flag, so that we can edit the file without any fuss.

sudo crontab -e

If this is the first cron you&#8217;re installing you [...]


Related posts:<ol><li><a href='http://seanbehan.com/ruby-on-rails/use-a-cron-job-to-automate-sphinx-index-refresh-from-rails-rake-task/' rel='bookmark' title='Permanent Link: Use a Cron Job to Automate Sphinx Index Refresh from Rails Rake Task'>Use a Cron Job to Automate Sphinx Index Refresh from Rails Rake Task</a></li>
<li><a href='http://seanbehan.com/ruby-on-rails/rake-db-everything-dump-destroy-create-load/' rel='bookmark' title='Permanent Link: Rake DB Everything, Dump, Destroy, Create, Load'>Rake DB Everything, Dump, Destroy, Create, Load</a></li>
<li><a href='http://seanbehan.com/programming/ruby-strftime-method-arguments/' rel='bookmark' title='Permanent Link: Ruby strftime() method arguments'>Ruby strftime() method arguments</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>First off you&#8217;ll need to edit your cron file. Normally, the cron files are kept under /etc/cron.daily or /etc/cron.hourly but we can just use the command line tool, crontab and pass it the -e flag, so that we can edit the file without any fuss.</p>
<pre>
sudo crontab -e
</pre>
<p>If this is the first cron you&#8217;re installing you should see a blank file or something that looks like this</p>
<pre>
# m h  dom mon dow   command
</pre>
<p>Essentially this is telling you the order of the arguments you need to specify. Each asterisk represents an interval of time. In this order they are</p>
<p>Minute, Hour, Day of Month, Month, Day of Week and then the path to your command. So to set up our cron to run once every five minutes we&#8217;ll write</p>
<pre>
*/5 * * * * /path/to/my/script
</pre>
<p>It&#8217;s important to note that it is */5 and not just 5. The interval for minute is 0 &#8211; 59, meaning that if you just enter a 5, you&#8217;ll run your cron job only once an hour but at the 5th minute of that hour. To specify that we want to run it every 5 minutes we need the */5.  Also, note that the cron will execute your command via the path. If you need an interpreter like ruby, rake or php, don&#8217;t forget to put that as a part of your command. For instance this will set a rake task to run every five minutes on a Ubuntu box.</p>
<pre>
*/5 * * * * cd /var/www/my_ror_application  &amp;&amp; /usr/bin/rake RAILS_ENV=development db:migrate
</pre>
<p>You can see that my command uses cd, changing directories to my application. I then specify the full path to the rake program, /usr/bin/rake and give it arguments, including the environment and then of course, the task I want to execute. In this case I&#8217;m migrating the database. Which is obviously pointless. Maybe you&#8217;ll want to email forum news or send out activation emails.</p>
<p>For more information here is a great reference <a href="http://mkaz.com//ref/unix_cron.html">mkaz.com</a></p>


<p>Related posts:<ol><li><a href='http://seanbehan.com/ruby-on-rails/use-a-cron-job-to-automate-sphinx-index-refresh-from-rails-rake-task/' rel='bookmark' title='Permanent Link: Use a Cron Job to Automate Sphinx Index Refresh from Rails Rake Task'>Use a Cron Job to Automate Sphinx Index Refresh from Rails Rake Task</a></li>
<li><a href='http://seanbehan.com/ruby-on-rails/rake-db-everything-dump-destroy-create-load/' rel='bookmark' title='Permanent Link: Rake DB Everything, Dump, Destroy, Create, Load'>Rake DB Everything, Dump, Destroy, Create, Load</a></li>
<li><a href='http://seanbehan.com/programming/ruby-strftime-method-arguments/' rel='bookmark' title='Permanent Link: Ruby strftime() method arguments'>Ruby strftime() method arguments</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/programming/set-cron-job-to-run-every-five-minutes-for-a-ruby-on-rails-rake-task/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
