<?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 &#187; NFS Mac OSX Lion &#8211; Ivan Villareal</title>
	<atom:link href="http://ivanvillareal.com/tag/linux/feed/" rel="self" type="application/rss+xml" />
	<link>http://ivanvillareal.com</link>
	<description>IT stuff and more...</description>
	<lastBuildDate>Tue, 01 Nov 2011 23:00:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>NFS Mac OSX Lion</title>
		<link>http://ivanvillareal.com/osx/nfs-mac-osx-lion/</link>
		<comments>http://ivanvillareal.com/osx/nfs-mac-osx-lion/#comments</comments>
		<pubDate>Mon, 29 Aug 2011 19:37:57 +0000</pubDate>
		<dc:creator>Ivan Villareal</dc:creator>
				<category><![CDATA[OSX]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[nfs]]></category>

		<guid isPermaLink="false">http://ivanvillareal.com/uncategorized/nfs-mac-osx-lion/</guid>
		<description><![CDATA[I was in the need of sharing files from a mac osx 10.7 and some linux servers, so I tought this would be a simple process just like in linux, [...]]]></description>
			<content:encoded><![CDATA[<p>I was in the need of sharing files from a mac osx 10.7 and some linux servers, so I tought this would be a simple process just like in linux, but I found some issues that prevented me to mount exported dirs to the mac or setup a nfsd on the mac OS, this is more a reminder to my self about how I was able to perform that.</p>
<p>Case 1 &#8211; Mac OSX as NFS server:</p>
<p>this problem with this one is that the syntax of the exports is different from what I know, but after changing some options I was able to export the Users folder on the mac with the following line:</p>
<pre>/Users -alldirs -network 192.168.0.0 -mask 255.255.0.0</pre>
<p>to mount the above on my linux box I used this:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ivan<span style="color: #000000; font-weight: bold;">@</span>orion:~$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">mount</span> <span style="color: #660033;">-t</span> nfs macbox:Users<span style="color: #000000; font-weight: bold;">/</span>ivan<span style="color: #000000; font-weight: bold;">/</span> ivanomac</pre></div></div>

<p>Only problem found was the weird group and user numbers, so that needs to be mapped out, but because I was only to get some files from the mac I didn’t bother doing that.</p>
<p>Case 2 &#8211; Linux NFS server Mac OSX client:</p>
<p>This case is because I have a dev vm, and I need to do constant changes from the mac, the linux flavor of the vm is Ubuntu Server 11.04 and to get the nfs server running I did the following:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">scorpion ~<span style="color: #666666; font-style: italic;"># apt-get install nfs-kernel-server nfs-common portmap</span>
scorpion ~<span style="color: #666666; font-style: italic;"># echo “/var/www 192.168.0.0/16(rw,no_subtree_check,no_root_squash)” &amp;gt;&amp;gt; /etc/exports</span>
scorpion ~<span style="color: #666666; font-style: italic;"># exportfs -a</span></pre></div></div>

<p>and on the mac I ran the following:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>ivan<span style="color: #000000; font-weight: bold;">@</span>kunglao:~<span style="color: #007800;">$sudo</span> <span style="color: #c20cb9; font-weight: bold;">mount</span> <span style="color: #660033;">-t</span> nfs <span style="color: #660033;">-o</span> resvport,<span style="color: #007800;">vers</span>=<span style="color: #000000;">4</span> scorpion:<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www scorpion</pre></div></div>

<p>with the above I was able to view the files on the ubuntu server, however when I mounted the same export on another ubuntu machine I got the uid/gid wrong, to fix that I just ran the idmapd service on the client machine.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">orion ~ <span style="color: #666666; font-style: italic;"># service idmapd start</span>
orion ~<span style="color: #666666; font-style: italic;"># mount -t nfs scorpion:/var/www scorpion</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://ivanvillareal.com/osx/nfs-mac-osx-lion/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Perl script to manage virtual hosts</title>
		<link>http://ivanvillareal.com/linux/perl-script-to-manage-virtual-hosts/</link>
		<comments>http://ivanvillareal.com/linux/perl-script-to-manage-virtual-hosts/#comments</comments>
		<pubDate>Wed, 08 Jun 2011 19:54:57 +0000</pubDate>
		<dc:creator>Ivan Villareal</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Sysadmin]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[vhost]]></category>

		<guid isPermaLink="false">http://ivanvillareal.com/?p=237</guid>
		<description><![CDATA[I did this script a while back, and I&#8217;ve been using it on gentoo, ubuntu and centos distros with a few changes, this can be extended to add new functionality, [...]]]></description>
			<content:encoded><![CDATA[<p>I did this script a while back, and I&#8217;ve been using it on gentoo, ubuntu and centos distros with a few changes, this can be extended to add new functionality, and it may contain bugs, but so far it has worked for me pretty well, I can add/remove virtual hosts very quickly.</p>
<p>To use this script you only need the packages File::Path and Getopt::Long; both of them are already on newer distros, just put the script somewhere I have it in /usr/local/bin and call it with sudo.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ivan<span style="color: #000000; font-weight: bold;">@</span>orion:<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>vhosts$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> vhost-updater.pl <span style="color: #660033;">--add</span> <span style="color: #660033;">--domain</span> test.orion</pre></div></div>

<p>This is the output:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Creating docroot <span style="color: #c20cb9; font-weight: bold;">dir</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>vhosts<span style="color: #000000; font-weight: bold;">/</span>test.orion<span style="color: #000000; font-weight: bold;">/</span>public_html 
Creating log <span style="color: #c20cb9; font-weight: bold;">dir</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>vhosts<span style="color: #000000; font-weight: bold;">/</span>test.orion<span style="color: #000000; font-weight: bold;">/</span>logs 
Site File: <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>apache2<span style="color: #000000; font-weight: bold;">/</span>sites-available<span style="color: #000000; font-weight: bold;">/</span>test.orion 
Creating Vhost... 
Adding host test.orion 
Run <span style="color: #ff0000;">'/etc/init.d/apache2 reload'</span> to activate new configuration<span style="color: #000000; font-weight: bold;">!</span>
Restarting apache 
 <span style="color: #000000; font-weight: bold;">*</span> Restarting web server apache2
 ... waiting    ...done.</pre></div></div>

<p>Once it has finished, point your browser to http://test.orion, and you&#8217;re done.</p>
<p>Enjoy!</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/perl -w</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#############################################################</span>
<span style="color: #666666; font-style: italic;"># The purpose of this script is to add/remove				# </span>
<span style="color: #666666; font-style: italic;"># virtual hosts easily, this script runs 					#</span>
<span style="color: #666666; font-style: italic;"># on Ubuntu/Debian withouth modifications. 					#</span>
<span style="color: #666666; font-style: italic;">#         													#	</span>
<span style="color: #666666; font-style: italic;">#         													#	</span>
<span style="color: #666666; font-style: italic;"># Author Ivan Villareal ivaano@gmail.com					#</span>
<span style="color: #666666; font-style: italic;">#         													#	</span>
<span style="color: #666666; font-style: italic;">#############################################################</span>
<span style="color: #000000; font-weight: bold;">use</span> strict<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> File<span style="color: #339933;">::</span><span style="color: #006600;">Path</span> <span style="color: #000066;">qw</span><span style="color: #009900;">&#40;</span>mkpath rmtree<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> Getopt<span style="color: #339933;">::</span><span style="color: #006600;">Long</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #b1b100;">our</span> <span style="color: #0000ff;">$ipAddress</span>        <span style="color: #339933;">=</span> <span style="color: #ff0000;">'127.0.0.1'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">our</span> <span style="color: #0000ff;">$apacheConfigDir</span>  <span style="color: #339933;">=</span> <span style="color: #ff0000;">'/etc/apache2'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">our</span> <span style="color: #0000ff;">$sitesAvailable</span>   <span style="color: #339933;">=</span> <span style="color: #ff0000;">'sites-available'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">our</span> <span style="color: #0000ff;">$docRootPrefix</span>    <span style="color: #339933;">=</span> <span style="color: #ff0000;">'/var/www/vhosts'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">our</span> <span style="color: #0000ff;">$docRoot</span>          <span style="color: #339933;">=</span> <span style="color: #ff0000;">'public_html'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">our</span> <span style="color: #0000ff;">$logsDir</span>          <span style="color: #339933;">=</span> <span style="color: #ff0000;">'logs'</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$del</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;">$add</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;">$domain</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">''</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066;">getpwuid</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$&lt;</span> <span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">ne</span> <span style="color: #ff0000;">'root'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;Script needs root privileges <span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000066;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">unless</span> <span style="color: #009900;">&#40;</span>GetOptions <span style="color: #009900;">&#40;</span>
		<span style="color: #ff0000;">'del'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">\$del</span><span style="color: #339933;">,</span> 
		<span style="color: #ff0000;">'add'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">\$add</span><span style="color: #339933;">,</span> 
		<span style="color: #ff0000;">'domain=s'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">\$domain</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">or</span> usage<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    usage<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#print $paramResults;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$add</span> <span style="color: #339933;">||</span> <span style="color: #0000ff;">$del</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;">$domain</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;">$add</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            createVhost<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$domain</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elsif</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$del</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            deleteVhost<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$domain</span><span style="color: #009900;">&#41;</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>
        usage<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</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>
    usage<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> usage <span style="color: #009900;">&#123;</span>
    <span style="color: #000066;">print</span> <span style="color: #339933;">&lt;</span> <span style="color: #339933;">&lt;</span>USAGE
This program will add <span style="color: #b1b100;">or</span> remove apache virtual hosts<span style="color: #339933;">.</span>
&nbsp;
usage<span style="color: #339933;">:</span> vhost<span style="color: #339933;">-</span>updater<span style="color: #339933;">.</span>pl <span style="color: #009900;">&#91;</span><span style="color: #339933;">--</span>add <span style="color: #339933;">|</span> <span style="color: #339933;">--</span>del<span style="color: #009900;">&#93;</span> <span style="color: #339933;">--</span>domain newhost<span style="color: #339933;">.</span>tld 
USAGE
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> returnVhostPaths
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$vhost</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;">@dir</span> <span style="color: #339933;">=</span> <span style="color: #000066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/\//</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$docRootPrefix</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">%res</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@dir</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$vhost</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$hostDir</span> <span style="color: #339933;">=</span> <span style="color: #000066;">join</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'/'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">@dir</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$res</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'docRoot'</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$hostDir</span> <span style="color: #339933;">.</span> <span style="color: #ff0000;">'/'</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">$docRoot</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$res</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'logsDir'</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$hostDir</span> <span style="color: #339933;">.</span> <span style="color: #ff0000;">'/'</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">$logsDir</span><span style="color: #339933;">;</span>
	<span style="color: #0000ff;">$res</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'hostDir'</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$hostDir</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">#todo dir validation</span>
    <span style="color: #0000ff;">@dir</span> <span style="color: #339933;">=</span> <span style="color: #000066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/\//</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$apacheConfigDir</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;">@dir</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$sitesAvailable</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;">@dir</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$vhost</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$res</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'apacheConfig'</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #000066;">join</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'/'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">@dir</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066;">return</span> <span style="color: #0000ff;">%res</span><span style="color: #339933;">;</span>   
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> createVhost <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$vhost</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">#first create the docRoot</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">%vhostInfo</span> <span style="color: #339933;">=</span> returnVhostPaths<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$vhost</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    informOut<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Creating docroot dir: $vhostInfo{'docRoot'}&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    mkpath<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$vhostInfo</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'docRoot'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$user</span> <span style="color: #339933;">=</span> <span style="color: #000066;">getlogin</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$uid</span>  <span style="color: #339933;">=</span> <span style="color: #000066;">getpwnam</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$user</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$gid</span>  <span style="color: #339933;">=</span> <span style="color: #000066;">getgrnam</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$user</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066;">chown</span> <span style="color: #0000ff;">$uid</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$gid</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$vhostInfo</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'hostDir'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
	<span style="color: #000066;">chown</span> <span style="color: #0000ff;">$uid</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$gid</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$vhostInfo</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'docRoot'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
    informOut<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Creating log dir: $vhostInfo{'logsDir'}&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    mkpath<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$vhostInfo</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'logsDir'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
    informOut<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Site File: $vhostInfo{'apacheConfig'}&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$vhostContent</span> <span style="color: #339933;">=</span> <span style="color: #cc0000; font-style: italic;">&lt;&lt; &quot;EOF&quot;;
&lt;VirtualHost *:80&gt;
    ServerName $vhost
    DocumentRoot $vhostInfo{'docRoot'}
    &lt;directory $vhostInfo{'docRoot'}&gt;
        Options Indexes FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
    &lt;/directory&gt;
        ErrorLog $vhostInfo{'logsDir'}/error_log
        CustomLog $vhostInfo{'logsDir'}/access_log &quot;%h %l %u %t \\&quot;%r\\&quot; %&gt;s %b \\&quot;%{Referer}i\\&quot; \\&quot;%{User-agent}i\\&quot;&quot;
        LogLevel debug
&nbsp;
&nbsp;
EOF</span>
    informOut<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Creating Vhost...&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">open</span> FILE<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;&gt;&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$vhostInfo</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'apacheConfig'</span><span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">or</span> <span style="color: #000066;">die</span> <span style="color: #0000ff;">$!</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">print</span> FILE <span style="color: #0000ff;">$vhostContent</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">close</span> FILE<span style="color: #339933;">;</span>
&nbsp;
    informOut<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Adding host $vhost&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">open</span> FILE<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;&gt;&gt;&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'/etc/hosts'</span> <span style="color: #b1b100;">or</span> <span style="color: #000066;">die</span> <span style="color: #0000ff;">$!</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">print</span> FILE <span style="color: #0000ff;">$ipAddress</span> <span style="color: #339933;">.</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span><span style="color: #339933;">.</span> <span style="color: #0000ff;">$vhost</span> <span style="color: #339933;">.</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">close</span> FILE<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$output</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">`/usr/sbin/a2ensite $vhost`</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">print</span> <span style="color: #0000ff;">$output</span><span style="color: #339933;">;</span>
&nbsp;
    restartApache<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">#print $vhostConten t;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> restartApache
<span style="color: #009900;">&#123;</span>
    informOut<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Restarting apache&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$output</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">`/etc/init.d/apache2 restart`</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">print</span> <span style="color: #0000ff;">$output</span><span style="color: #339933;">;</span> 
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> deleteVhost
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$vhost</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;">%vhostInfo</span> <span style="color: #339933;">=</span> returnVhostPaths<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$vhost</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    informOut<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Removing $vhost from hosts file&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">open</span> IN<span style="color: #339933;">,</span> <span style="color: #ff0000;">'&lt; '</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'/etc/hosts'</span> <span style="color: #b1b100;">or</span> <span style="color: #000066;">die</span> <span style="color: #0000ff;">$!</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@hostsFile</span> <span style="color: #339933;">=</span> <span style="color: #009999;">&lt;IN&gt;</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">close</span> IN<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@contents</span> <span style="color: #339933;">=</span> <span style="color: #000066;">grep</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!/^</span>127<span style="color: #339933;">.</span>0<span style="color: #339933;">.</span>0<span style="color: #339933;">.</span>1<span style="color: #0000ff;">\t</span><span style="color: #0000ff;">$vhost</span><span style="color: #339933;">/,</span> <span style="color: #0000ff;">@hostsFile</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066;">open</span> FILE<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;&gt;&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'/etc/hosts'</span> <span style="color: #b1b100;">or</span> <span style="color: #000066;">die</span> <span style="color: #0000ff;">$!</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">print</span> FILE <span style="color: #0000ff;">@contents</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">close</span> FILE<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$output</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">`/usr/sbin/a2dissite $vhost`</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">print</span> <span style="color: #0000ff;">$output</span><span style="color: #339933;">;</span>
&nbsp;
    informOut<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Removing  $vhostInfo{'apacheConfig'} file&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">unlink</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$vhostInfo</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'apacheConfig'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    restartApache<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot; manually remove $vhostInfo{'docRoot'}... <span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> informOut <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$message</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;$message <span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://ivanvillareal.com/linux/perl-script-to-manage-virtual-hosts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ubuntu 9.10 on an hp mini 110-1125nr</title>
		<link>http://ivanvillareal.com/linux/ubuntu-9-10-on-an-hp-mini-110-1125nr/</link>
		<comments>http://ivanvillareal.com/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://ivanvillareal.com/?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, [...]]]></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://ivanvillareal.com/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://ivanvillareal.com/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://ivanvillareal.com/linux/mount-a-remote-filesystem-using-sshfs/</link>
		<comments>http://ivanvillareal.com/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://ivanvillareal.com/?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 [...]]]></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>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Symbol: FUSE_FS [=m]
Location:
  -&gt; File systems
      -&gt; Filesystem in Userspace support</pre></div></div>

<p>and after this was ready I only installed sys-fs/sshfs-fuse</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><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.</pre></div></div>

<p>when it was ready I did the following to mount the remote filesystem:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">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></pre></div></div>

<p>After this I&#8217;m able to use the remote file system as usual.</p>
]]></content:encoded>
			<wfw:commentRss>http://ivanvillareal.com/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://ivanvillareal.com/linux/mysql5-and-php5-on-centos4/</link>
		<comments>http://ivanvillareal.com/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://ivanvillareal.com/?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 [...]]]></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:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><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></pre></div></div>

<p>Then make an update:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">yum update</pre></div></div>

<p>After 496 package updates I&#8217;ve installed php5</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">yum <span style="color: #660033;">--enablerepo</span>=centosplus <span style="color: #c20cb9; font-weight: bold;">install</span> php</pre></div></div>

<p>This were the installed packages:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">php-5.1.6-<span style="color: #000000;">3</span>.el4s1.10
php-cli-5.1.6-<span style="color: #000000;">3</span>.el4s1.10
php-common-5.1.6-<span style="color: #000000;">3</span>.el4s1.10</pre></div></div>

<p>So I&#8217;ve created a info.php file, and restarted the apache server:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><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</pre></div></div>

<p>It was working correctly, so the next thing was to have mysql 5 in it, so I did:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">yum <span style="color: #660033;">--enablerepo</span>=centosplus <span style="color: #c20cb9; font-weight: bold;">install</span> mysql-server</pre></div></div>

<p>I got some problems here, first I got this:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">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-<span style="color: #000000;">1</span>.el4_6 conflicts with <span style="color: #c20cb9; font-weight: bold;">file</span> from package mysql-4.1.22-<span style="color: #000000;">2</span>.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-<span style="color: #000000;">1</span>.el4_6 conflicts with <span style="color: #c20cb9; font-weight: bold;">file</span> from package mysql-4.1.22-<span style="color: #000000;">2</span>.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-<span style="color: #000000;">1</span>.el4_6 conflicts with <span style="color: #c20cb9; font-weight: bold;">file</span> from package mysql-4.1.22-<span style="color: #000000;">2</span>.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-<span style="color: #000000;">1</span>.el4_6 conflicts with <span style="color: #c20cb9; font-weight: bold;">file</span> from package mysql-4.1.22-<span style="color: #000000;">2</span>.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-<span style="color: #000000;">1</span>.el4_6 conflicts with <span style="color: #c20cb9; font-weight: bold;">file</span> from package mysql-4.1.22-<span style="color: #000000;">2</span>.el4</pre></div></div>

<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</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">yum <span style="color: #660033;">--enablerepo</span>=centosplus <span style="color: #c20cb9; font-weight: bold;">install</span> mysql.x86_64 mysql-server</pre></div></div>

<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:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">InnoDB: Creating foreign key constraint system tables
InnoDB: Foreign key constraint system tables created
091012 <span style="color: #000000;">11</span>:01:<span style="color: #000000;">18</span>  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</pre></div></div>

<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:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><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</span></pre></div></div>

<p>After the server was up, I changed the root password and added a new user:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><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></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;">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> <span style="color: #008080;">5</span>
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> <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> <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 <span style="color: #008080;">0</span> MAX_CONNECTIONS_PER_HOUR <span style="color: #008080;">0</span> MAX_UPDATES_PER_HOUR <span style="color: #008080;">0</span> MAX_USER_CONNECTIONS <span style="color: #008080;">0</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> <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> <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> <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> <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> 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</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://ivanvillareal.com/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://ivanvillareal.com/linux/removing-hybrid-feature-of-an-acomdata-drive/</link>
		<comments>http://ivanvillareal.com/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://ivanvillareal.com/?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 [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://ivanvillareal.com/wp-content/uploads/2009/10/AcomdataDrive.jpg"><br />
<img class="size-full wp-image-51 alignleft" title="Acomdata Drive" src="http://ivanvillareal.com/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™ 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 messages and I started to worry, It showed as a CD drive instead of a Mass Storage Device, I tried unsuccessfully to mount this manually, so I thought 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 thought 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 useful, 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 Linux, however this still had a problem, because I was using ivman to detect the drive and mounted, ivman  didn&#8217;t worked for hard drive partition, just for the virtual CD, I&#8217;ve tried unsuccessfully 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 without the cd part, I did this, and the format was 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 unmounted the CD part and mount the hard drive partition, it took me about a week to have this thing working the way I wanted,  this was  unbelievable, 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 to the office, and as soon as I plugged in the CD partition appeared on my Desktop, so I thought 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  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.</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  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> 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://ivanvillareal.com/wp-content/uploads/2009/10/MP251MFG_Interface.png"><img class="size-full wp-image-57 aligncenter" title="MP251MFG.exe Interface" src="http://ivanvillareal.com/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 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://ivanvillareal.com/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></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://ivanvillareal.com/linux/removing-hybrid-feature-of-an-acomdata-drive/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Setting up ssh keys for passwordless login</title>
		<link>http://ivanvillareal.com/linux/setting-up-ssh-keys-for-passwordless-login/</link>
		<comments>http://ivanvillareal.com/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://ivanvillareal.com/?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 [...]]]></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.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gondor .ssh <span style="color: #666666; font-style: italic;"># cd ~/.ssh</span>
gondor .ssh ~ <span style="color: #c20cb9; font-weight: bold;">ssh-keygen</span>
Generating public<span style="color: #000000; font-weight: bold;">/</span>private rsa key pair.
Enter <span style="color: #c20cb9; font-weight: bold;">file</span> <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #c20cb9; font-weight: bold;">which</span> to save the key <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span>id_rsa<span style="color: #7a0874; font-weight: bold;">&#41;</span>:
Enter passphrase <span style="color: #7a0874; font-weight: bold;">&#40;</span>empty <span style="color: #000000; font-weight: bold;">for</span> no passphrase<span style="color: #7a0874; font-weight: bold;">&#41;</span>:
Enter same passphrase again:
Your identification has been saved <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span>id_rsa.
Your public key has been saved <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span>id_rsa.pub.
The key fingerprint is:
<span style="color: #000000;">53</span>:<span style="color: #c20cb9; font-weight: bold;">df</span>:bb:<span style="color: #000000;">74</span>:<span style="color: #000000;">24</span>:2d:7f:<span style="color: #000000;">78</span>:1f:<span style="color: #000000;">85</span>:<span style="color: #000000;">66</span>:f0:<span style="color: #000000;">19</span>:b6:9f:<span style="color: #000000;">71</span> root<span style="color: #000000; font-weight: bold;">@</span>gondor
The key<span style="color: #ff0000;">'s randomart image is:
+--[ RSA 2048]----+
|                 |
|                 |
|          . . o  |
|         . . = * |
|        S   . @.E|
|         .   o O=|
|              +o*|
|             . ++|
|              . .|
+-----------------+</span></pre></div></div>

<p>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</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gondor .ssh <span style="color: #666666; font-style: italic;"># ssh-copy-id -i id_rsa.pub ivan@odin</span>
The authenticity of host <span style="color: #ff0000;">'odin (192.168.1.201)'</span> can<span style="color: #ff0000;">'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 '</span>odin,192.168.1.201<span style="color: #ff0000;">' (RSA) to the list of known hosts.
Password:</span></pre></div></div>

<p>Now try logging into the machine, with &#8220;ssh &#8216;ivan@odin&#8217;&#8221;, and check in:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">  .ssh<span style="color: #000000; font-weight: bold;">/</span>authorized_keys</pre></div></div>

<p>to make sure we haven&#8217;t added extra keys that you weren&#8217;t expecting.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gondor .ssh <span style="color: #666666; font-style: italic;"># ssh ivan@odin</span>
Last <span style="color: #c20cb9; font-weight: bold;">login</span>: Fri Sep <span style="color: #000000;">25</span> <span style="color: #000000;">15</span>:<span style="color: #000000;">50</span>:03 PDT <span style="color: #000000;">2009</span> from gondor.artedigital on <span style="color: #c20cb9; font-weight: bold;">ssh</span>
Last <span style="color: #c20cb9; font-weight: bold;">login</span>: Fri Sep <span style="color: #000000;">25</span> <span style="color: #000000;">15</span>:<span style="color: #000000;">50</span>:07 <span style="color: #000000;">2009</span> from gondor.artedigital
ivan<span style="color: #000000; font-weight: bold;">@</span>odin ~ $</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://ivanvillareal.com/linux/setting-up-ssh-keys-for-passwordless-login/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automated Capture of Webpages (Main Process)</title>
		<link>http://ivanvillareal.com/linux/automated-capture-of-webpages-main-process/</link>
		<comments>http://ivanvillareal.com/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://ivanvillareal.com/?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 [...]]]></description>
			<content:encoded><![CDATA[<p>This post is the continuation of &nbsp;<strong><a title="Xvfb and Firefox headless screenshot generator" href="http://ivanvillareal.com/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://ivanvillareal.com/wp-content/uploads/2009/09/screen_grabber_system_arquitechture1.png"><img class="size-large wp-image-28 " title="Screen Grabber System Arquitechture" src="http://ivanvillareal.com/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>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><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> <span style="color: #cc66cc;">1</span><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> <span style="color: #cc66cc;">1</span><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><span style="color: #cc66cc;">0</span><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> <span style="color: #cc66cc;">2</span><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><span style="color: #cc66cc;">2</span><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><span style="color: #cc66cc;">1</span><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><span style="color: #cc66cc;">3</span><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><span style="color: #cc66cc;">1</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;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><span style="color: #cc66cc;">3</span><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><span style="color: #cc66cc;">3</span><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><span style="color: #cc66cc;">3</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: #cc66cc;">1</span><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><span style="color: #cc66cc;">1</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: #cc66cc;">5</span><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><span style="color: #cc66cc;">4</span><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></pre></div></div>

<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>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><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><span style="color: #cc66cc;">4</span><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><span style="color: #cc66cc;">1</span><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><span style="color: #339933;">&lt;/</span>file<span style="color: #339933;">&gt;</span></pre></div></div>

<p>And the captureSite sub is where the magic is, here it is:</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><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><span style="color: #cc66cc;">2</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;"># 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><span style="color: #cc66cc;">0</span><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><span style="color: #cc66cc;">1</span><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><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000066;">kill</span> <span style="color: #cc66cc;">0</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>
            <span style="color: #000066;">sleep</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><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><span style="color: #cc66cc;">1</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: #cc66cc;">3</span><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><span style="color: #cc66cc;">1</span><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><span style="color: #cc66cc;">1</span><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> <span style="color: #cc66cc;">3</span><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><span style="color: #cc66cc;">3</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>
<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><span style="color: #cc66cc;">0</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><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> <span style="color: #cc66cc;">0</span><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><span style="color: #cc66cc;">1</span><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><span style="color: #cc66cc;">1</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: #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> <span style="color: #cc66cc;">3</span><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><span style="color: #cc66cc;">1</span><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><span style="color: #cc66cc;">1</span><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: #339933;">=</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><span style="color: #cc66cc;">2</span><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><span style="color: #cc66cc;">2</span><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> <span style="color: #cc66cc;">3</span><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><span style="color: #cc66cc;">1</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;">$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> <span style="color: #cc66cc;">3</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;">'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><span style="color: #cc66cc;">1</span><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><span style="color: #cc66cc;">1</span><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><span style="color: #cc66cc;">1</span><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></pre></div></div>

<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://ivanvillareal.com/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://ivanvillareal.com/linux/xvfb-and-firefox-headles-screenshot-generator/</link>
		<comments>http://ivanvillareal.com/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://ivanvillareal.com/?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 [...]]]></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://ivanvillareal.com/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>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ivano ~ <span style="color: #666666; font-style: italic;"># apt-get install xvfb xfonts-base xfonts-75dpi xfonts-100dpi firefox</span></pre></div></div>

<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 1280x1024x12.</p></blockquote>
<p>So I did:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">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></pre></div></div>

<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>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ivano ~ <span style="color: #666666; font-style: italic;"># DISPLAY=:1 firefox http://google.com &amp;</span></pre></div></div>

<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>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ivano ~ <span style="color: #666666; font-style: italic;"># DISPLAY=:1 import -window root google.com.png</span></pre></div></div>

<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://ivanvillareal.com/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://ivanvillareal.com/linux/xvfb-and-firefox-headles-screenshot-generator/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

