<?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>Fernando Ipar &#187; perl</title>
	<atom:link href="http://fernandoipar.com/tag/perl/feed/" rel="self" type="application/rss+xml" />
	<link>http://fernandoipar.com</link>
	<description>I love mankind! Its people I can&#039;t stand!</description>
	<lastBuildDate>Wed, 07 Jul 2010 04:10:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>Generating random salts from bash</title>
		<link>http://fernandoipar.com/2009/02/04/generating-random-salts-from-bash/</link>
		<comments>http://fernandoipar.com/2009/02/04/generating-random-salts-from-bash/#comments</comments>
		<pubDate>Wed, 04 Feb 2009 23:19:57 +0000</pubDate>
		<dc:creator>fernando</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://fernandoipar.com/?p=86</guid>
		<description><![CDATA[From the &#8216;just because it can be done&#8217; column, here comes a handy shell script to generate random salts. So, without further ado,  here it goes: #!/bin/bash [ $# -eq 0 ] &#38;&#38; { echo "usage: salt &#60;length&#62;"&#62;&#38;2 exit } strings &#60;/dev/urandom &#124; while read line; do echo $line &#124; tr '\n\t ' $RANDOM:0:1 &#62;&#62; [...]


Related posts:<ol><li><a href='http://fernandoipar.com/2009/08/14/generating-data-with-dbmonster/' rel='bookmark' title='Permanent Link: Generating data with dbmonster'>Generating data with dbmonster</a> <small> In my last post I included some sample data...</small></li><li><a href='http://fernandoipar.com/2009/01/12/running-commands-from-the-shell-with-a-timeout-pt-2/' rel='bookmark' title='Permanent Link: Running commands from the shell with a timeout (pt 2)'>Running commands from the shell with a timeout (pt 2)</a> <small>Here&#8217;s an improved version of the safecmd script. This one...</small></li><li><a href='http://fernandoipar.com/2009/01/10/running-commands-from-the-shell-with-a-timeout/' rel='bookmark' title='Permanent Link: Running commands from the shell with a timeout'>Running commands from the shell with a timeout</a> <small>Sometimes, in a shell script, you need to run a...</small></li></ol>

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>From the &#8216;just because it can be done&#8217; column, here comes a handy shell script to generate random <a title="Cryptographic Salt (Wikipedia)" href="http://en.wikipedia.org/wiki/Salt_(cryptography)">salts</a>.</p>
<p>So, without further ado,  here it goes:</p>
<pre>#!/bin/bash 

[ $# -eq 0 ] &amp;&amp; {
        echo "usage: salt &lt;length&gt;"&gt;&amp;2
        exit
}
strings &lt;/dev/urandom | while read line; do
        echo $line | tr '\n\t ' $RANDOM:0:1 &gt;&gt; /tmp/.salt.$$
        salt=$(cat /tmp/.salt.$$)
        [ ${#salt} -ge $1 ] &amp;&amp; salt=${salt:0:$1} &amp;&amp; echo $salt &amp;&amp; break
done
rm -f /tmp/.salt.$$</pre>
<p>I had to use $1 and not a var, and echo the salt right from inside the while, because the &#8216;|&#8217; creates another shell, so I can&#8217;t pass variables to or from the while in this case.</p>
<p>If you want to keep things simple, you can go perl and just do</p>
<pre>
#!/usr/bin/perl
use Crypt::Salt;
my $length = shift;
print salt($length);
</pre>
<p>But if you ever find yourself in a server with no cpan, the first option might prove useful <img src='http://fernandoipar.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>


<p>Related posts:<ol><li><a href='http://fernandoipar.com/2009/08/14/generating-data-with-dbmonster/' rel='bookmark' title='Permanent Link: Generating data with dbmonster'>Generating data with dbmonster</a> <small> In my last post I included some sample data...</small></li><li><a href='http://fernandoipar.com/2009/01/12/running-commands-from-the-shell-with-a-timeout-pt-2/' rel='bookmark' title='Permanent Link: Running commands from the shell with a timeout (pt 2)'>Running commands from the shell with a timeout (pt 2)</a> <small>Here&#8217;s an improved version of the safecmd script. This one...</small></li><li><a href='http://fernandoipar.com/2009/01/10/running-commands-from-the-shell-with-a-timeout/' rel='bookmark' title='Permanent Link: Running commands from the shell with a timeout'>Running commands from the shell with a timeout</a> <small>Sometimes, in a shell script, you need to run a...</small></li></ol></p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://fernandoipar.com/2009/02/04/generating-random-salts-from-bash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
