<?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>GFMorris.org &#187; Shell Scripts</title>
	<atom:link href="http://gfmorris.org/categories/shell-scripts/feed/" rel="self" type="application/rss+xml" />
	<link>http://gfmorris.org</link>
	<description>Smart Guy, Dumb Code</description>
	<lastBuildDate>Sat, 17 Jul 2010 15:39:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Planet, Shell Scripts, and Binary Locations</title>
		<link>http://gfmorris.org/archives/2006/07/13/planet-shell-scripts-and-binary-locations/</link>
		<comments>http://gfmorris.org/archives/2006/07/13/planet-shell-scripts-and-binary-locations/#comments</comments>
		<pubDate>Thu, 13 Jul 2006 18:11:28 +0000</pubDate>
		<dc:creator>Geof F. Morris</dc:creator>
				<category><![CDATA[Planet]]></category>
		<category><![CDATA[Shell Scripts]]></category>

		<guid isPermaLink="false">http://gfmorris.org/archives/2006/07/13/planet-shell-scripts-and-binary-locations/</guid>
		<description><![CDATA[I ran into some issues in the last week or so with getting my Planet-updating shell script invoked by CRON; it would run when I ran the script by hand, but it wouldn&#8217;t run when cPanel&#8217;s CRON spooler would try to invoke it. I was getting the following error: Traceback (most recent call last): File [...]]]></description>
			<content:encoded><![CDATA[<p>I ran into some issues in the last week or so with getting <a href="http://gfmorris.org/archives/2006/05/23/shell-script-for-planetplanet-cron-job/">my Planet-updating shell script</a> invoked by CRON; it would run when I ran the script by hand, but it wouldn&#8217;t run when cPanel&#8217;s CRON spooler would try to invoke it.  I was getting the following error:</p>
<blockquote><p>Traceback (most recent call last):<br />
  File &#8220;./planet.py&#8221;, line 23, in ?<br />
    import planet<br />
  File &#8220;./planet/__init__.py&#8221;, line 23, in ?<br />
    from planet.truncate import _TruncateHTMLProcessor<br />
  File &#8220;./planet/truncate.py&#8221;, line 2, in ?<br />
    import textwrap<br />
ImportError: No module named textwrap</p></blockquote>
<p>After looking confused for a while, I talked to my local python guru, <a href="http://grandes.com/">Stephen Granade</a>, and he pointed something out to me: textwrap.py is a Python 2.3-era addition, so I probably had a Python environment issue.  [My server has 2.2.x and 2.4.x installed.  Silly cPanel.]</p>
<p>Armed with this knowledge, I futzed around for a while and figured out that my shell script was missing an invocation of the Python environment.  I have updated it:</p>
<blockquote><p><code>#!/bin/csh -f<br />
cd /home/path/to/planet<br />
/path/to/python/binary ./planet.py ./config.ini</code></p></blockquote>
<p>Consult your system adminstrator if you don&#8217;t know /path/to/python/binary.  If you&#8217;re the sysadmin and can&#8217;t find the Python binary, please ram your forehead into your desk repeatedly.</p>
<p>Thanks again, Stephen.  I owe you a beer.</p>
<img src="http://gfmorris.org/wordpress/?ak_action=api_record_view&id=23&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://gfmorris.org/archives/2006/07/13/planet-shell-scripts-and-binary-locations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shell Script for PlanetPlanet CRON Job</title>
		<link>http://gfmorris.org/archives/2006/05/23/shell-script-for-planetplanet-cron-job/</link>
		<comments>http://gfmorris.org/archives/2006/05/23/shell-script-for-planetplanet-cron-job/#comments</comments>
		<pubDate>Tue, 23 May 2006 13:13:10 +0000</pubDate>
		<dc:creator>Geof F. Morris</dc:creator>
				<category><![CDATA[Planet]]></category>
		<category><![CDATA[Shell Scripts]]></category>

		<guid isPermaLink="false">http://gfmorris.org/archives/2006/05/23/shell-script-for-planetplanet-cron-job/</guid>
		<description><![CDATA[Has Sam Ruby gotten you excited about PlanetPlanet, even though you don&#8217;t know Python from Perl? Got it running, but don&#8217;t have a clue how to get CRON up and running with a shell script? Yeah, that was me yesterday. Google provided some help, eventually, but I&#8217;ll break it down a little more for you: [...]]]></description>
			<content:encoded><![CDATA[<p>Has <a href="http://www.intertwingly.net/blog/">Sam Ruby</a> gotten you excited about <a href="http://planetplanet.org/">Planet<strike>Planet</strike></a>, even though you don&#8217;t know Python from Perl?  Got it running, but don&#8217;t have a clue how to get CRON up and running with a shell script?  Yeah, that was me yesterday.  Google provided some help, eventually, but I&#8217;ll break it down a little more for you:</p>
<ol>
<li><strong>Make sure all your file permissions are right</strong>.  Half of my hell yesterday was having done all the work as root but not having CHOWN&#8217;d and CHGRP&#8217;d as appropriate.</li>
<li><strong><a href="http://support.invisionfree.com/index.php?showtopic=252790">Use your shell script to change to the appopriate directory before invoking planet.py</a></strong>.  I&#8217;d never really had to do that, as I&#8217;m still a babe in the shell-scripting woods.  But if you go in, cd to the /path/to/your/planet.py, then invoke ./planet.py /path/relative/to/config.ini, you&#8217;ll be rockin&#8217;.</li>
</ol>
<p>My shell script looks like:</p>
<blockquote><p><code>#!/bin/csh -f<br />
cd /home/path/to/planet<br />
/path/to/python/binary ./planet.py ./config.ini</code></p></blockquote>
<p>Now, I simplified things by putting config.ini and planet.py in the same folder.  If you didn&#8217;t [for example, if you're using examples/basic/config.ini just for funsies], you&#8217;d just invoke ./planet.py ./path/examples/basic/config.ini.</p>
<p>Thanks, Sam, for pushing me over the edge to play with Planet<strike>Planet</strike>.  Now it&#8217;s time to get the templates like I want them so I can start using it in production.  <img src='http://gfmorris.org/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<img src="http://gfmorris.org/wordpress/?ak_action=api_record_view&id=21&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://gfmorris.org/archives/2006/05/23/shell-script-for-planetplanet-cron-job/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Stripping Unwanted Referrers from Refer Database</title>
		<link>http://gfmorris.org/archives/2004/05/28/stripping-unwanted-referrers-from-refer-database/</link>
		<comments>http://gfmorris.org/archives/2004/05/28/stripping-unwanted-referrers-from-refer-database/#comments</comments>
		<pubDate>Fri, 28 May 2004 17:15:13 +0000</pubDate>
		<dc:creator>Geof F. Morris</dc:creator>
				<category><![CDATA[Shell Scripts]]></category>

		<guid isPermaLink="false">http://gfmorris.org/archives/2004/05/28/stripping-unwanted-referrers-from-refer-database/</guid>
		<description><![CDATA[If you use Dean Allen&#8216;s wonderful Refer PHP script to track incoming referrers as I do, you may come across some unwanted referrers that cannot be blocked from within refer.php. I was specifically having issues with a cached Google reference to an entry on GFMorris.com that, in a previous life, had a popup photo of [...]]]></description>
			<content:encoded><![CDATA[<p>If you use <a href="http://textism.com/">Dean Allen</a>&#8216;s wonderful <a href="http://textism.com/tools/refer/">Refer</a> <acronym title="PHP: Hypertext Preprocessor">PHP</acronym> script to track incoming referrers as I do, you may come across some unwanted referrers that cannot be blocked from within refer.php.</p>
<p>I was specifically having issues with a cached Google reference to an entry on GFMorris.com that, in a previous life, had a popup photo of my friend Samantha.  Google had <a href="http://ijsm.org/images/referred/samantha.jpg">&#8216;samantha.jpg&#8217;</a> cached, but their incoming references to the photo are, somehow, borked.  Unfortunately, Google still treats this as a valid incoming referral, probably because the photo itself hasn&#8217;t been taken down.</p>
<p>There must be 15 or 20 people a day who hit that image through images.google.com, and well, I was getting annoyed.  So I made myself take the time to learn how to write a shell script to call a .sql script.  What follows is the result of that.</p>
<h4>.sql Script to Strip Unwanted Referrers</h4>
<p>The .sql script is pretty straightforward: connect to the database, run a nice DELETE FROM command, then quit.</p>
<pre style="overflow:scroll">
CONNECT [database];
DELETE FROM refer WHERE page = '[unwanted referrer]';
quit
</pre>
<p><em>Per my convention, items in [brackets] should be replaced by the end-user of the script.</em></p>
<p>If I had multiple pages that I wanted stripped, I&#8217;d just have multiple DELETE FROM commands.</p>
<h4>Shell Script to Run the .sql Script</h4>
<pre style="overflow:scroll;">

#!/bin/csh -f

# Log in to MySQL and run striprefer.sql.

mysql -hlocalhost -u[user] -p[password] &lt; striprefer.sql
</pre>
<p><em>N.B.: This assumes that striprefer.sql and the attendant shell script&#8212;which I&#8217;ve named striprefer&#8212;are in the same directory.  If they are not, you will need to reference that from the user root (e.g., ./sql-scripts/striprefer.sql).</em></p>
<p>You can&#8217;t have the shell script run the SQL commands, unfortunately.  I found that out the hard way.</p>
<h4>How I Use ./striprefer</h4>
<p>I use a cron job to run this every hour.  That&#8217;s probably overkill, but as I said, I&#8217;m using these scripts to stop an annoyance, so I&#8217;ll deal with the attendant overhead.</p>
<img src="http://gfmorris.org/wordpress/?ak_action=api_record_view&id=5&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://gfmorris.org/archives/2004/05/28/stripping-unwanted-referrers-from-refer-database/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>WordPress Backup Shell Script</title>
		<link>http://gfmorris.org/archives/2004/04/29/wordpress-backup-shell-script/</link>
		<comments>http://gfmorris.org/archives/2004/04/29/wordpress-backup-shell-script/#comments</comments>
		<pubDate>Thu, 29 Apr 2004 17:22:54 +0000</pubDate>
		<dc:creator>Geof F. Morris</dc:creator>
				<category><![CDATA[Shell Scripts]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://gfmorris.org/archives/2004/04/29/wordpress-backup-shell-script/</guid>
		<description><![CDATA[For those seeking to backup their WordPress installations on a nightly basis, I have decided to publish the following shell script. Below, any instance of a tilde [~] indicates /home/[username]/. Referencing to user root is key to this. You could change it to /home/[username]/ if you so chose. #!/bin/csh -f # Determine current date setenv [...]]]></description>
			<content:encoded><![CDATA[<p>For those seeking to backup their WordPress installations on a nightly basis, I have decided to publish the following shell script.</p>
<p>Below, any instance of a tilde [~] indicates /home/[username]/. Referencing to user root is key to this. You could change it to /home/[username]/ if you so chose.</p>
<pre style="overflow:scroll;">
#!/bin/csh -f

# Determine current date
setenv CURDATE date +%Y%m%d

# Backup all WP databases to compressed, dated file in home directory
mysqldump -q -e -hlocalhost -u[user] -p[pass] [database] | gzip - &gt; ~/${CURDATE}_db-backup.sql.gz

# Backup WP files to compressed, dated file in home directory
cd ~/path/to/wp-files/
tar cf - . | gzip - &gt; ~/${CURDATE}_files.tar.gz
</pre>
<p>Any data in [brackets] should be filled in, sans brackets.</p>
<p>This should sit in userroot, chmod&#8217;d to 755 to be executable.</p>
<p>You will get errors for all files in wp-uploads on the second TAR run for the backups. If you don&#8217;t want backups of your WP files but are more concerned about the backup of the database, remove everything from the last comment on down.</p>
<p>I personally get an email sent to me to verify that there were no errors in the running of the script.  I also use <a href="http://ftpvoyager.com/">FTP Voyager</a>&#8216;s scheduler to do a Move Down on the backups to a local machine.  When I can get a RAID box running at home, I&#8217;ll be dumping it to that, since I trust RAID more than a single-point-of-failure HD machine.  <img src='http://gfmorris.org/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<img src="http://gfmorris.org/wordpress/?ak_action=api_record_view&id=4&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://gfmorris.org/archives/2004/04/29/wordpress-backup-shell-script/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
	</channel>
</rss>
