<?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&#039;s 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 Programming, Ruby on Rails, Wordpress, PHP from Burlington, Vermont</description>
	<lastBuildDate>Wed, 18 Jan 2012 21:44:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Backup and Rotate MySQL Databases Simple Bash Script</title>
		<link>http://seanbehan.com/databases/backup-and-rotate-mysql-databases-simple-bash-script/</link>
		<comments>http://seanbehan.com/databases/backup-and-rotate-mysql-databases-simple-bash-script/#comments</comments>
		<pubDate>Sat, 04 Jun 2011 16:29:48 +0000</pubDate>
		<dc:creator>bseanvt</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[backups]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[mysqldump]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=1343</guid>
		<description><![CDATA[Make a directory ( it can anywhere ) called baks/mysql mkdir -p /baks/mysql Create a file (it can be anywhere) called /root/mysql_backups.sh and put this script in it #!/bin/bash # modify the following to suit your environment export DB_BACKUP=&#34;/baks/mysql&#34; export DB_USER=&#34;root&#34; export DB_PASSWD=&#34;your-mysql-password-goes-here&#34; # title and version echo &#34;&#34; echo &#34;Backup and rotate all mysql [...]]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fseanbehan.com%2Fdatabases%2Fbackup-and-rotate-mysql-databases-simple-bash-script%2F&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="Backup and Rotate MySQL Databases Simple Bash Script" data-url="http://seanbehan.com/databases/backup-and-rotate-mysql-databases-simple-bash-script/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><p>Make a directory ( it can anywhere ) called baks/mysql</p>
<pre class="wp-code-highlight prettyprint">
mkdir -p /baks/mysql
</pre>
<p>Create a file (it can be anywhere) called /root/mysql_backups.sh and put this script in it</p>
<pre class="wp-code-highlight prettyprint">
#!/bin/bash

# modify the following to suit your environment
export DB_BACKUP=&quot;/baks/mysql&quot;
export DB_USER=&quot;root&quot;
export DB_PASSWD=&quot;your-mysql-password-goes-here&quot;

# title and version
echo &quot;&quot;
echo &quot;Backup and rotate all mysql databases&quot;
echo &quot;--------------------------&quot;

rm -rf $DB_BACKUP/04
mv $DB_BACKUP/03 $DB_BACKUP/04
mv $DB_BACKUP/02 $DB_BACKUP/03
mv $DB_BACKUP/01 $DB_BACKUP/02
mkdir $DB_BACKUP/01

echo &quot;* Creating backup...&quot;
mysqldump --user=$DB_USER --password=$DB_PASSWD --all-databases | bzip2 &gt; $DB_BACKUP/01/mysql-`date +%Y-%m-%d`.bz2
echo &quot;----------------------&quot;
echo &quot;Done&quot;
exit 0
</pre>
<p>Install it via cron and have it run at 3:10 am every morning.</p>
<pre class="wp-code-highlight prettyprint">
crontab -e

10 3 * * * /root/mysql_backups.sh  &gt; /baks/status.log
</pre>
<p>This script will save the last 4 days of data.</p>
]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/databases/backup-and-rotate-mysql-databases-simple-bash-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>bseanvt</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 [...]]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fseanbehan.com%2Fruby-on-rails%2Fuse-a-cron-job-to-automate-sphinx-index-refresh-from-rails-rake-task%2F&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="Use a Cron Job to Automate Sphinx Index Refresh from Rails Rake Task" data-url="http://seanbehan.com/ruby-on-rails/use-a-cron-job-to-automate-sphinx-index-refresh-from-rails-rake-task/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><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 class="wp-code-highlight prettyprint">
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 :(</p>
<p>You find your specific PATH and SHELL info like so</p>
<pre class="wp-code-highlight prettyprint">
echo $PATH
echo $SHELL
</pre>
<p>To get into the cron and set your schedule</p>
<pre class="wp-code-highlight prettyprint">
crontab -e
</pre>
<pre class="wp-code-highlight prettyprint">
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 &amp;&amp; /usr/local/bin/rake thinking_sphinx:index &gt;&gt; /dev/null 2&gt;&amp;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>
]]></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>4</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>bseanvt</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 [...]]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fseanbehan.com%2Fprogramming%2Fset-cron-job-to-run-every-five-minutes-for-a-ruby-on-rails-rake-task%2F&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="Set Cron Job to Run Every Five Minutes for a Ruby on Rails Rake Task" data-url="http://seanbehan.com/programming/set-cron-job-to-run-every-five-minutes-for-a-ruby-on-rails-rake-task/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><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 class="wp-code-highlight prettyprint">
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 class="wp-code-highlight prettyprint">
# 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 class="wp-code-highlight prettyprint">
*/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 class="wp-code-highlight prettyprint">
*/5 * * * * cd /var/www/my_ror_application  &amp;amp;&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>
]]></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>

