<?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>mikerochford.com &#187; mrochford</title>
	<atom:link href="http://mikerochford.com/blog/author/mrochford/feed/" rel="self" type="application/rss+xml" />
	<link>http://mikerochford.com/blog</link>
	<description>Being technical</description>
	<lastBuildDate>Thu, 16 Jun 2011 19:02:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2</generator>
		<item>
		<title>Filesystem backups</title>
		<link>http://mikerochford.com/blog/2011/06/16/filesystem-backups/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://mikerochford.com/blog/2011/06/16/filesystem-backups/#comments</comments>
		<pubDate>Thu, 16 Jun 2011 19:02:59 +0000</pubDate>
		<dc:creator>mrochford</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mikerochford.com/blog/?p=157</guid>
		<description><![CDATA[I always deal with friend and family's computers. They are always full of viruses and mail-ware. All they care is "Backup my music and pictures." Well I got tired of always trying to search and finding these files on there disk. So I wrote a quick little python script to gather all the files I [...]]]></description>
			<content:encoded><![CDATA[<p>I always deal with friend and family's computers. They are always full of viruses and mail-ware. All they care is "Backup my music and pictures."  Well I got tired of always trying to search and finding these files on there disk. So I wrote a quick little python script to gather all the files I want based on the file extension.  Please see the script below and let me know what you think. </p>
<p><a href="http://mikerochford.com/code/python/filefinder.py">filefind.py</a></p>
<img src="http://mikerochford.com/blog/?ak_action=api_record_view&id=157&type=feed" alt="" /><p class='fb-like'><iframe src='http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fmikerochford.com%2Fblog%2F2011%2F06%2F16%2Ffilesystem-backups%2F&amp;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=65&amp;font=lucida+grande' scrolling='no' frameborder='0' allowTransparency='true' style='border:none; overflow:hidden; width:450px; height:65px'></iframe></p>]]></content:encoded>
			<wfw:commentRss>http://mikerochford.com/blog/2011/06/16/filesystem-backups/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Find all the perl modules in your script and make sure they are installed</title>
		<link>http://mikerochford.com/blog/2011/03/29/find-all-the-perl-modules-in-your-script-and-make-sure-they-are-installed/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://mikerochford.com/blog/2011/03/29/find-all-the-perl-modules-in-your-script-and-make-sure-they-are-installed/#comments</comments>
		<pubDate>Wed, 30 Mar 2011 01:38:22 +0000</pubDate>
		<dc:creator>mrochford</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://mikerochford.com/blog/?p=150</guid>
		<description><![CDATA[Ever migrated code from one server to another and never remember if you captured all the modules that need to be installed? I have, its a pain in the ass sometimes. So I thought I would throw together a little script to check if I have all the modules I used installed. I have written [...]]]></description>
			<content:encoded><![CDATA[<p>Ever migrated code from one server to another and never remember if you captured all the modules that need to be installed? I have, its a pain in the ass sometimes. So I thought I would throw together a little script to check if I have all the modules I used installed. I have written it in python and perl (Dont ask!)</p>
<p><strong>Versions</strong>:</p>
<ul>
<li><a title="Perl Version" href="http://mikerochford.com/code/perl/perl_module_check.pl" target="_blank">Perl</a></li>
<li><a title="Python Version" href="http://mikerochford.com/code/python/perl_module_check.py" target="_blank">Python</a></li>
</ul>
<p><strong>Example:</strong><br />
<code><br />
mrochford@mrochford-linux:~/bin$ ./perl_module_check.pl simpleMenu.pl<br />
Found 5 modules in simpleMenu.pl<br />
Testing Config: OK<br />
Testing Data::Dumper: OK<br />
Testing FindBin: OK<br />
Testing Strings::IO: NOT INSTALLED<br />
Testing strict: OK<br />
</code></p>
<img src="http://mikerochford.com/blog/?ak_action=api_record_view&id=150&type=feed" alt="" /><p class='fb-like'><iframe src='http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fmikerochford.com%2Fblog%2F2011%2F03%2F29%2Ffind-all-the-perl-modules-in-your-script-and-make-sure-they-are-installed%2F&amp;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=65&amp;font=lucida+grande' scrolling='no' frameborder='0' allowTransparency='true' style='border:none; overflow:hidden; width:450px; height:65px'></iframe></p>]]></content:encoded>
			<wfw:commentRss>http://mikerochford.com/blog/2011/03/29/find-all-the-perl-modules-in-your-script-and-make-sure-they-are-installed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing VMWare tools for Debian or Ubuntu</title>
		<link>http://mikerochford.com/blog/2011/03/13/installing-vmware-tools-for-debian-or-ubuntu/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://mikerochford.com/blog/2011/03/13/installing-vmware-tools-for-debian-or-ubuntu/#comments</comments>
		<pubDate>Sun, 13 Mar 2011 21:10:50 +0000</pubDate>
		<dc:creator>mrochford</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[VMWare]]></category>

		<guid isPermaLink="false">http://mikerochford.com/blog/?p=146</guid>
		<description><![CDATA[Packages that are required to install VMWare Tools in debian or ubuntu apt-get install make gcc linux-headers-$(uname -r)]]></description>
			<content:encoded><![CDATA[<p>Packages that are required to install VMWare Tools in debian or ubuntu</p>
<p><code><br />
apt-get install make gcc linux-headers-$(uname -r)<br />
</code></p>
<img src="http://mikerochford.com/blog/?ak_action=api_record_view&id=146&type=feed" alt="" /><p class='fb-like'><iframe src='http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fmikerochford.com%2Fblog%2F2011%2F03%2F13%2Finstalling-vmware-tools-for-debian-or-ubuntu%2F&amp;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=65&amp;font=lucida+grande' scrolling='no' frameborder='0' allowTransparency='true' style='border:none; overflow:hidden; width:450px; height:65px'></iframe></p>]]></content:encoded>
			<wfw:commentRss>http://mikerochford.com/blog/2011/03/13/installing-vmware-tools-for-debian-or-ubuntu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Verifying your Linux Distro is 64bit.</title>
		<link>http://mikerochford.com/blog/2011/01/20/verifying-your-linux-distro-is-64bit/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://mikerochford.com/blog/2011/01/20/verifying-your-linux-distro-is-64bit/#comments</comments>
		<pubDate>Thu, 20 Jan 2011 13:32:08 +0000</pubDate>
		<dc:creator>mrochford</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[One Liner]]></category>

		<guid isPermaLink="false">http://mikerochford.com/blog/?p=117</guid>
		<description><![CDATA[I ran into a situation that I had to verify that I was running a 64bit os. Below is a quick command line check. It checks based on the current kernel loaded. mrochford@host1:~$ fgrep CONFIG_64BIT /boot/config-`uname -r` CONFIG_64BIT=y mrochford@host1:~$]]></description>
			<content:encoded><![CDATA[<p>I ran into a situation that I had to verify that I was running a 64bit os. Below is a quick command line check. It checks based on the current kernel loaded. </p>
<p><code><br />
mrochford@host1:~$ fgrep CONFIG_64BIT /boot/config-`uname -r`<br />
CONFIG_64BIT=y<br />
mrochford@host1:~$<br />
</code></p>
<img src="http://mikerochford.com/blog/?ak_action=api_record_view&id=117&type=feed" alt="" /><p class='fb-like'><iframe src='http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fmikerochford.com%2Fblog%2F2011%2F01%2F20%2Fverifying-your-linux-distro-is-64bit%2F&amp;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=65&amp;font=lucida+grande' scrolling='no' frameborder='0' allowTransparency='true' style='border:none; overflow:hidden; width:450px; height:65px'></iframe></p>]]></content:encoded>
			<wfw:commentRss>http://mikerochford.com/blog/2011/01/20/verifying-your-linux-distro-is-64bit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Run a command randomly</title>
		<link>http://mikerochford.com/blog/2010/09/22/run-a-command-randomly/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://mikerochford.com/blog/2010/09/22/run-a-command-randomly/#comments</comments>
		<pubDate>Wed, 22 Sep 2010 18:58:11 +0000</pubDate>
		<dc:creator>mrochford</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[One Liner]]></category>

		<guid isPermaLink="false">http://mikerochford.com/blog/?p=110</guid>
		<description><![CDATA[I wanted to run a command randomly everyday. Here is a one liner cron that I created. echo "" &#124; at now + `awk -vu=30 'BEGIN { srand(); printf( "%0.0f\n", rand() * u ); }'` minutes]]></description>
			<content:encoded><![CDATA[<p>I wanted to run a command randomly everyday. Here is a one liner cron that I created. </p>
<p><code><br />
echo "<what you want to run randomly>" | at now + `awk -vu=30 'BEGIN { srand(); printf( "%0.0f\n", rand() * u ); }'` minutes<br />
</code></p>
<img src="http://mikerochford.com/blog/?ak_action=api_record_view&id=110&type=feed" alt="" /><p class='fb-like'><iframe src='http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fmikerochford.com%2Fblog%2F2010%2F09%2F22%2Frun-a-command-randomly%2F&amp;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=65&amp;font=lucida+grande' scrolling='no' frameborder='0' allowTransparency='true' style='border:none; overflow:hidden; width:450px; height:65px'></iframe></p>]]></content:encoded>
			<wfw:commentRss>http://mikerochford.com/blog/2010/09/22/run-a-command-randomly/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Moving a directory from one host to another using tar over ssh</title>
		<link>http://mikerochford.com/blog/2009/11/18/moving-a-directory-from-one-host-to-another-using-tar-over-ssh/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://mikerochford.com/blog/2009/11/18/moving-a-directory-from-one-host-to-another-using-tar-over-ssh/#comments</comments>
		<pubDate>Wed, 18 Nov 2009 17:28:00 +0000</pubDate>
		<dc:creator>mrochford</dc:creator>
				<category><![CDATA[One Liner]]></category>

		<guid isPermaLink="false">http://mikerochford.com/blog/?p=101</guid>
		<description><![CDATA[tar cf - * &#124; ssh]]></description>
			<content:encoded><![CDATA[<p><code lang="bash">tar cf - * | ssh <username@<hostname> "(cd <destination_dir> &#038;& tar xf -)"</code></p>
<img src="http://mikerochford.com/blog/?ak_action=api_record_view&id=101&type=feed" alt="" /><p class='fb-like'><iframe src='http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fmikerochford.com%2Fblog%2F2009%2F11%2F18%2Fmoving-a-directory-from-one-host-to-another-using-tar-over-ssh%2F&amp;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=65&amp;font=lucida+grande' scrolling='no' frameborder='0' allowTransparency='true' style='border:none; overflow:hidden; width:450px; height:65px'></iframe></p>]]></content:encoded>
			<wfw:commentRss>http://mikerochford.com/blog/2009/11/18/moving-a-directory-from-one-host-to-another-using-tar-over-ssh/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Naigos Plugin: Check for packages to update in Debian/Ubuntu</title>
		<link>http://mikerochford.com/blog/2009/11/05/naigos-plugin-check-for-packages-to-update-in-debianubuntu/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://mikerochford.com/blog/2009/11/05/naigos-plugin-check-for-packages-to-update-in-debianubuntu/#comments</comments>
		<pubDate>Fri, 06 Nov 2009 04:13:47 +0000</pubDate>
		<dc:creator>mrochford</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Nagios]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://mikerochford.com/blog/?p=97</guid>
		<description><![CDATA[Over the years I have manages a lot of systems, mostly debian based. The thing I really hate about having a lot of standalone systems is updating software. I am really bad at keeping track of new updates and I really dont want to have a cron script running to send me a email every [...]]]></description>
			<content:encoded><![CDATA[<p>Over the years I have manages a lot of systems, mostly debian based. The thing I really hate about having a lot of standalone systems is updating software. I am really bad at keeping track of new updates and I really dont want to have a cron script running to send me a email every day. Below is a script I used as a plugin for nagios. </p>
<p>The Script: <a href="http://mikerochford.com/code/perl/check_for_updates.pl">check_for_updates.pl</a></p>
<img src="http://mikerochford.com/blog/?ak_action=api_record_view&id=97&type=feed" alt="" /><p class='fb-like'><iframe src='http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fmikerochford.com%2Fblog%2F2009%2F11%2F05%2Fnaigos-plugin-check-for-packages-to-update-in-debianubuntu%2F&amp;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=65&amp;font=lucida+grande' scrolling='no' frameborder='0' allowTransparency='true' style='border:none; overflow:hidden; width:450px; height:65px'></iframe></p>]]></content:encoded>
			<wfw:commentRss>http://mikerochford.com/blog/2009/11/05/naigos-plugin-check-for-packages-to-update-in-debianubuntu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Backup of your MYSQL server using mysqldump</title>
		<link>http://mikerochford.com/blog/2009/10/22/backup-of-your-mysql-server-using-mysqldump/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://mikerochford.com/blog/2009/10/22/backup-of-your-mysql-server-using-mysqldump/#comments</comments>
		<pubDate>Thu, 22 Oct 2009 15:25:51 +0000</pubDate>
		<dc:creator>mrochford</dc:creator>
				<category><![CDATA[Mysql]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://mikerochford.com/blog/?p=85</guid>
		<description><![CDATA[Over the years of being a admin I have seen many ideas on how to backup a mysql database server. Many people are satisfied with with one large dump of all databases into one flat text file. Others think copy the actual db files to other locations are the way to back things up. I [...]]]></description>
			<content:encoded><![CDATA[<p>Over the years of being a admin I have seen many ideas on how to backup a mysql database server. Many people are satisfied with with one large dump of all databases into one flat text file. Others think copy the actual db files to other locations are the way to back things up. I have found dealing with customer and internal databases you need incremental backups. With all that said I developed a perl script that will log in grab all existing database names and do a mysqldump of each database. It will also keep a specified amount of backups and you also can choose to have some logs gzip'ed or left uncompressed. Below is the link to the code. You will have update login credentials and the ip address of the mysql server. </p>
<p>Link: <a href="http://mikerochford.com/code/perl/mysql_backup.pl">mysql_backup.pl</a></p>
<p>Explanation of the script: </p>
<p>The script will login to your mysql server and issue a "show databases;". Once it the database names are retrieved it will run a mysqldump on each database and store the output in the specified directory. The name scheme of the out will be database_name-YYYYMMDD.sql. Doing this it will allow you to sort based on date. Once all mysqldumps have completed it will go through each database directory and audit what should be saved, deleted, gzipped or leave alone. You will be able to chose what the numbers of day you want to retain and the how many days you want to leave as a uncompressed file.</p>
<img src="http://mikerochford.com/blog/?ak_action=api_record_view&id=85&type=feed" alt="" /><p class='fb-like'><iframe src='http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fmikerochford.com%2Fblog%2F2009%2F10%2F22%2Fbackup-of-your-mysql-server-using-mysqldump%2F&amp;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=65&amp;font=lucida+grande' scrolling='no' frameborder='0' allowTransparency='true' style='border:none; overflow:hidden; width:450px; height:65px'></iframe></p>]]></content:encoded>
			<wfw:commentRss>http://mikerochford.com/blog/2009/10/22/backup-of-your-mysql-server-using-mysqldump/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Changing the I/O timeout on your SCSI disk</title>
		<link>http://mikerochford.com/blog/2009/07/23/changing-the-io-timeout-on-your-scsi-disk/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://mikerochford.com/blog/2009/07/23/changing-the-io-timeout-on-your-scsi-disk/#comments</comments>
		<pubDate>Thu, 23 Jul 2009 23:52:15 +0000</pubDate>
		<dc:creator>mrochford</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[VMWare]]></category>

		<guid isPermaLink="false">http://mikerochford.com/blog/?p=77</guid>
		<description><![CDATA[Changing your I/O timeout for your SCSI disks are rare. When you are running VMWare that houses the guest OS on a NFS/SAN mount you need to change the timeout. If you dont you will run into a mess with your guest OS. You will try running a snapshot and browsing your file system and [...]]]></description>
			<content:encoded><![CDATA[<p>Changing your I/O timeout for your SCSI disks are rare. When you are running  VMWare that houses the guest OS on a NFS/SAN mount you need to change the timeout. If you dont you will run into a mess with your guest OS. You will try running a snapshot and browsing your file system and bam its locks up. Below is what you need to change in your udev rules to change it. </p>
<p>Location: /etc/udev/rules.d/50-udev-default.rules</p>
<p><code txt><br />
SUBSYSTEM=="scsi" , SYSFS{type}=="0|7|14", RUN+="/bin/sh -c 'echo 60 > /sys/block/sda/device/timeout'"<br />
SUBSYSTEM=="scsi" , SYSFS{type}=="0|7|14", RUN+="/bin/sh -c 'echo 190 > /sys/block/sda/device/timeout'"<br />
SUBSYSTEM=="scsi" , SYSFS{type}=="1", RUN+="/bin/sh -c 'echo 900 > /sys/block/sda/device/timeout'"<br />
</code></p>
<img src="http://mikerochford.com/blog/?ak_action=api_record_view&id=77&type=feed" alt="" /><p class='fb-like'><iframe src='http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fmikerochford.com%2Fblog%2F2009%2F07%2F23%2Fchanging-the-io-timeout-on-your-scsi-disk%2F&amp;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=65&amp;font=lucida+grande' scrolling='no' frameborder='0' allowTransparency='true' style='border:none; overflow:hidden; width:450px; height:65px'></iframe></p>]]></content:encoded>
			<wfw:commentRss>http://mikerochford.com/blog/2009/07/23/changing-the-io-timeout-on-your-scsi-disk/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Connecting to a machine using sockets</title>
		<link>http://mikerochford.com/blog/2009/05/27/connecting-to-a-machine-using-sockets/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://mikerochford.com/blog/2009/05/27/connecting-to-a-machine-using-sockets/#comments</comments>
		<pubDate>Wed, 27 May 2009 12:43:37 +0000</pubDate>
		<dc:creator>mrochford</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://mikerochford.com/blog/?p=70</guid>
		<description><![CDATA[I work with a api system that connects on a high port. My co-work Matt came up with a great way to set the socket up and verify if the socket isn't stale. This sub-routine is specific to the api but you can use the theory and apply it to pretty much your socket needs. [...]]]></description>
			<content:encoded><![CDATA[<p>I work with a api system that connects on a high port. My co-work <a href="http://www.popmartian.com/tipsntricks/" target="_blank">Matt</a> came up with a great way to set the socket up and verify if the socket isn't stale. This sub-routine is specific to the api but you can use the theory and apply it to pretty much your socket needs.</p>
<div class="dean_ch" style="white-space: wrap;">
<span class="kw2">sub</span> cp_connect <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp;<span class="co1">###############</span><br />
&nbsp; &nbsp; &nbsp;<span class="co1">#</span><br />
&nbsp; &nbsp; &nbsp;<span class="co1"># This function connects to a cp server</span><br />
&nbsp; &nbsp; &nbsp;<span class="co1">#</span><br />
&nbsp; &nbsp; &nbsp;<span class="co1"># Accepts:</span><br />
&nbsp; &nbsp; &nbsp;<span class="co1"># $remote_host The server to connect to</span><br />
&nbsp; &nbsp; &nbsp;<span class="co1"># $remote_port The port to connect to</span><br />
&nbsp; &nbsp; &nbsp;<span class="co1">#</span><br />
&nbsp; &nbsp; &nbsp;<span class="co1"># Returns:</span><br />
&nbsp; &nbsp; &nbsp;<span class="co1"># A critical Path mail server socket connection.</span><br />
&nbsp; &nbsp; &nbsp;<span class="co1">#</span><br />
&nbsp; &nbsp; &nbsp;<span class="co1">###############</span></p>
<p>&nbsp; &nbsp; &nbsp;<span class="kw1">my</span> <span class="re0">$remote_host</span> = <a href="http://perldoc.perl.org/functions/shift.html"><span class="kw3">shift</span></a>;<br />
&nbsp; &nbsp; &nbsp;<span class="kw1">my</span> <span class="re0">$remote_port</span> = <a href="http://perldoc.perl.org/functions/shift.html"><span class="kw3">shift</span></a>;<br />
&nbsp; &nbsp; &nbsp;<span class="kw1">my</span> <span class="re0">$remote_password</span> = <a href="http://perldoc.perl.org/functions/shift.html"><span class="kw3">shift</span></a>;<br />
&nbsp; &nbsp; &nbsp;<span class="kw1">my</span> <span class="re0">$remote_conneciton_type</span> = <a href="http://perldoc.perl.org/functions/shift.html"><span class="kw3">shift</span></a>;<br />
&nbsp; &nbsp; &nbsp;<span class="kw1">my</span> <span class="re0">$EOL</span> = <a href="http://perldoc.perl.org/functions/shift.html"><span class="kw3">shift</span></a>;</p>
<p>&nbsp; &nbsp; &nbsp;<span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$remote_conneciton_type</span> =~ <a href="http://perldoc.perl.org/functions/m.html"><span class="kw3">m</span></a>/^rw$/<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$remote_password</span> = <span class="re0">$remote_password</span> .<span class="st0">&quot; write&quot;</span>;<br />
&nbsp; &nbsp; &nbsp;<span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp;<span class="kw1">my</span> <span class="re0">$socket</span> = IO::<span class="me2">Socket</span>::<span class="me2">INET</span>-&gt;<span class="me1">new</span><span class="br0">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PeerAddr =&gt; <span class="re0">$remote_host</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PeerPort &nbsp; &nbsp; &nbsp; &nbsp;=&gt; <span class="re0">$remote_port</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Proto &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span class="st0">&quot;tcp&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Type &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;=&gt; SOCK_STREAM,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Timeout &nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span class="nu0">5</span> <span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; || <a href="http://perldoc.perl.org/functions/die.html"><span class="kw3">die</span></a> <span class="st0">&quot;Couldn't open socket!<span class="es0">\n</span><span class="es0">\n</span>&quot;</span>;</p>
<p>&nbsp; &nbsp; &nbsp;<span class="kw1">my</span> <span class="re0">$answer</span> = &lt;<span class="re0">$socket</span>&gt;;<br />
&nbsp; &nbsp; &nbsp;<a href="http://perldoc.perl.org/functions/print.html"><span class="kw3">print</span></a> <span class="re0">$socket</span> <span class="st0">&quot;LOGIN $remote_password&quot;</span> . <span class="re0">$EOL</span>;<br />
&nbsp; &nbsp; &nbsp;<span class="re0">$answer</span> = &lt;<span class="re0">$socket</span>&gt;;<br />
&nbsp; &nbsp; &nbsp;<span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$answer</span> !~ /^OK/<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://perldoc.perl.org/functions/print.html"><span class="kw3">print</span></a> <span class="st0">&quot;Failed to login to $remote_host : $remote_port : $answer<span class="es0">\n</span><span class="es0">\n</span>&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://perldoc.perl.org/functions/exit.html"><span class="kw3">exit</span></a><span class="br0">&#40;</span><span class="nu0">1</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp;<span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp;<a href="http://perldoc.perl.org/functions/return.html"><span class="kw3">return</span></a> <span class="re0">$socket</span>;<br />
<span class="br0">&#125;</span><br />
&nbsp;</div>
<p>Once you have the understanding of how the sub-routine works. Building a script that interacts with the api is a piece of cake. </p>
<p>Here is an example of how we use the sub-routine in a script. This example will check to see if the socket is defined, if not it will try to connect and define the socket. Once the socket is defined it will issue a command and read the socket. </p>
<div class="dean_ch" style="white-space: wrap;">
<span class="kw1">if</span><span class="br0">&#40;</span>!<a href="http://perldoc.perl.org/functions/defined.html"><span class="kw3">defined</span></a> <span class="re0">$socket</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="re0">$socket</span> = cp_connect<span class="br0">&#40;</span><span class="re0">$remote_host</span>, <span class="re0">$remote_port</span>, <span class="re0">$remote_rwpass</span>,<span class="st0">&quot;rw&quot;</span>,<span class="re0">$EOL</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span><br />
<a href="http://perldoc.perl.org/functions/print.html"><span class="kw3">print</span></a> <span class="re0">$socket</span> <span class="st0">&quot;DOMAIN ENUMERATE&quot;</span>. <span class="re0">$EOL</span>;<br />
<span class="kw1">while</span> <span class="br0">&#40;</span><a href="http://perldoc.perl.org/functions/defined.html"><span class="kw3">defined</span></a> <span class="br0">&#40;</span><a href="http://perldoc.perl.org/functions/chomp.html"><span class="kw3">chomp</span></a><span class="br0">&#40;</span><span class="re0">$answer</span> = &lt;<span class="re0">$socket</span>&gt;<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$answer</span> =~ /\*\<a href="http://perldoc.perl.org/functions/s.html"><span class="kw3">s</span></a>+<span class="br0">&#40;</span>.+<span class="br0">&#41;</span>\<a href="http://perldoc.perl.org/functions/s.html"><span class="kw3">s</span></a>/<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$domains</span><span class="br0">&#123;</span>$<span class="nu0">1</span><span class="br0">&#125;</span><span class="br0">&#123;</span><span class="st0">'users'</span><span class="br0">&#125;</span> = <span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="kw1">elsif</span><span class="br0">&#40;</span><span class="re0">$answer</span> =~ /^ERROR/<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$error</span> = <span class="re0">$answer</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://perldoc.perl.org/functions/return.html"><span class="kw3">return</span></a> <span class="nu0">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">last</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="kw1">elsif</span><span class="br0">&#40;</span><span class="re0">$answer</span> =~ /OK/<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://perldoc.perl.org/functions/return.html"><span class="kw3">return</span></a> <span class="nu0">1</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">last</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span><br />
&nbsp;</div>
<img src="http://mikerochford.com/blog/?ak_action=api_record_view&id=70&type=feed" alt="" /><p class='fb-like'><iframe src='http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fmikerochford.com%2Fblog%2F2009%2F05%2F27%2Fconnecting-to-a-machine-using-sockets%2F&amp;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=65&amp;font=lucida+grande' scrolling='no' frameborder='0' allowTransparency='true' style='border:none; overflow:hidden; width:450px; height:65px'></iframe></p>]]></content:encoded>
			<wfw:commentRss>http://mikerochford.com/blog/2009/05/27/connecting-to-a-machine-using-sockets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

