<?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>Open Sourcery &#187; System Administration</title>
	<atom:link href="http://www.opensourcery.co.uk/category/tips-and-tricks/system-administration/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.opensourcery.co.uk</link>
	<description>Open Source Support and Consultancy</description>
	<lastBuildDate>Wed, 27 Aug 2008 12:45:47 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Preserve formatting when pasting in vi/vim</title>
		<link>http://www.opensourcery.co.uk/2008/07/preserve-formatting-when-pasting-in-vivim/</link>
		<comments>http://www.opensourcery.co.uk/2008/07/preserve-formatting-when-pasting-in-vivim/#comments</comments>
		<pubDate>Thu, 10 Jul 2008 16:34:53 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[System Administration]]></category>
		<category><![CDATA[Tips and tricks]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[tip]]></category>
		<category><![CDATA[vi]]></category>

		<guid isPermaLink="false">http://www.opensourcery.co.uk/?p=63</guid>
		<description><![CDATA[When copy and pasting into vi or vim, you can often end up with badly formatted text. This is often referred to as &#8220;the staircase effect&#8221;. It&#8217;s easily prevented by entering :set paste before you paste, when you have finished turn it off again with :set nopaste.
a
<p>a</p>
]]></description>
			<content:encoded><![CDATA[<p>When copy and pasting into vi or vim, you can often end up with badly formatted text. This is often referred to as &#8220;the staircase effect&#8221;. It&#8217;s easily prevented by entering <code>:set paste</code> before you paste, when you have finished turn it off again with <code>:set nopaste</code>.</p>
<p>a</p>
]]></content:encoded>
			<wfw:commentRss>http://www.opensourcery.co.uk/2008/07/preserve-formatting-when-pasting-in-vivim/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Handling temporary files in BASH shell scripts</title>
		<link>http://www.opensourcery.co.uk/2008/06/handling-temporary-files-in-bash-shell-scripts/</link>
		<comments>http://www.opensourcery.co.uk/2008/06/handling-temporary-files-in-bash-shell-scripts/#comments</comments>
		<pubDate>Thu, 05 Jun 2008 13:41:59 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[BASH scripting]]></category>
		<category><![CDATA[System Administration]]></category>
		<category><![CDATA[Tips and tricks]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[ftp]]></category>

		<guid isPermaLink="false">http://www.opensourcery.co.uk/?p=35</guid>
		<description><![CDATA[Temporary files left over from shell scripts clutter up your /tmp directory and may result in information leakage. Below are a pair of functions we use to gracefully handle the creation and removal of temporary files in shell scripts.
The first function is used to create a temporary file:
function os_mktemp {
&#160;[[ ! $1 ]] &#038;&#038; echo [...]<p>a</p>
]]></description>
			<content:encoded><![CDATA[<p>Temporary files left over from shell scripts clutter up your /tmp directory and may result in information leakage. Below are a pair of functions we use to gracefully handle the creation and removal of temporary files in shell scripts.</p>
<p>The first function is used to create a temporary file:</p>
<blockquote><p><code>function os_mktemp {<br />
&nbsp;[[ ! $1 ]] &#038;&#038; echo "os_mktemp: required a handle name" &#038;&#038; exit 99<br />
&nbsp;let OS_TEMPFILEHANDLE++;<br />
&nbsp;OS_TEMPFILE[$OS_TEMPFILEHANDLE]=`mktemp /tmp/ostmp.XXXXXXXX`<br />
&nbsp;eval F_$1=${OS_TEMPFILE[$OS_TEMPFILEHANDLE]}<br />
}<br />
</code></p></blockquote>
<p>It requires a single parameter, which is used to create a variable name containing the path to the temporary file. For example. <code>os_mktemp FTPOUTPUT</code> will return a variable <code>$F_FTPOUTPUT</code>. </p>
<p>The array OS_TEMPFILE is an array holding the names of all the temporary file names, this is used by the cleanup function to remove the temporary files.</p>
<p> <code>os_mktemp OUTPUT</code>; this results in a temporary file with a random name being created and the name being stored in the variable $F_OUTPUT.</p>
<p>The second function is used to remove all temporary files.</p>
<blockquote><p><code><br />
function os_cleanup {<br />
&nbsp;for FILE in ${OS_TEMPFILE[@]}; do<br />
&nbsp;&nbsp;[[ -e "$FILE" ]] &#038;&#038; rm "$FILE" || echo "os_cleanup: couldn't remove temporary file $FILE."<br />
&nbsp;done<br />
}<br />
</code></p></blockquote>
<p>To ensure the os_cleanup code is executed whenever the shell script closes, we use the BASH <em>trap</em> command. </p>
<blockquote><p><code><br />
trap os_cleanup INT TERM EXIT<br />
</code></p></blockquote>
<p>a</p>
]]></content:encoded>
			<wfw:commentRss>http://www.opensourcery.co.uk/2008/06/handling-temporary-files-in-bash-shell-scripts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automatically backing up files before making changes</title>
		<link>http://www.opensourcery.co.uk/2008/06/backing-up-files-before-making-changes/</link>
		<comments>http://www.opensourcery.co.uk/2008/06/backing-up-files-before-making-changes/#comments</comments>
		<pubDate>Sun, 01 Jun 2008 08:40:01 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[BASH scripting]]></category>
		<category><![CDATA[System Administration]]></category>
		<category><![CDATA[Tips and tricks]]></category>
		<category><![CDATA[backups]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[best practice]]></category>
		<category><![CDATA[change control]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://www.opensourcery.co.uk/?p=43</guid>
		<description><![CDATA[It&#8217;s best practice (and common sense) to make a backup of a file before you edit it. Unfortunately it&#8217;s easy to forget to do this. We use this simple script below to make a time/date stamped copy of a file before launching the editor (in this case vim). We create it as /usr/local/bin/bvi.

#!/bin/bash
[[ -r $1 [...]<p>a</p>
]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s best practice (and common sense) to make a backup of a file before you edit it. Unfortunately it&#8217;s easy to forget to do this. We use this simple script below to make a time/date stamped copy of a file before launching the editor (in this case <a href="http://www.vim.org/" target="_blank">vim</a>). We create it as <em>/usr/local/bin/bvi</em>.</p>
<blockquote><p><code><br />
#!/bin/bash<br />
[[ -r $1 ]] &#038;&#038; cp $1{,.`date +%Y%m%d-%H%M`} ||  echo "$1 is a new file"</code><br />
vim $1
</p></blockquote>
<p>We then add the following two aliases to our ~/.bashrc file to make sure it&#8217;s run automatically when we call vim.</p>
<blockquote><p><code>alias vi=/usr/local/bin/bvi<br />
alias vim=/usr/local/bin/bvi<br />
</code></p></blockquote>
<p>This isn&#8217;t a replacement for good version control of important files, but it&#8217;s a good safety net. It&#8217;s also worth noting that this can leave a lot of old copies of files laying about, so it&#8217;s work cleaning out old copies every now and again.</p>
<p>a</p>
]]></content:encoded>
			<wfw:commentRss>http://www.opensourcery.co.uk/2008/06/backing-up-files-before-making-changes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Check, repair and optimize all MySQL databases</title>
		<link>http://www.opensourcery.co.uk/2008/05/check-repair-and-optimize-all-mysql-databases/</link>
		<comments>http://www.opensourcery.co.uk/2008/05/check-repair-and-optimize-all-mysql-databases/#comments</comments>
		<pubDate>Wed, 21 May 2008 19:49:14 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[System Administration]]></category>
		<category><![CDATA[Tips and tricks]]></category>
		<category><![CDATA[backups]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.opensourcery.co.uk/?p=60</guid>
		<description><![CDATA[The following command will check, repair and optimize all databases on your MySQL server.
mysqlcheck -u root -p --auto-repair --check --optimize --all-databases
It is the equivalent of calling CHECK TABLE, REPAIR TABLE, ANALYZE TABLE and OPTIMZE TABLE for each table in each database on your server.
We tend to run this command directly after our scheduled backups.
a
<p>a</p>
]]></description>
			<content:encoded><![CDATA[<p>The following command will check, repair and optimize all databases on your MySQL server.</p>
<blockquote><p><code>mysqlcheck -u root -p --auto-repair --check --optimize --all-databases</code></p></blockquote>
<p>It is the equivalent of calling CHECK TABLE, REPAIR TABLE, ANALYZE TABLE and OPTIMZE TABLE for each table in each database on your server.</p>
<p>We tend to run this command directly <em>after</em> our scheduled backups.</p>
<p>a</p>
]]></content:encoded>
			<wfw:commentRss>http://www.opensourcery.co.uk/2008/05/check-repair-and-optimize-all-mysql-databases/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>BASH quick tip: Change to last directory</title>
		<link>http://www.opensourcery.co.uk/2008/05/bash-change-to-last-director/</link>
		<comments>http://www.opensourcery.co.uk/2008/05/bash-change-to-last-director/#comments</comments>
		<pubDate>Fri, 16 May 2008 19:55:21 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[System Administration]]></category>
		<category><![CDATA[Tips and tricks]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[tip]]></category>

		<guid isPermaLink="false">http://www.opensourcery.co.uk/?p=50</guid>
		<description><![CDATA[You can change to the previous working directory in BASH by using the command:
cd - 
a
<p>a</p>
]]></description>
			<content:encoded><![CDATA[<p>You can change to the previous working directory in BASH by using the command:</p>
<blockquote><p><code>cd - </code></p></blockquote>
<p>a</p>
]]></content:encoded>
			<wfw:commentRss>http://www.opensourcery.co.uk/2008/05/bash-change-to-last-director/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
