<?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>Ivan Villareal</title>
	<atom:link href="http://blog.ivanvillareal.info/tag/linux/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.ivanvillareal.info</link>
	<description>IT stuff and more...</description>
	<lastBuildDate>Fri, 13 Aug 2010 23:05:31 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Compressing/Decompressing mysql dumps on the fly</title>
		<link>http://blog.ivanvillareal.info/linux/compressingdecompressing-mysql-dumps-on-the-fly/</link>
		<comments>http://blog.ivanvillareal.info/linux/compressingdecompressing-mysql-dumps-on-the-fly/#comments</comments>
		<pubDate>Wed, 17 Feb 2010 20:17:06 +0000</pubDate>
		<dc:creator>Ivan Villareal</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[pipes]]></category>
		<category><![CDATA[restore]]></category>

		<guid isPermaLink="false">http://blog.ivanvillareal.info/?p=197</guid>
		<description><![CDATA[One line commands I use to compress or decompress mysql dumps.]]></description>
			<content:encoded><![CDATA[<p>Using pipes and redirection in the shell we can do backups or restore them, performing compression or decompression on the fly, this are the commands I frequently use:</p>
<p>Create a backup <dbname>with mysqldump and compress the stream with bzip2<br />
<!--DEVFMTCODE--><pre class="devcodeblock" title="Bash"><div class="devcodeoverflow">ivan<span style="color: #000000; font-weight: bold;">@</span>mini:~$ mysqldump –h dbHost –u dbUser –pdbPass –add-drop-database –databases <span style="color: #000000; font-weight: bold;">&lt;</span>dbname<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">bzip2</span> <span style="color: #000000; font-weight: bold;">&gt;</span> dbName-02-<span style="color: #000000;">17</span>-2010.sql.bz2<span style="color: #000000; font-weight: bold;">&lt;/</span>dbname<span style="color: #000000; font-weight: bold;">&gt;</span></div></pre><!--END_DEVFMTCODE--></dbname></p>
<p>If I want to restore the backup I use:</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="Bash"><div class="devcodeoverflow">ivan<span style="color: #000000; font-weight: bold;">@</span>mini:~$ <span style="color: #c20cb9; font-weight: bold;">bunzip2</span> <span style="color: #000000; font-weight: bold;">&lt;</span> dbName-02-17-2010.sql.bz2 <span style="color: #000000; font-weight: bold;">|</span> mysql –h dbHost –u dbUser –pdbPass</div></pre><!--END_DEVFMTCODE--></p>
<p>I can switch bzip2 compression by changing only the program name for example gzip/gunzip lzma/unlzma</code></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ivanvillareal.info/linux/compressingdecompressing-mysql-dumps-on-the-fly/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting up a new centos VPS server from console</title>
		<link>http://blog.ivanvillareal.info/linux/setting-up-a-new-centos-vps-server-from-console/</link>
		<comments>http://blog.ivanvillareal.info/linux/setting-up-a-new-centos-vps-server-from-console/#comments</comments>
		<pubDate>Tue, 16 Feb 2010 00:36:30 +0000</pubDate>
		<dc:creator>Ivan Villareal</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[configuration]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[vps]]></category>

		<guid isPermaLink="false">http://blog.ivanvillareal.info/?p=185</guid>
		<description><![CDATA[How I did an initial configuration of a Centos 5.4 VPS server to have it working with virtual hosts.]]></description>
			<content:encoded><![CDATA[<p>I just got a couple of vps servers, that I have to configure to run some apps, this are the tasks I did to have them ready for production use:</p>
<p>&nbsp;</p>
<p>This servers didn’t came with a control panel (better for me), so the first thing I did was to login:</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="Bash"><div class="devcodeoverflow">ivan<span style="color: #000000; font-weight: bold;">@</span>mini:~$ <span style="color: #c20cb9; font-weight: bold;">ssh</span> root<span style="color: #000000; font-weight: bold;">@</span>23.45.12.56</div></pre><!--END_DEVFMTCODE--></p>
<p>After this I checked the OS, version and architecture</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="Bash"><div class="devcodeoverflow"><span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>V100205C4HB9V-<span style="color: #000000;">1</span> ~<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># cat /etc/*release*</span>
CentOS release <span style="color: #000000;">5.4</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>Final<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>V100205C4HB9V-<span style="color: #000000;">1</span> ~<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># uname -a</span>
Linux V100205C4HB9V-<span style="color: #000000;">1</span> 2.6.18-028stab064.7 <span style="color: #666666; font-style: italic;">#1 SMP Wed Aug 26 13:11:07 MSD 2009 x86_64 x86_64 x86_64 GNU/Linux</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>V100205C4HB9V-<span style="color: #000000;">1</span> ~<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;">#</div></pre><!--END_DEVFMTCODE--></p>
<p>Ok, now that I know the OS I create a normal user to avoid using the root account.</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="Bash"><div class="devcodeoverflow"><span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>V100205C4HB9V-<span style="color: #000000;">1</span> ~<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># useradd –Gwheel ivan</div></pre><!--END_DEVFMTCODE--></p>
<p>Then I change the server name to mygdon</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="Bash"><div class="devcodeoverflow"><span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>V100205C4HB9V-<span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># sed -i 's/V100205C4HB9V-1/mygdon/g' /etc/sysconfig/network</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>V100205C4HB9V-<span style="color: #000000;">1</span> ~<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># sed -i 's/V100205C4HB9V-1/mygdon/g' /etc/hosts</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>V100205C4HB9V-<span style="color: #000000;">1</span> ~<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># echo HOST.DOMAIN.com &gt; /etc/hostname</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>V100205C4HB9V-<span style="color: #000000;">1</span> ~<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># hostname -F /etc/hostname</div></pre><!--END_DEVFMTCODE--></p>
<p>Unfortunately I was unable to persist the new hostname, because it is a VPS server, there are ways around this, but didn’t have the time to make the changes so I just moved on, and leave this for later</p>
<p>The next thing I did was update the OS, and add the rpmforge repo because I will need some apps from there</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="Bash"><div class="devcodeoverflow"><span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>V100205C4HB9V-<span style="color: #000000;">1</span> ~<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># yum update</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>V100205C4HB9V-<span style="color: #000000;">1</span> ~<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># yum upgrade</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>V100205C4HB9V-<span style="color: #000000;">1</span> ~<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.1-1.el5.rf.x86_64.rpm</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>V100205C4HB9V-<span style="color: #000000;">1</span> ~<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># rpm -Uhv rpmforge-release-0.5.1-1.$dist.rf.$arch.rpm</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>V100205C4HB9V-<span style="color: #000000;">1</span> ~<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># yum update</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>V100205C4HB9V-<span style="color: #000000;">1</span> ~<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># yum upgrade</div></pre><!--END_DEVFMTCODE--></p>
<p>Then I installed some packages I often use:</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="Bash"><div class="devcodeoverflow"><span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>V100205C4HB9V-<span style="color: #000000;">1</span> ~<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># yum install htop screen vim-enhanced</div></pre><!--END_DEVFMTCODE--></p>
<p>The VPS already had a web stack installed I just did some configuration:</p>
<h2>Configuring Apache Virtual Hosts</h2>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="Bash"><div class="devcodeoverflow"><span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>V100205C4HB9V-<span style="color: #000000;">1</span> ~<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># mkdir /var/www/vhosts/{site1, site2} –p</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>V100205C4HB9V-<span style="color: #000000;">1</span> ~<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># vi /etc/httpd/conf/httpd.conf</div></pre><!--END_DEVFMTCODE--></p>
<p>Here I Uncommented the following directive</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="Apache configuration"><div class="devcodeoverflow"><span style="color: #00007f;">NameVirtualHost</span> *:<span style="color: #ff0000;">80</span></div></pre><!--END_DEVFMTCODE--></p>
<p>and Added a default vhost a new vhost</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="Apache configuration"><div class="devcodeoverflow">&lt;<span style="color: #000000; font-weight:bold;">virtualhost</span> *:80&gt;
    <span style="color: #00007f;">DocumentRoot</span> /var/www/vhosts/default
    <span style="color: #00007f;">ServerName</span> mygdon.site1.net
    &lt;<span style="color: #000000; font-weight:bold;">directory</span> /var/www/vhosts/default&gt;
        <span style="color: #00007f;">Options</span> <span style="color: #0000ff;">Indexes</span> <span style="color: #0000ff;">FollowSymLinks</span>
        <span style="color: #00007f;">AllowOverride</span> <span style="color: #0000ff;">All</span>
        <span style="color: #00007f;">Order</span> <span style="color: #00007f;">allow</span>,<span style="color: #00007f;">deny</span>
        <span style="color: #00007f;">Allow</span> from <span style="color: #0000ff;">all</span>
    &lt;/<span style="color: #000000; font-weight:bold;">directory</span>&gt;
    <span style="color: #00007f;">ErrorLog</span> logs/mygdon.site1.net-error_log
    <span style="color: #00007f;">CustomLog</span> logs/mygdon.site1.net-access_log common
&lt;/<span style="color: #000000; font-weight:bold;">virtualhost</span>&gt;
&nbsp;
&lt;<span style="color: #000000; font-weight:bold;">virtualhost</span> *:80&gt;
    <span style="color: #00007f;">DocumentRoot</span> /var/www/vhosts/site2
    <span style="color: #00007f;">ServerName</span> appname.site2.net
    &lt;<span style="color: #000000; font-weight:bold;">directory</span> /var/www/vhosts/site2&gt;
        <span style="color: #00007f;">Options</span> <span style="color: #0000ff;">Indexes</span> <span style="color: #0000ff;">FollowSymLinks</span>
        <span style="color: #00007f;">AllowOverride</span> <span style="color: #0000ff;">All</span>
        <span style="color: #00007f;">Order</span> <span style="color: #00007f;">allow</span>,<span style="color: #00007f;">deny</span>
        <span style="color: #00007f;">Allow</span> from <span style="color: #0000ff;">all</span>
    &lt;/<span style="color: #000000; font-weight:bold;">directory</span>&gt;
    <span style="color: #00007f;">ErrorLog</span> logs/appname.site2.net-error_log
    <span style="color: #00007f;">CustomLog</span> logs/appname.site2.net-access_log common
&lt;/<span style="color: #000000; font-weight:bold;">virtualhost</span>&gt;</div></pre><!--END_DEVFMTCODE--></p>
<p>then restarted the apache server:</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="Bash"><div class="devcodeoverflow"><span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>V100205C4HB9V-<span style="color: #000000;">1</span> ~<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># service httpd restart</span>
Stopping httpd:                                            <span style="color: #7a0874; font-weight: bold;">&#91;</span>  OK  <span style="color: #7a0874; font-weight: bold;">&#93;</span>
Starting  httpd:                                            <span style="color: #7a0874; font-weight: bold;">&#91;</span>  OK  <span style="color: #7a0874; font-weight: bold;">&#93;</span></div></pre><!--END_DEVFMTCODE--></p>
<p>and&nbsp; I wrote a simple php file to test this out:</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="Bash"><div class="devcodeoverflow"><span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>V100205C4HB9V-<span style="color: #000000;">1</span> ~<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># echo '&amp;lt;? phpinfo(); ?&amp;gt;' &gt; /var/www/vhosts/site1/index.php</div></pre><!--END_DEVFMTCODE--></p>
<p>And because I haven’t configured a DNS server I just temporarily added the server to my hosts file (On my local machine):</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="PHP"><div class="devcodeoverflow">root<span style="color: #339933;">@</span>mini<span style="color: #339933;">:/</span>etc<span style="color: #666666; font-style: italic;"># echo 'subdomain.site1.net 54.65.74.23' &gt; /etc/hosts</div></pre><!--END_DEVFMTCODE--></p>
<p>and here is the result:</p>
<p><a href="http://blog.ivanvillareal.info/wp-content/uploads/2010/02/testingvhost.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="testing-vhost" src="http://blog.ivanvillareal.info/wp-content/uploads/2010/02/testingvhost_thumb.png" border="0" alt="testing-vhost" width="644" height="379" /></a>&nbsp;</p>
<h2>Configuring Mysql</h2>
<p>Once I had the virtual hosts configuration in place I added a mysql user and changed the default root password:</p>
<p>&nbsp;</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="MySQL"><div class="devcodeoverflow"><span style="color: #FF00FF;">&#91;</span>root@V100205C4HB9V<span style="color: #CC0099;">-</span><span style="color: #008080;">1</span> vhosts<span style="color: #FF00FF;">&#93;</span><span style="color: #808080; font-style: italic;"># mysql</span>
Welcome <span style="color: #990099; font-weight: bold;">to</span> the MySQL monitor.  Commands <span style="color: #009900;">end</span> <span style="color: #990099; font-weight: bold;">with</span> <span style="color: #000033;">;</span> <span style="color: #CC0099; font-weight: bold;">or</span> \g.
Your MySQL <span style="color: #FF9900; font-weight: bold;">connection</span> id <span style="color: #CC0099; font-weight: bold;">is</span> 5
Server <span style="color: #000099;">version</span>: 5.0.77 Source distribution
&nbsp;
<span style="color: #990099; font-weight: bold;">Type</span> <span style="color: #008000;">'help;'</span> <span style="color: #CC0099; font-weight: bold;">or</span> <span style="color: #008000;">'<span style="color: #004000; font-weight: bold;">\h</span>'</span> for <span style="color: #990099; font-weight: bold;">help</span>. <span style="color: #990099; font-weight: bold;">Type</span> <span style="color: #008000;">'<span style="color: #004000; font-weight: bold;">\c</span>'</span> <span style="color: #990099; font-weight: bold;">to</span> clear the <span style="color: #00CC00;">buffer</span>.
&nbsp;
mysql<span style="color: #CC0099;">&gt;</span> <span style="color: #990099; font-weight: bold;">show</span> <span style="color: #990099; font-weight: bold;">databases</span><span style="color: #000033;">;</span>
<span style="color: #CC0099;">+--------------------+</span>
<span style="color: #CC0099;">|</span> <span style="color: #990099; font-weight: bold;">Database</span>           <span style="color: #CC0099;">|</span>
<span style="color: #CC0099;">+--------------------+</span>
<span style="color: #CC0099;">|</span> information_schema <span style="color: #CC0099;">|</span>
<span style="color: #CC0099;">|</span> mysql              <span style="color: #CC0099;">|</span>
<span style="color: #CC0099;">|</span> test               <span style="color: #CC0099;">|</span>
<span style="color: #CC0099;">+--------------------+</span>
3 rows <span style="color: #990099; font-weight: bold;">in</span> <span style="color: #990099; font-weight: bold;">set</span> <span style="color: #FF00FF;">&#40;</span>0.00 sec<span style="color: #FF00FF;">&#41;</span>
&nbsp;
mysql<span style="color: #CC0099;">&gt;</span> <span style="color: #990099; font-weight: bold;">UPDATE</span> mysql.<span style="color: #000099;">user</span> <span style="color: #990099; font-weight: bold;">SET</span> <span style="color: #000099;">Password</span><span style="color: #CC0099;">=</span><span style="color: #000099;">PASSWORD</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">'pass-here'</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">WHERE</span> <span style="color: #000099;">user</span><span style="color: #CC0099;">=</span><span style="color: #008000;">'root'</span><span style="color: #000033;">;</span>
Query OK<span style="color: #000033;">,</span> 3 rows affected <span style="color: #FF00FF;">&#40;</span>0.02 sec<span style="color: #FF00FF;">&#41;</span>
Rows matched: 3  Changed: 3  <span style="color: #990099; font-weight: bold;">Warnings</span>: 0
&nbsp;
mysql<span style="color: #CC0099;">&gt;</span> FLUSH <span style="color: #990099; font-weight: bold;">PRIVILEGES</span><span style="color: #000033;">;</span>
Query OK<span style="color: #000033;">,</span> 0 rows affected <span style="color: #FF00FF;">&#40;</span>0.01 sec<span style="color: #FF00FF;">&#41;</span>
&nbsp;
mysql<span style="color: #CC0099;">&gt;</span> <span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #000099;">USER</span> <span style="color: #008000;">'ivan'</span>@<span style="color: #008000;">'localhost'</span> IDENTIFIED BY <span style="color: #008000;">'pass-here'</span><span style="color: #000033;">;</span>
Query OK<span style="color: #000033;">,</span> 0 rows affected <span style="color: #FF00FF;">&#40;</span>0.01 sec<span style="color: #FF00FF;">&#41;</span>
&nbsp;
mysql<span style="color: #CC0099;">&gt;</span> <span style="color: #990099; font-weight: bold;">GRANT</span> <span style="color: #990099; font-weight: bold;">ALL</span> <span style="color: #990099; font-weight: bold;">PRIVILEGES</span> <span style="color: #990099; font-weight: bold;">ON</span> <span style="color: #CC0099;">*</span>.<span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">TO</span> <span style="color: #008000;">'ivan'</span>@<span style="color: #008000;">'localhost'</span> <span style="color: #990099; font-weight: bold;">WITH</span> <span style="color: #990099; font-weight: bold;">GRANT</span> <span style="color: #990099; font-weight: bold;">OPTION</span><span style="color: #000033;">;</span>
Query OK<span style="color: #000033;">,</span> 0 rows affected <span style="color: #FF00FF;">&#40;</span>0.00 sec<span style="color: #FF00FF;">&#41;</span>
&nbsp;
mysql<span style="color: #CC0099;">&gt;</span> <span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #000099;">USER</span> <span style="color: #008000;">'ivan'</span>@<span style="color: #008000;">'<span style="color: #008080; font-weight: bold;">%</span>'</span> IDENTIFIED BY <span style="color: #008000;">'pass-here'</span><span style="color: #000033;">;</span>
Query OK<span style="color: #000033;">,</span> 0 rows affected <span style="color: #FF00FF;">&#40;</span>0.00 sec<span style="color: #FF00FF;">&#41;</span>
&nbsp;
mysql<span style="color: #CC0099;">&gt;</span> <span style="color: #990099; font-weight: bold;">GRANT</span> <span style="color: #990099; font-weight: bold;">ALL</span> <span style="color: #990099; font-weight: bold;">PRIVILEGES</span> <span style="color: #990099; font-weight: bold;">ON</span> <span style="color: #CC0099;">*</span>.<span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">TO</span> <span style="color: #008000;">'ivan'</span>@<span style="color: #008000;">'<span style="color: #008080; font-weight: bold;">%</span>'</span> <span style="color: #990099; font-weight: bold;">WITH</span> <span style="color: #990099; font-weight: bold;">GRANT</span> <span style="color: #990099; font-weight: bold;">OPTION</span><span style="color: #000033;">;</span>
Query OK<span style="color: #000033;">,</span> 0 rows affected <span style="color: #FF00FF;">&#40;</span>0.00 sec<span style="color: #FF00FF;">&#41;</span>
&nbsp;
mysql<span style="color: #CC0099;">&gt;</span> FLUSH <span style="color: #990099; font-weight: bold;">PRIVILEGES</span><span style="color: #000033;">;</span>
Query OK<span style="color: #000033;">,</span> <span style="color: #008080;">0</span> rows affected <span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">0.00</span> sec<span style="color: #FF00FF;">&#41;</span>
&nbsp;
mysql<span style="color: #CC0099;">&gt;</span></div></pre><!--END_DEVFMTCODE--></p>
<p>&nbsp;</p>
<p>Now the server is&nbsp; ready for adding some virtual hosts, I just need to configure a DNS server and the mail server, but because the DNS is on another server and already working I just have to add a new zone, as for mail server, this server will be only used to send emails so I don’t need to dig in postfix configuration files for now.</p>
<p>I&#8217;ll write another post regarding the security, but for now this will work.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ivanvillareal.info/linux/setting-up-a-new-centos-vps-server-from-console/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Ubuntu 9.10 on an hp mini 110-1125nr</title>
		<link>http://blog.ivanvillareal.info/linux/ubuntu-9-10-on-an-hp-mini-110-1125nr/</link>
		<comments>http://blog.ivanvillareal.info/linux/ubuntu-9-10-on-an-hp-mini-110-1125nr/#comments</comments>
		<pubDate>Wed, 27 Jan 2010 00:56:14 +0000</pubDate>
		<dc:creator>Ivan Villareal</dc:creator>
				<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[netbook]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://blog.ivanvillareal.info/?p=148</guid>
		<description><![CDATA[I got this new mini 110, it came with Windows 7 Starter, and after a day of using it I was very frustrated because it was very limiting, for example, I was unable to change my Desktop background, the network management is confusing and frustrating, and it had a lot of crapware, except for the [...]]]></description>
			<content:encoded><![CDATA[<p>I got this new mini 110, it came with Windows 7 Starter, and after a day of using it I was very frustrated because it was very limiting, for example, I was unable to change my Desktop background, the network management is confusing and frustrating, and it had a lot of crapware, except for the hp games, that some of them are fun.</p>
<p>Anyway, right now I don&#8217;t have time to spend getting a new OS on this machine, I just want something that works, I don&#8217;t plan using this to work, but I would like to have some of the tools I use into this.</p>
<p>So my options were, trying Ubuntu remix or Windows Xp, after checking that hp had the drivers for XP, I was going to change Windows 7 to Xp, but I was reading how to create a USB boot drive, and it was too much hassle for me. (I&#8217;m very lazy for any Microsoft stuff).</p>
<p>My next option was Ubuntu remix, I&#8217;m not a big fan of Ubuntu, but I wanted something to just worked out of the box, also this little netbook comes with splashtop, a really nice feature for checking stuff online fast, and I didn&#8217;t want to loose this so I really didn&#8217;t knew how well this was going to work.</p>
<p>I started downloading Ubuntu 9.10 Karmic yesterday night, just in case, Today after more frustrating things, I decided to give Karmic a try.</p>
<p>I grabbed my usb pendrive, a 1gb &nbsp;kingston traveler, mounted the iso and ran usbinst.exe, it was pretty straightforward, my only advice to you would be to avoid saving space for your documents in the usb, my first try I set this to 30Mb and the boot failed, so I set the do not save feature.</p>
<p>It took about 40 minutes to finish copying the files, after it was done, I restarted the netbook with the pendrive connected, and at the first boot screen I pressed F9 key for booting options, selected the pendrive and that was it.</p>
<p>After testing ubuntu from the pendrive, it ran pretty well and everything but the wifi worked, I did an installation, keeping the windows partition and the hp restore partition, just in case.</p>
<p>The installation was pretty smooth, no issues at all, after the first boot I just installed the broadcom drivers, it was pretty easy with the driver manager in ubuntu, and the wifi was working</p>
<p>Update: My hp mini was stolen by a couple of elderly people, I saw the video <img src='http://blog.ivanvillareal.info/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> , so I&#8217;m unable to play more with this, but the time I had this I was very happy with it, it performed well.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ivanvillareal.info/linux/ubuntu-9-10-on-an-hp-mini-110-1125nr/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mount a remote filesystem using sshfs</title>
		<link>http://blog.ivanvillareal.info/linux/mount-a-remote-filesystem-using-sshfs/</link>
		<comments>http://blog.ivanvillareal.info/linux/mount-a-remote-filesystem-using-sshfs/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 19:25:39 +0000</pubDate>
		<dc:creator>Ivan Villareal</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[fuse]]></category>
		<category><![CDATA[mount]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[sshfs]]></category>

		<guid isPermaLink="false">http://blog.ivanvillareal.info/?p=82</guid>
		<description><![CDATA[I often have to upload files to several servers, and some of them doesn&#8217;t have an rsync or ftp server, so if I&#8217;m going to make a deployment, I have to use scp, or sftp to upload the files.
This works well when I need to make a quick change or test 1 file, but If [...]]]></description>
			<content:encoded><![CDATA[<p>I often have to upload files to several servers, and some of them doesn&#8217;t have an rsync or ftp server, so if I&#8217;m going to make a deployment, I have to use scp, or sftp to upload the files.</p>
<p>This works well when I need to make a quick change or test 1 file, but If I have to synchronize several files it is a very time consuming task.</p>
<p>So what I use in this cases is <a title="This is a filesystem client based on the SSH File Transfer Protocol." href="http://fuse.sourceforge.net/sshfs.html" target="_blank">sshfs</a>&nbsp;it is a pretty cool tool, to allow me to mount any filesystem so I can use any rsync on a remote server&nbsp;without&nbsp;dealing with opening ports configure, the server or do other stuff,</p>
<p>Gentoo is my main OS, so it was really easy to have this working, I had to reconfigure the kernel to support fuse</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="Text"><div class="devcodeoverflow">Symbol: FUSE_FS [=m]
Location:
  -&gt; File systems
      -&gt; Filesystem in Userspace support</div></pre><!--END_DEVFMTCODE--></p>
<p>and after this was ready I only installed sys-fs/sshfs-fuse</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="Bash"><div class="devcodeoverflow"><span style="color: #7a0874; font-weight: bold;">&#91;</span>I<span style="color: #7a0874; font-weight: bold;">&#93;</span> sys-fs<span style="color: #000000; font-weight: bold;">/</span>sshfs-fuse
     Available versions:  <span style="color: #000000;">1.9</span> ~<span style="color: #000000;">2.1</span> <span style="color: #000000;">2.2</span>
     Installed versions:  <span style="color: #000000;">2.2</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">12</span>:<span style="color: #000000;">33</span>:09 PM 09<span style="color: #000000; font-weight: bold;">/</span>08<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">2009</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
     Homepage:            http:<span style="color: #000000; font-weight: bold;">//</span>fuse.sourceforge.net<span style="color: #000000; font-weight: bold;">/</span>sshfs.html
     Description:         Fuse-filesystem utilizing the sftp service.
</div></pre><!--END_DEVFMTCODE--></p>
<p>when it was ready I did the following to mount the remote filesystem:</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="Bash"><div class="devcodeoverflow">ivan<span style="color: #000000; font-weight: bold;">@</span>gondor ~ $ sshfs phpfix<span style="color: #000000; font-weight: bold;">@</span>prestant.citizenhawk.net: preasent<span style="color: #000000; font-weight: bold;">/</span></div></pre><!--END_DEVFMTCODE--></p>
<p>After this I&#8217;m able to use the remote file system as usual.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ivanvillareal.info/linux/mount-a-remote-filesystem-using-sshfs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mysql5 and PHP5 on centos4</title>
		<link>http://blog.ivanvillareal.info/linux/mysql5-and-php5-on-centos4/</link>
		<comments>http://blog.ivanvillareal.info/linux/mysql5-and-php5-on-centos4/#comments</comments>
		<pubDate>Mon, 12 Oct 2009 19:00:06 +0000</pubDate>
		<dc:creator>Ivan Villareal</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[configuration]]></category>
		<category><![CDATA[installation]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.ivanvillareal.info/?p=76</guid>
		<description><![CDATA[I have the need to install php5 and mysql 5 on a centos 4 server, so I found that the Centos Plus repository had this, and this is what I did to get these two working.
First check what is the version of the distro:
cat /etc/*release*
Then make an update:
yum update
After 496 package updates I&#8217;ve installed php5
yum [...]]]></description>
			<content:encoded><![CDATA[<p>I have the need to install php5 and mysql 5 on a centos 4 server, so I found that the Centos Plus repository had this, and this is what I did to get these two working.</p>
<p>First check what is the version of the distro:<br />
<!--DEVFMTCODE--><pre class="devcodeblock" title="Bash"><div class="devcodeoverflow"><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/*</span>release<span style="color: #000000; font-weight: bold;">*</span></div></pre><!--END_DEVFMTCODE--></p>
<p>Then make an update:<br />
<!--DEVFMTCODE--><pre class="devcodeblock" title="Bash"><div class="devcodeoverflow">yum update</div></pre><!--END_DEVFMTCODE--></p>
<p>After 496 package updates I&#8217;ve installed php5<br />
<!--DEVFMTCODE--><pre class="devcodeblock" title="Bash"><div class="devcodeoverflow">yum <span style="color: #660033;">--enablerepo</span>=centosplus <span style="color: #c20cb9; font-weight: bold;">install</span> php</div></pre><!--END_DEVFMTCODE--></p>
<p>This were the installed packages:<br />
<!--DEVFMTCODE--><pre class="devcodeblock" title="Bash"><div class="devcodeoverflow">php-5.1.6-3.el4s1.10
php-cli-5.1.6-3.el4s1.10
php-common-5.1.6-3.el4s1.10
</div></pre><!--END_DEVFMTCODE--></p>
<p>So I&#8217;ve created a info.php file, and restarted the apache server:<br />
<!--DEVFMTCODE--><pre class="devcodeblock" title="Bash"><div class="devcodeoverflow"><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&lt;?php phpinfo(); ?&gt;&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>html<span style="color: #000000; font-weight: bold;">/</span>info.php <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> service httpd restart</div></pre><!--END_DEVFMTCODE--></p>
<p>It was working correctly, so the next thing was to have mysql 5 in it, so I did:<br />
<!--DEVFMTCODE--><pre class="devcodeblock" title="Bash"><div class="devcodeoverflow">yum <span style="color: #660033;">--enablerepo</span>=centosplus <span style="color: #c20cb9; font-weight: bold;">install</span> mysql-server</div></pre><!--END_DEVFMTCODE--></p>
<p>I got some problems here, first I got this:<br />
<!--DEVFMTCODE--><pre class="devcodeblock" title="Bash"><div class="devcodeoverflow">Transaction Check Error: <span style="color: #c20cb9; font-weight: bold;">file</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>my.cnf from <span style="color: #c20cb9; font-weight: bold;">install</span> of mysql-libs-5.0.68-1.el4_6 conflicts with <span style="color: #c20cb9; font-weight: bold;">file</span> from package mysql-4.1.22-2.el4
<span style="color: #c20cb9; font-weight: bold;">file</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>mysql<span style="color: #000000; font-weight: bold;">/</span>charsets<span style="color: #000000; font-weight: bold;">/</span>Index.xml from <span style="color: #c20cb9; font-weight: bold;">install</span> of mysql-libs-5.0.68-1.el4_6 conflicts with <span style="color: #c20cb9; font-weight: bold;">file</span> from package mysql-4.1.22-2.el4
<span style="color: #c20cb9; font-weight: bold;">file</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>mysql<span style="color: #000000; font-weight: bold;">/</span>charsets<span style="color: #000000; font-weight: bold;">/</span>README from <span style="color: #c20cb9; font-weight: bold;">install</span> of mysql-libs-5.0.68-1.el4_6 conflicts with <span style="color: #c20cb9; font-weight: bold;">file</span> from package mysql-4.1.22-2.el4
<span style="color: #c20cb9; font-weight: bold;">file</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>mysql<span style="color: #000000; font-weight: bold;">/</span>charsets<span style="color: #000000; font-weight: bold;">/</span>armscii8.xml from <span style="color: #c20cb9; font-weight: bold;">install</span> of mysql-libs-5.0.68-1.el4_6 conflicts with <span style="color: #c20cb9; font-weight: bold;">file</span> from package mysql-4.1.22-2.el4
<span style="color: #c20cb9; font-weight: bold;">file</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>mysql<span style="color: #000000; font-weight: bold;">/</span>charsets<span style="color: #000000; font-weight: bold;">/</span>ascii.xml from <span style="color: #c20cb9; font-weight: bold;">install</span> of mysql-libs-5.0.68-1.el4_6 conflicts with <span style="color: #c20cb9; font-weight: bold;">file</span> from package mysql-4.1.22-2.el4</div></pre><!--END_DEVFMTCODE--></p>
<p>So what I found was that yum was trying to install mysql.i386 but the architechture is x86_64, to fix this I had to specify the arch<br />
<!--DEVFMTCODE--><pre class="devcodeblock" title="Bash"><div class="devcodeoverflow">yum <span style="color: #660033;">--enablerepo</span>=centosplus <span style="color: #c20cb9; font-weight: bold;">install</span> mysql.x86_64 mysql-server</div></pre><!--END_DEVFMTCODE--></p>
<p>After this I was able to install it, but when I tried to start the server I received some errors about error messages not right, I&#8217;ve checked the installed packages and it was installed mysqlclient10, so I removed the error messages problem disappeared, however I still couldn&#8217;t startup the server, checking at the logs I found this:<br />
<!--DEVFMTCODE--><pre class="devcodeblock" title="Bash"><div class="devcodeoverflow">InnoDB: Creating foreign key constraint system tables
InnoDB: Foreign key constraint system tables created
091012 11:01:18  InnoDB: Started; log sequence number <span style="color: #000000;">0</span> <span style="color: #000000;">0</span>                       091012 <span style="color: #000000;">11</span>:01:<span style="color: #000000;">18</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>ERROR<span style="color: #7a0874; font-weight: bold;">&#93;</span> Fatal error: Can<span style="color: #ff0000;">'t open and lock privilege tables: Table '</span>mysql.host<span style="color: #ff0000;">' doesn'</span>t exist                                                     091012 <span style="color: #000000;">11</span>:01:<span style="color: #000000;">18</span>  mysqld ended                                               </div></pre><!--END_DEVFMTCODE-->\</p>
<p>To fix this I cleared the data dir, that had som files, this was in &#8216;/var/lib/mysql&#8217; and after that I ran mysql_install_db:<br />
<!--DEVFMTCODE--><pre class="devcodeblock" title="Bash"><div class="devcodeoverflow"><span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>prestant <span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># cd /var/lib/mysql </span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>prestant mysql<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># rm -rf *</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>prestant mysql<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># mysql_install_db --user=mysql -ldata=/var/lib/mysql</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>prestant mysql<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># service mysqld start</div></pre><!--END_DEVFMTCODE--></p>
<p>After the server was up, I changed the root password and added a new user:</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="Bash"><div class="devcodeoverflow"><span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>prestant mysql<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># mysqladmin -u root password NEWPASSWORD</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>prestant mysql<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># mysql -pNEWPASSWORD</span>
&nbsp;
</div></pre><!--END_DEVFMTCODE--><br />
<!--DEVFMTCODE--><pre class="devcodeblock" title="MySQL"><div class="devcodeoverflow">Welcome <span style="color: #990099; font-weight: bold;">to</span> the MySQL monitor.  Commands <span style="color: #009900;">end</span> <span style="color: #990099; font-weight: bold;">with</span> <span style="color: #000033;">;</span> <span style="color: #CC0099; font-weight: bold;">or</span> \g.
Your MySQL <span style="color: #FF9900; font-weight: bold;">connection</span> id <span style="color: #CC0099; font-weight: bold;">is</span> 5
Server <span style="color: #000099;">version</span>: 5.0.82sp1 Source distribution
&nbsp;
<span style="color: #990099; font-weight: bold;">Type</span> <span style="color: #008000;">'help;'</span> <span style="color: #CC0099; font-weight: bold;">or</span> <span style="color: #008000;">'<span style="color: #004000; font-weight: bold;">\h</span>'</span> for <span style="color: #990099; font-weight: bold;">help</span>. <span style="color: #990099; font-weight: bold;">Type</span> <span style="color: #008000;">'<span style="color: #004000; font-weight: bold;">\c</span>'</span> <span style="color: #990099; font-weight: bold;">to</span> clear the current input statement.
&nbsp;
mysql<span style="color: #CC0099;">&gt;</span> <span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #000099;">USER</span> <span style="color: #008000;">'ivan'</span>@<span style="color: #008000;">'<span style="color: #008080; font-weight: bold;">%</span>'</span> IDENTIFIED BY <span style="color: #008000;">'passhere'</span><span style="color: #000033;">;</span>
Query OK<span style="color: #000033;">,</span> 0 rows affected <span style="color: #FF00FF;">&#40;</span>0.00 sec<span style="color: #FF00FF;">&#41;</span>
&nbsp;
mysql<span style="color: #CC0099;">&gt;</span> <span style="color: #990099; font-weight: bold;">GRANT</span> <span style="color: #990099; font-weight: bold;">ALL</span> <span style="color: #990099; font-weight: bold;">PRIVILEGES</span> <span style="color: #990099; font-weight: bold;">ON</span> <span style="color: #CC0099;">*</span>.<span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">TO</span> <span style="color: #008000;">'ivan'</span>@<span style="color: #008000;">'<span style="color: #008080; font-weight: bold;">%</span>'</span> IDENTIFIED BY <span style="color: #008000;">'passhere'</span> <span style="color: #990099; font-weight: bold;">WITH</span> <span style="color: #990099; font-weight: bold;">GRANT</span> <span style="color: #990099; font-weight: bold;">OPTION</span> MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 <span style="color: #000033;">;</span>
Query OK<span style="color: #000033;">,</span> 0 rows affected <span style="color: #FF00FF;">&#40;</span>0.00 sec<span style="color: #FF00FF;">&#41;</span>
&nbsp;
mysql<span style="color: #CC0099;">&gt;</span> <span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #000099;">USER</span> <span style="color: #008000;">'ivan'</span>@<span style="color: #008000;">'localhost'</span> IDENTIFIED BY <span style="color: #008000;">'passhere'</span><span style="color: #000033;">;</span>
Query OK<span style="color: #000033;">,</span> 0 rows affected <span style="color: #FF00FF;">&#40;</span>0.00 sec<span style="color: #FF00FF;">&#41;</span>
&nbsp;
mysql<span style="color: #CC0099;">&gt;</span> <span style="color: #990099; font-weight: bold;">GRANT</span> <span style="color: #990099; font-weight: bold;">ALL</span> <span style="color: #990099; font-weight: bold;">PRIVILEGES</span> <span style="color: #990099; font-weight: bold;">ON</span> <span style="color: #CC0099;">*</span>.<span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">TO</span> <span style="color: #008000;">'ivan'</span>@<span style="color: #008000;">'localhost'</span> <span style="color: #990099; font-weight: bold;">WITH</span> <span style="color: #990099; font-weight: bold;">GRANT</span> <span style="color: #990099; font-weight: bold;">OPTION</span><span style="color: #000033;">;</span>
Query OK<span style="color: #000033;">,</span> 0 rows affected <span style="color: #FF00FF;">&#40;</span>0.00 sec<span style="color: #FF00FF;">&#41;</span>
&nbsp;
mysql<span style="color: #CC0099;">&gt;</span> flush <span style="color: #990099; font-weight: bold;">privileges</span><span style="color: #000033;">;</span>
Query OK<span style="color: #000033;">,</span> <span style="color: #008080;">0</span> rows affected <span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">0.00</span> sec<span style="color: #FF00FF;">&#41;</span>
&nbsp;
mysql<span style="color: #CC0099;">&gt;</span> exit
Bye
&nbsp;
&nbsp;
</div></pre><!--END_DEVFMTCODE--></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ivanvillareal.info/linux/mysql5-and-php5-on-centos4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Removing Hybrid feature of an Acomdata drive.</title>
		<link>http://blog.ivanvillareal.info/linux/removing-hybrid-feature-of-an-acomdata-drive/</link>
		<comments>http://blog.ivanvillareal.info/linux/removing-hybrid-feature-of-an-acomdata-drive/#comments</comments>
		<pubDate>Thu, 01 Oct 2009 17:58:28 +0000</pubDate>
		<dc:creator>Ivan Villareal</dc:creator>
				<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[external hd]]></category>
		<category><![CDATA[firmware]]></category>
		<category><![CDATA[flashing]]></category>

		<guid isPermaLink="false">http://blog.ivanvillareal.info/?p=50</guid>
		<description><![CDATA[

About 2 years ago I purchased this 500Gb Acomdata drive that was on sale at Fry&#8217;s, it was a good deal back then, cost me about 100 bucks, it had an aluminium case and a power off switch, and I was in the need to expand the storage capacity of my multimedia server, which is [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.ivanvillareal.info/wp-content/uploads/2009/10/AcomdataDrive.jpg"><br />
<img class="size-full wp-image-51 alignleft" title="Acomdata Drive" src="http://blog.ivanvillareal.info/wp-content/uploads/2009/10/AcomdataDrive.jpg" alt="500Gb Acomdata Drive" width="420" height="210" /></a></p>
<p>About 2 years ago I purchased this <a title="Product Page" href="http://www.acomdata.com/e5_hybriddrive.asp" target="_blank">500Gb Acomdata drive</a> that was on sale at Fry&#8217;s, it was a good deal back then, cost me about 100 bucks, it had an aluminium case and a power off switch, and I was in the need to expand the storage capacity of my multimedia server, which is linux based.</p>
<p>I didn&#8217;t researched this product, I didn&#8217;t even knew that acomdata was a brand, anyway I remember seeing the &#8220;Hybrid Drive&#8221; statement, but didn&#8217;t care, I was going to wipe this drive an reformat it as ext3, so I was aware that all the &#8220;software features&#8221; it had were useless to me, like the <span>PushButton&trade; Backup and the Nomad Mobile Desktop.</span></p>
<p><span>After I arrived home, I plugged this thing on my server, which had ivman and a custom script to mount anything, but after few seconds nothing happened, I look at the kernel&nbsp;messages&nbsp;and I started to worry, It showed as a CD drive instead of a Mass Storage Device, I tried&nbsp;unsuccessfully&nbsp;to mount this manually, so I&nbsp;thought&nbsp;this drive must be bad.</span></p>
<p>The next day I connected this drive to a Windows XP, and after some drivers install, it was working, I noticed that it created a virtual CD drive on Windows it had some software on it, so I&nbsp;thought&nbsp;that this was some kind of partition that would be erased after I formatted the drive, so I did this, but the partition was still there.</p>
<p>I did some research on the internet but didn&#8217;t found anything&nbsp;use full, so I was again trying to make this stupid drive worked on linux, I hate when I have to fight with the stuff I buy just to make it work on linux, I was very annoyed by this, finally after looking the kernel messages I&#8217;ve found that the drive was acting as a SCSI device, so I activated &#8220;Probe all LUNs on each SCSI device&#8221; in the kernel and after a kernel restart both partitions were available on&nbsp;Linux, however this still had a problem, because I was using ivman to detect the drive and mounted, ivman &nbsp;didn&#8217;t worked for hard drive partition, just for the virtual CD, I&#8217;ve tried&nbsp;unsuccessfully&nbsp;to delete that stupid CD partition on windows and Linux.</p>
<p>I had enough of this and I was going to take this drive back to the store, but in a desperation moment I took my screwdriver and started to tearing apart the drive, I wasn&#8217;t even stopped by the warranty void seal, my intention was to take the drive format it and put it back&nbsp;without&nbsp;the cd part, I did this, and the format was&nbsp;successful, the drive was totally empty, but when I put this back to the enclosure the stupid CD partition was there, empty this time, but it was there, so it was a firmware issue and I didn&#8217;t found a firmware upgrade to remove this stupid feature.</p>
<p>I did some scripts to detect this&nbsp;unmounted the CD part&nbsp;and mount the hard drive partition, it took me about a week to have this thing working the way I wanted, &nbsp;this was &nbsp;unbelievable,&nbsp;why they don&#8217;t put the software to remove this &#8220;hybryd feature&#8221;.</p>
<p>However this drive has been working fine, with the virtual CD partition still there until Yesterday, I was in the need to transfer some large files from work to home, and this was the drive more reachable from all the drives I have, so I bring it her to the&nbsp;office, and as soon as I plugged in the CD partition appeared on my Desktop, so I&nbsp;thought&nbsp;it has been a while now, lets see if I can finally reflash the firmware to remove this so called feature, and I&#8217;ve found a forum with several users trying to remove this, and suddenly I&#8217;ve found this &nbsp;post:</p>
<blockquote><p>You need this software from http://www.mediafire.com/?bgwuwq5xzbm</p>
<p>unzip and click on MP251MFG, click on &#8220;configure hdd&#8221; and once it says pass just unplug and plug in the device. CD PART gone.&nbsp;</p></blockquote>
<p>I quickly downloaded the file in question, it was a zip file called &#8220;REMOVE CD PART.zip&#8221; with about 1.5Mb in size, it has &nbsp;a Readme.pdf that describes the MP251MFG program, I booted up in Windows, installed the <a title="Ext2 file system on windows" href="http://www.fs-driver.org/" target="_blank">fsdriver</a>&nbsp;because this drive was an ext3, plugged the drive and run the MP251MFG.exe application this is what I saw:</p>
<p style="text-align: center;"><a href="http://blog.ivanvillareal.info/wp-content/uploads/2009/10/MP251MFG_Interface.png"><img class="size-full wp-image-57 aligncenter" title="MP251MFG.exe Interface" src="http://blog.ivanvillareal.info/wp-content/uploads/2009/10/MP251MFG_Interface.png" alt="MP251MFG.exe Interface" width="540" height="328" /></a></p>
<p>I didn&#8217;t backed up the drive, I was just exploring the options and I clicked the Configure HDD, a process was started and finished&nbsp;successfully, I was affraid that my data were gone, so I headed to check if the data was there, and it was, I copied the important stuff somewhere else, unplugged the drive and plugged back in, and voilà, the CD partition was gone along with the data in the drive, but that din&#8217;t matter the CD partition was really gone <img src='http://blog.ivanvillareal.info/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>The drive was reformatted to FAT32, so I reformatted back to ext3, and now it is working pretty well, 2 years later.</p>
<p>I&#8217;ve found that this program works for other drives too, here are some links where this program can be found</p>
<p>For Windows:</p>
<ul>
<li><a href="http://www.techsupportlive.com/index.php?_m=downloads&amp;_a=viewdownload&amp;downloaditemid=53&amp;nav=0,7" target="link">xSil251  Switch HDD to CD+HDD_Nomad Mobile Desktop_V1.04_091007</a></li>
<li><a href="http://www.techsupportlive.com/index.php?_m=downloads&amp;_a=viewdownload&amp;downloaditemid=29" target="link">xSil251 Switch CD+HDD to HDD 3.5_Toshiba_V1.02_041307</a>&nbsp;</li>
</ul>
<p>For Macintosh:</p>
<ul>
<li><a href="http://www.techsupportlive.com/index.php?_m=downloads&amp;_a=viewdownload&amp;downloaditemid=51&amp;nav=0,7" target="link">Switch to CD+Secure Nomad for Mac</a></li>
<li><a href="http://www.techsupportlive.com/index.php?_m=downloads&amp;_a=viewdownload&amp;downloaditemid=46" target="link">CD to HDD Convertor for Mac</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.ivanvillareal.info/linux/removing-hybrid-feature-of-an-acomdata-drive/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting up ssh keys for passwordless login</title>
		<link>http://blog.ivanvillareal.info/linux/setting-up-ssh-keys-for-passwordless-login/</link>
		<comments>http://blog.ivanvillareal.info/linux/setting-up-ssh-keys-for-passwordless-login/#comments</comments>
		<pubDate>Fri, 25 Sep 2009 23:57:29 +0000</pubDate>
		<dc:creator>Ivan Villareal</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[auth]]></category>
		<category><![CDATA[key]]></category>
		<category><![CDATA[passwordless]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://blog.ivanvillareal.info/?p=40</guid>
		<description><![CDATA[Most part of the time I&#8217;ve spent on my development machine I have several terminals opened, but thanks to screen I only have one per server.
However I&#8217;m constantly in the need to login to some servers just to make a quick check of something, so I have to type in my credentials every time I [...]]]></description>
			<content:encoded><![CDATA[<p>Most part of the time I&#8217;ve spent on my development machine I have several terminals opened, but thanks to <a title="Screen is a full-screen window manager that multiplexes a physical terminal between several processes" href="http://www.gnu.org/software/screen/" target="_blank">screen </a>I only have one per server.</p>
<p>However I&#8217;m constantly in the need to login to some servers just to make a quick check of something, so I have to type in my credentials every time I log in, this really annoys me, because when I&#8217;m focused on something I don&#8217;t want to loose that focus waiting for the login prompt.</p>
<p>So what I did &nbsp;to fix this annoyance, was to use Key Authentication &nbsp;instead of Password Authentication, I&#8217;ve been using this for several years now under several distros&nbsp;without&nbsp;a problem.</p>
<p>So in short this is what I do, whenever I want to use Key Auth.<br />
<pre>gondor .ssh # cd ~/.ssh
gondor .ssh ~ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
53:df:bb:74:24:2d:7f:78:1f:85:66:f0:19:b6:9f:71 root@gondor
The key's randomart image is:
+--[ RSA 2048]----+
|                 |
|                 |
|          . . o  |
|         . . = * |
|        S   . @.E|
|         .   o O=|
|              +o*|
|             . ++|
|              . .|
+-----------------+</pre><br />
I haven&#8217;t set a password for the key, &nbsp;because if I set a password I would have to type the password for the key each time, or setup a program to remember the key password like Gnome Keyring or Putty Pageant in Windows.</p>
<p>After my private and public keys are generated I copy the public key to the server where I want to access&nbsp;without&nbsp;password<br />
<pre>
gondor .ssh # ssh-copy-id -i id_rsa.pub ivan@odin
The authenticity of host 'odin (192.168.1.201)' can't be established.
RSA key fingerprint is bb:36:b4:0b:05:13:ce:a2:2e:95:97:59:65:f3:f8:a8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'odin,192.168.1.201' (RSA) to the list of known hosts.
Password:
Now try logging into the machine, with "ssh 'ivan@odin'", and check in:

  .ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

gondor .ssh # ssh ivan@odin
Last login: Fri Sep 25 15:50:03 PDT 2009 from gondor.artedigital on ssh
Last login: Fri Sep 25 15:50:07 2009 from gondor.artedigital
ivan@odin ~ $</pre></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ivanvillareal.info/linux/setting-up-ssh-keys-for-passwordless-login/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Automated Capture of Webpages (Main Process)</title>
		<link>http://blog.ivanvillareal.info/linux/automated-capture-of-webpages-main-process/</link>
		<comments>http://blog.ivanvillareal.info/linux/automated-capture-of-webpages-main-process/#comments</comments>
		<pubDate>Fri, 25 Sep 2009 00:21:45 +0000</pubDate>
		<dc:creator>Ivan Villareal</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[architechture]]></category>
		<category><![CDATA[daemon]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[xvfb]]></category>
		<category><![CDATA[Zend_Json]]></category>

		<guid isPermaLink="false">http://blog.ivanvillareal.info/?p=25</guid>
		<description><![CDATA[This post is the continuation of &#160;Xvfb and Firefox headless screenshot generator&#160;were I explained how Xvfb and Firefox can be used to get a screenshot of any web resource supported by firefox.
The next challenge I had, involved the creation of an automated process that could be called from the web or from a cron job, [...]]]></description>
			<content:encoded><![CDATA[<p>This post is the continuation of &nbsp;<strong><a title="Xvfb and Firefox headless screenshot generator" href="http://blog.ivanvillareal.info/linux/xvfb-and-firefox-headles-screenshot-generator/">Xvfb and Firefox headless screenshot generator</a>&nbsp;</strong>were I explained how Xvfb and Firefox can be used to get a screenshot of any web resource supported by firefox.</p>
<p>The next challenge I had, involved the creation of an automated process that could be called from the web or from a cron job, this process job would take a list of sites that need to be captured, and it will save its shots with their respective thumbnail somewhere, also this same process had to&nbsp;communicate&nbsp;somehow with the&nbsp;front end, to inform the user about the status.</p>
<p>So I&#8217;ve planned the&nbsp;architecture&nbsp;for this solution in a modular way</p>
<ul>
<li>A daemon checking if new jobs were sent.</li>
<li>The main process that takes some parameters including the site list and save the generated screenshots somewhere.</li>
<li>A logger facility to&nbsp;communicate&nbsp;with an external process.</li>
<li>A web application to take the site list and show the results.</li>
</ul>
<p>This is the&nbsp;architecture&nbsp;diagram:</p>
<div id="attachment_28" class="wp-caption aligncenter" style="width: 727px"><a href="http://blog.ivanvillareal.info/wp-content/uploads/2009/09/screen_grabber_system_arquitechture1.png"><img class="size-large wp-image-28 " title="Screen Grabber System Arquitechture" src="http://blog.ivanvillareal.info/wp-content/uploads/2009/09/screen_grabber_system_arquitechture1-717x1024.png" alt="Screen Grabber System Arquitechture" width="717" height="1024" /></a><p class="wp-caption-text">Screen Grabber System Arquitechture</p></div>
<p>From the above modules, I will describe briefly the Main process, this main process started as a simple bash script but this wasn&#8217;t sufficient for&nbsp;scalability and security standpoints, so I&#8217;ve decided to make it in perl.</p>
<p>&nbsp;</p>
<p>The current version has changed a lot, but I will describe the main aspects of this script:</p>
<p>The following CPAN extensions were used in this module:</p>
<ul>
<li><a title="Run - Perl extension for to start programs in background" href="http://search.cpan.org/~ilyaz/Run-0.03/Run.pm" target="_blank">Run</a></li>
<li><a title="DBI - Database independent interface for Perl" href="http://search.cpan.org/~timb/DBI-1.609/DBI.pm" target="_blank">DBI</a></li>
<li><a title="File::Basename - Parse file paths into directory, filename and suffix." href="http://search.cpan.org/~dapm/perl-5.10.1/lib/File/Basename.pm" target="_blank">File::Basename</a></li>
<li><span style="text-decoration: line-through;"><a title="Perl implementation of PHP's native serialize(), unserialize() [Used at first to comunicate with PHP frontend, now the comunication is done trough the db]" href="http://hurring.com/code/perl/serialize/" target="_blank">Serialize</a></span></li>
</ul>
<p>This process receives the following arguments:</p>
<ol>
<li>The path to a file where the list of urls are, the filename represents the job name and this file must contain 1 url per line <span style="color: #ff0000;">(Required)</span></li>
<li><span style="color: #ff0000;"><span style="color: #000000;">The number of seconds that firefox will have to render each url <span style="color: #3366ff;">(Optional)</span></span></span></li>
</ol>
<p>After the main process is called, either by a daemon or by a cron job, it will connect to a database and search the job based on the received parameter, this job needs to be inserted with an API I did in php, this API is called from the frontend and the cron jobs as well and it serves as a glue point between everything.</p>
<p>After the update is done, I prepare the environment for Xvfb and spawn a new Virtual Screen with its corresponding firefox instance:</p>
<p>This is the code used:</p>
<p><span style="font-family: monospace;"><!--DEVFMTCODE--><pre class="devcodeblock" title="Perl"><div class="devcodeoverflow">
<span style="color: #000000; font-weight: bold;">sub</span> initialize <span style="color: #009900;">&#123;</span>
    logThis<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;======= Process Starting ==========&quot;</span><span style="color: #339933;">,</span> 1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$numArgs</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$#ARGV</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$numArgs</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        logThis<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Bad number of parameters&quot;</span><span style="color: #339933;">,</span> 1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">die</span> <span style="color: #ff0000;">&quot;Bad Number of params <span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000066;">chomp</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$siteList</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$ARGV</span><span style="color: #009900;">&#91;</span>0<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$numArgs</span> <span style="color: #339933;">&gt;</span> 2<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066;">chomp</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$renderTime</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$ARGV</span><span style="color: #009900;">&#91;</span>2<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$jobName</span><span style="color: #339933;">,</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$dirName</span><span style="color: #339933;">,</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$fileExtension</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> fileparse<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$siteList</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'\.processing'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    logThis<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Parameters received <span style="color: #000099; font-weight: bold;">\n</span>SiteList: $siteList<span style="color: #000099; font-weight: bold;">\n</span>Related Domain:$relatedDomain<span style="color: #000099; font-weight: bold;">\n</span>Render Time: $renderTime&quot;</span><span style="color: #339933;">,</span>1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    logThis<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Initializing Db&quot;</span><span style="color: #339933;">,</span>3<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$dsn</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;DBI:mysql:database=$db{'name'};host=$db{'host'};port=$db{'port'}&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$dbh</span> <span style="color: #339933;">=</span> DBI<span style="color: #339933;">-&gt;</span><span style="color: #006600;">connect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$dsn</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$db</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'user'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$db</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'pass'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">or</span> <span style="color: #000066;">die</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'failed to connect'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$jobRow</span> <span style="color: #339933;">=</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$domain</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$dbh</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">selectrow_hashref</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;SELECT idJobs FROM jobs WHERE jobName = ?&quot;</span><span style="color: #339933;">,</span><span style="color: #000066;">undef</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$jobName</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$jobId</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$jobRow</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'idJobs'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$result</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$dbh</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">do</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;UPDATE jobs SET dateStarted = CURRENT_TIMESTAMP WHERE jobName = ?&quot;</span><span style="color: #339933;">,</span><span style="color: #000066;">undef</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$jobName</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    logThis<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Conected to Db $db{'name'}&quot;</span><span style="color: #339933;">,</span>1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    jobUpdate<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Starting capture process...&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$ENV</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'DISPLAY'</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span><span style="color: #ff0000;">':1'</span><span style="color: #339933;">;</span>
    logThis<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Starting virtual screen...&quot;</span><span style="color: #339933;">,</span>3<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$pid</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'xvfb'</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> spawn <span style="color: #0000ff;">$xvfbBin</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">':1'</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'-screen'</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'0'</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'1024x768x24'</span> <span style="color: #b1b100;">or</span> <span style="color: #000066;">die</span> <span style="color: #ff0000;">&quot;Xvfb failed to start $!&quot;</span><span style="color: #339933;">;</span>
    logThis<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Xvfb Pid: $pid{'xvfb'} &quot;</span><span style="color: #339933;">,</span>3<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$pid</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'ratpoison'</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> spawn <span style="color: #ff0000;">'ratpoison'</span> <span style="color: #b1b100;">or</span> <span style="color: #000066;">die</span> <span style="color: #ff0000;">&quot;spawn ratpoison failed&quot;</span><span style="color: #339933;">;</span>
    logThis<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Ratpoison Pid: $pid{'ratpoison'} &quot;</span><span style="color: #339933;">,</span>3<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">sleep</span><span style="color: #009900;">&#40;</span>1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$pid</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'firefox'</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> spawn <span style="color: #0000ff;">$ffBin</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'-width 1024'</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'-height 768'</span> <span style="color: #b1b100;">or</span> <span style="color: #000066;">die</span> <span style="color: #ff0000;">&quot;spawn $!&quot;</span><span style="color: #339933;">;</span>
    logThis<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Firefox Process Id: $pid{'firefox'}&quot;</span><span style="color: #339933;">,</span>1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">sleep</span><span style="color: #009900;">&#40;</span>5<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    logThis<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;---Initialize sub end here---&quot;</span><span style="color: #339933;">,</span>4<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">return</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
</div></pre><!--END_DEVFMTCODE--><br />
</span></p>
<p>After the initialization I proceed to read the list of files to start capturing each one, this is the code that does exactly that:</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="Perl"><div class="devcodeoverflow"> 
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009999;">&lt;FILE&gt;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
 <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$site</span>    <span style="color: #339933;">=</span> <span style="color: #0000ff;">$_</span><span style="color: #339933;">;</span>
 <span style="color: #000066;">chop</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$site</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #666666; font-style: italic;">##</span>
 <span style="color: #666666; font-style: italic;"># Validate that the line starts with http or https</span>
 <span style="color: #666666; font-style: italic;">##</span>
 <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$site</span> <span style="color: #339933;">=~</span> <span style="color: #000066;">m</span><span style="color: #339933;">!</span><span style="color: #0000ff;">\b</span><span style="color: #009900;">&#40;</span>https<span style="color: #339933;">?</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">://!</span>i<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    logThis<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Processing: $site&quot;</span><span style="color: #339933;">,</span>4<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    captureSite<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$site</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$relatedDomainId</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    logThis<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Sites Processed&quot;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">$stats</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'processed'</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">.</span><span style="color: #ff0000;">&quot;=&quot;</span><span style="color: #339933;">.</span> <span style="color: #0000ff;">$stats</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'succesfull'</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">.</span><span style="color: #ff0000;">&quot;+&quot;</span><span style="color: #339933;">.</span> <span style="color: #0000ff;">$stats</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'failed'</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">.</span><span style="color: #ff0000;">&quot;+&quot;</span><span style="color: #339933;">.</span> <span style="color: #0000ff;">$stats</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'unrendered'</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">.</span><span style="color: #ff0000;">&quot;entre &quot;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">$stats</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'siteCount'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$stats</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'percentage'</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$stats</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'processed'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">/</span><span style="color: #0000ff;">$stats</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'siteCount'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span>
    updateStatus<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'stats'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">\%stats</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #009900;">&#125;</span></div></pre><!--END_DEVFMTCODE--></p>
<p>And the captureSite sub is where the magic is, here it is:</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="Perl"><div class="devcodeoverflow">
<span style="color: #000000; font-weight: bold;">sub</span> captureSite <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$site</span>          <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$result</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$imgName</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$imageStatus</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">''</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$fileNameExit</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$imgCounter</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$imgFullName</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$thumbFile</span><span style="color: #339933;">;</span>
&nbsp;
    updateStatus<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'status'</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Processing $site&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    jobUpdate<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Processing $site&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    logThis<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Starting to capture: $site&quot;</span><span style="color: #339933;">,</span>2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">##</span>
<span style="color: #666666; font-style: italic;"># Check the domain for valid parts</span>
<span style="color: #666666; font-style: italic;">##</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@domainParts</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$site</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">m/\b((?#protocol)https?|ftp):\/\/((?#domain)[-A-Z0-9.]+)((?#file)\/[-A-Z0-9+&amp;@#\/%=~_|!:,.;]*)?((?#parameters)\?[-A-Z0-9+&amp;@#\/%=~_|!:,.;]*)?/ig</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$domainParts</span><span style="color: #009900;">&#91;</span>0<span style="color: #009900;">&#93;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #0000ff;">$domainParts</span><span style="color: #009900;">&#91;</span>1<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$openedTabs</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000ff;">$maximumTabs</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            logThis<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Maximum Number of Opened Tabs Reached Killing Firefox pid $pid{'firefox'}&quot;</span><span style="color: #339933;">,</span>3<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000066;">kill</span> 0<span style="color: #339933;">,</span> <span style="color: #0000ff;">$pid</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'firefox'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
            <span style="color: #000066;">sleep</span><span style="color: #009900;">&#40;</span>2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #0000ff;">$pid</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'firefox'</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> spawn <span style="color: #0000ff;">$ffBin</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'-width 1024'</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'-height 768'</span> <span style="color: #b1b100;">or</span> <span style="color: #000066;">die</span> <span style="color: #ff0000;">&quot;spawn $!&quot;</span><span style="color: #339933;">;</span>
            logThis<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;New Firefox Process Id: $pid{'firefox'}&quot;</span><span style="color: #339933;">,</span>1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000066;">sleep</span><span style="color: #009900;">&#40;</span>3<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #0000ff;">$openedTabs</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">#because ff is tabless the old page doesn't disappear until</span>
<span style="color: #666666; font-style: italic;">#all content is loaded, so I should remove content first.</span>
        <span style="color: #0000ff;">$cmd</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$ffBin</span> <span style="color: #339933;">.</span> <span style="color: #ff0000;">' -remote &quot;openUrl(http://localhost/blank.html)&quot;'</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$res</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">`$cmd`</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">sleep</span><span style="color: #009900;">&#40;</span>1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #0000ff;">$cmd</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$ffBin</span> <span style="color: #339933;">.</span> <span style="color: #ff0000;">' -remote &quot;openUrl('</span><span style="color: #339933;">.</span><span style="color: #0000ff;">$site</span><span style="color: #339933;">.</span><span style="color: #ff0000;">')&quot;'</span><span style="color: #339933;">;</span>
        logThis<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Opening $site&quot;</span><span style="color: #339933;">,</span>1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        logThis<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$cmd</span><span style="color: #339933;">,</span> 3<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #0000ff;">$res</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">`$cmd`</span><span style="color: #339933;">;</span>
        <span style="color: #0000ff;">$openedTabs</span><span style="color: #339933;">++;</span>
        logThis<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Waiting $renderTime seconds to allow page rendering&quot;</span><span style="color: #339933;">,</span>3<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">sleep</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$renderTime</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">##</span>
<span style="color: #666666; font-style: italic;"># We remove harmfull charachters</span>
<span style="color: #666666; font-style: italic;"># maybe an md5sum would be better, because</span>
<span style="color: #666666; font-style: italic;"># we would always have the same number of chars</span>
<span style="color: #666666; font-style: italic;">##</span>
        <span style="color: #0000ff;">$imgName</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$site</span><span style="color: #339933;">;</span>
        <span style="color: #0000ff;">$imgName</span> <span style="color: #339933;">=~</span> <span style="color: #000066;">s</span><span style="color: #339933;">!</span><span style="color: #0000ff;">\b</span><span style="color: #009900;">&#40;</span>https<span style="color: #339933;">?</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">://|</span><span style="color: #009900;">&#40;</span>www\<span style="color: #339933;">.</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">!!</span>g<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">#removes http://www</span>
            <span style="color: #0000ff;">$imgName</span> <span style="color: #339933;">=~</span> <span style="color: #000066;">s</span><span style="color: #339933;">!</span>\<span style="color: #339933;">/|</span>\<span style="color: #666666; font-style: italic;">#|\?$!!g; #removes \ # ? from the end</span>
            <span style="color: #0000ff;">$imgName</span> <span style="color: #339933;">=~</span> <span style="color: #000066;">s</span><span style="color: #339933;">!</span><span style="color: #009900;">&#91;</span><span style="color: #339933;">^</span>0<span style="color: #339933;">-</span>9<span style="color: #339933;">^</span>A<span style="color: #339933;">-</span>Z<span style="color: #339933;">^</span>a<span style="color: #339933;">-</span>z<span style="color: #339933;">^</span>_<span style="color: #339933;">^.</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">!</span>_<span style="color: #339933;">!</span>g<span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">#cut excessive large filenames</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066;">length</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$imgName</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000ff;">$maxFileNameLength</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #0000ff;">$imgName</span> <span style="color: #339933;">=</span> <span style="color: #000066;">substr</span> <span style="color: #0000ff;">$imgName</span><span style="color: #339933;">,</span> 0<span style="color: #339933;">,</span> <span style="color: #0000ff;">$maxFileNameLength</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$baseImgName</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$imgName</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #0000ff;">$fileNameExit</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #0000ff;">$imgFullName</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$saveDir</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">$imgName</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">$saveFormat</span><span style="color: #339933;">;</span>
            <span style="color: #0000ff;">$thumbFile</span>   <span style="color: #339933;">=</span> <span style="color: #0000ff;">$thumbsDir</span> <span style="color: #339933;">.</span> <span style="color: #ff0000;">'thumb_'</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">$imgName</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">$saveFormat</span><span style="color: #339933;">;</span>
            logThis<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$imgFullName</span><span style="color: #339933;">,</span>1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            logThis<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Cecking if image already exists&quot;</span><span style="color: #339933;">,</span>1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span>e <span style="color: #0000ff;">$imgFullName</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #0000ff;">$imgCounter</span><span style="color: #339933;">++;</span>
                <span style="color: #0000ff;">$imgName</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$baseImgName</span> <span style="color: #339933;">.</span> <span style="color: #ff0000;">'_'</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">$imgCounter</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #0000ff;">$fileNameExit</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">#creating the screenshot</span>
        <span style="color: #0000ff;">$cmd</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'import -window root '</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">$imgFullName</span><span style="color: #339933;">;</span>
        logThis<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Command: &quot;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">$cmd</span><span style="color: #339933;">,</span> 3<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #0000ff;">$res</span>   <span style="color: #339933;">=</span> <span style="color: #ff0000;">`$cmd`</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span>e <span style="color: #0000ff;">$imgFullName</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            logThis<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;The image $imgFullName was created succesfully&quot;</span><span style="color: #339933;">,</span>1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #0000ff;">$imageStatus</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'success'</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$fileSize</span> <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #000066;">s</span> <span style="color: #0000ff;">$imgFullName</span><span style="color: #339933;">;</span>
            logThis<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;File Size for image created: $fileSize&quot;</span><span style="color: #339933;">,</span>1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;"># Check the filesize, if its to low wait give more time to render the page</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$fileSize</span> <span style="color: #339933;">&lt;=</span> <span style="color: #0000ff;">$minFileSize</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                logThis<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;File is too small, I think the page has not finished rendering, giving it more time...&quot;</span><span style="color: #339933;">,</span>2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$exit</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$try</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #0000ff;">$exit</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    logThis<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Giving the page $renderTime more seconds to render...&quot;</span><span style="color: #339933;">,</span>2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    updateStatus<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'status'</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Giving $site more time to render...&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #000066;">sleep</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$renderTime</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    logThis<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Command: &quot;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">$cmd</span><span style="color: #339933;">,</span> 3<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #0000ff;">$res</span>   <span style="color: #339933;">=</span> <span style="color: #ff0000;">`$cmd`</span><span style="color: #339933;">;</span>
                    <span style="color: #0000ff;">$fileSize</span> <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #000066;">s</span> <span style="color: #0000ff;">$imgFullName</span><span style="color: #339933;">;</span>
                    logThis<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;File Size for image created: $fileSize&quot;</span><span style="color: #339933;">,</span>1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$fileSize</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000ff;">$minFileSize</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        <span style="color: #0000ff;">$exit</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
                        <span style="color: #0000ff;">$imageStatus</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'success'</span><span style="color: #339933;">;</span>
                    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
                        <span style="color: #0000ff;">$try</span><span style="color: #339933;">++;</span>
                    <span style="color: #009900;">&#125;</span>
                    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$try</span> <span style="color: #339933;">&gt;</span> 3 <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        <span style="color: #0000ff;">$exit</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
                        <span style="color: #0000ff;">$imageStatus</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'failed'</span><span style="color: #339933;">;</span>
                    <span style="color: #009900;">&#125;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
            logThis<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Croping image...&quot;</span><span style="color: #339933;">,</span>1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #0000ff;">$cmd</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;convert $imgFullName -crop '1024x768+0+24' $imgFullName&quot;</span><span style="color: #339933;">;</span>
            <span style="color: #0000ff;">$res</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">`$cmd`</span><span style="color: #339933;">;</span>
&nbsp;
            logThis<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Creating Thumbnail in $thumbFile&quot;</span><span style="color: #339933;">,</span>1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #0000ff;">$cmd</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;convert $imgFullName -resize '170x128' $thumbFile&quot;</span><span style="color: #339933;">;</span>
            <span style="color: #0000ff;">$res</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">`$cmd`</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">%image</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>
                    site   <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">$site</span><span style="color: #339933;">,</span>
                    image  <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">$imgFullName</span><span style="color: #339933;">,</span>
                    thumb  <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">$thumbFile</span><span style="color: #339933;">,</span>
                    status <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">$imageStatus</span><span style="color: #339933;">,</span>
                    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@images</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">\%image</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            insertImage<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$site</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$imgFullName</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$thumbFile</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$relatedDomainId</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$imageStatus</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$imageStatus</span> <span style="color: #b1b100;">eq</span> <span style="color: #ff0000;">'success'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #0000ff;">$stats</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'succesfull'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">++;</span>
            <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #0000ff;">$stats</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'failed'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">++;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
            logThis<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Fail creating the image&quot;</span><span style="color: #339933;">,</span>1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #0000ff;">$stats</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'unrendered'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">++;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #0000ff;">$stats</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'unrendered'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">++;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #0000ff;">$stats</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'processed'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">++;</span>
    jobUpdate<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Finished processing $site&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
</div></pre><!--END_DEVFMTCODE--></p>
<p>As you can see I&#8217;m updating the job status in the <strong>jobUpdate</strong> sub, also there are other subs to take care of &nbsp;inserting the screenshot info in the db.</p>
<p>When this program ends, it updates the db to let the inform the daemon that is ready to take more jobs.</p>
<p>In the next post I will be providing &nbsp;info on how the frontend works, and what the final results of this implementation ended.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ivanvillareal.info/linux/automated-capture-of-webpages-main-process/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Xvfb and Firefox headless screenshot generator</title>
		<link>http://blog.ivanvillareal.info/linux/xvfb-and-firefox-headles-screenshot-generator/</link>
		<comments>http://blog.ivanvillareal.info/linux/xvfb-and-firefox-headles-screenshot-generator/#comments</comments>
		<pubDate>Fri, 18 Sep 2009 00:25:41 +0000</pubDate>
		<dc:creator>Ivan Villareal</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[headless]]></category>
		<category><![CDATA[virtual screen]]></category>
		<category><![CDATA[xvfb]]></category>

		<guid isPermaLink="false">http://blog.ivanvillareal.info/?p=10</guid>
		<description><![CDATA[I&#8217;ve been working on a project that its main purpose is to get a screenshot of a bunch of different sites. The requirements for this project were simple.

It has to be fast
It needs to run on linux

I did some research, trying to found the best approach, I already knew Xvfb but haven&#8217;t worked with it [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on a project that its main purpose is to get a screenshot of a bunch of different sites. The requirements for this project were simple.</p>
<ul>
<li>It has to be fast</li>
<li>It needs to run on linux</li>
</ul>
<p>I did some research, trying to found the best approach, I already knew Xvfb but haven&#8217;t worked with it in a real project, there wasn&#8217;t much info about what I was trying to do, however I&#8217;ve found some other automated solutions made in .NET that worked on windows using IE as rendering engine, but I&#8217;ve found nothing that worked out of the box in linux <img src='http://blog.ivanvillareal.info/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>I did found some interesting setups but nothing similar to what I was trying to achieve, and all the directions I&#8217;ve got, pointed me to the same place <strong>Xvfb</strong>, so because I&#8217;m a hands-on guy, I quickly cloned a minimal debian box to start playing with this.</p>
<p>First I&#8217;ve installed Xvfb, firefox and some fonts</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="Bash"><div class="devcodeoverflow">
ivano ~ <span style="color: #666666; font-style: italic;"># apt-get install xvfb xfonts-base xfonts-75dpi xfonts-100dpi firefox</span>
</div></pre><!--END_DEVFMTCODE--></p>
<p>After some package downloads I&#8217;ve got everything installed, I&#8217;ve checked the man page and found:</p>
<blockquote><p>-screen screennum WxHxD</p>
<p>This  option  creates  screen screennum and sets its width, height,</p>
<p>and depth to W, H, and D respectively.  By default, only  screen  0</p>
<p>exists and has the dimensions 1280&#215;1024x12.</p></blockquote>
<p>So I did:</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="Bash"><div class="devcodeoverflow">
ivano ~ <span style="color: #666666; font-style: italic;"># Xvfb :1 -screen 0 1024x768x24 &amp;</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000;">2665</span>
ivano ~ <span style="color: #666666; font-style: italic;"># Could not init font path element /usr/X11R6/lib/X11/fonts/misc, removing from list!</span>
Could not init font path element <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>fonts<span style="color: #000000; font-weight: bold;">/</span>X11<span style="color: #000000; font-weight: bold;">/</span>cyrillic, removing from list<span style="color: #000000; font-weight: bold;">!</span>
Could not init font path element <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>fonts<span style="color: #000000; font-weight: bold;">/</span>X11<span style="color: #000000; font-weight: bold;">/</span>Type1, removing from list<span style="color: #000000; font-weight: bold;">!</span>
Could not init font path element <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>X11R6<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>X11<span style="color: #000000; font-weight: bold;">/</span>fonts<span style="color: #000000; font-weight: bold;">/</span>Type1, removing from list<span style="color: #000000; font-weight: bold;">!</span>
Could not init font path element <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>defoma<span style="color: #000000; font-weight: bold;">/</span>x-ttcidfont-conf.d<span style="color: #000000; font-weight: bold;">/</span>dirs<span style="color: #000000; font-weight: bold;">/</span>TrueType, removing from list<span style="color: #000000; font-weight: bold;">!</span>
</div></pre><!--END_DEVFMTCODE--></p>
<p>I&#8217;ve got some warnings from X, but nothing lethal, so now I have a Virtual X server ready to throw anything at it.</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="Bash"><div class="devcodeoverflow">ivano ~ <span style="color: #666666; font-style: italic;"># DISPLAY=:1 firefox http://google.com &amp;</div></pre><!--END_DEVFMTCODE--></p>
<p>I have to set the DISPLAY variable to be the same as the virtual screen I&#8217;ve created, after this command firefox must be there so I need to get a screen shot of the virtual screen so I&#8217;ve used the image magick import tool</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="Bash"><div class="devcodeoverflow">ivano ~ <span style="color: #666666; font-style: italic;"># DISPLAY=:1 import -window root google.com.png</div></pre><!--END_DEVFMTCODE--></p>
<p>When the import program ended I had a the following pg file:</p>
<div id="attachment_12" class="wp-caption aligncenter" style="width: 650px"><img class="size-full wp-image-12" title="google.com" src="http://blog.ivanvillareal.info/wp-content/uploads/2009/09/google.com.jpg" alt="Firefox capture within Xvfb" width="640" height="480" /><p class="wp-caption-text">Firefox capture within Xvfb</p></div>
<p>This apparently worked well, however I did some more testing to found any possible problem and the only thing I&#8217;ve found was that firefox tried to restore the session because of the improper shutdown so I had to tweak the firefox profile to avoid this, apart from this there were no other significant issues.</p>
<p>I will talk more about how I implemented the backend and frontend for the entire solution.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ivanvillareal.info/linux/xvfb-and-firefox-headles-screenshot-generator/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

<!-- www.000webhost.com Analytics Code -->
<script type="text/javascript" src="http://analytics.hosting24.com/count.php"></script>
<noscript><a href="http://www.hosting24.com/"><img src="http://analytics.hosting24.com/count.php" alt="web hosting" /></a></noscript>
<!-- End Of Analytics Code -->
