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

<channel>
	<title>The Penguinlinux.com Blog</title>
	<atom:link href="http://www.penguinlinux.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.penguinlinux.com/blog</link>
	<description>Linux and Open Source Software tips and hacks</description>
	<pubDate>Thu, 03 Dec 2009 18:44:04 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
	<language>en</language>
			<item>
		<title>HOW TO UPGRADE TO PHP 5.3 ON A CENTOS 5 DISTRO</title>
		<link>http://www.penguinlinux.com/blog/lamp/how-to-upgrade-to-php-53-on-a-centos-5-distro/</link>
		<comments>http://www.penguinlinux.com/blog/lamp/how-to-upgrade-to-php-53-on-a-centos-5-distro/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 18:36:35 +0000</pubDate>
		<dc:creator>tepezcuintle</dc:creator>
		
		<category><![CDATA[LAMP]]></category>

		<guid isPermaLink="false">http://www.penguinlinux.com/blog/?p=672</guid>
		<description><![CDATA[
HOW TO UPGRADE TO PHP 5.3 ON A CENTOS 5 DISTRO
I am trying to install cahoots a StackOverflow clone but I am running Centos 5 and by default
it comes with php 5.1.6 and I needed to install the Zend Framework.  If you tried to install the Zend
framework you will realize that you need PHP [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://gofedora.com/wp-content/uploads/2009/09/RedHat-CentOS-PHP.jpg" alt="Centos" /><br />
HOW TO UPGRADE TO PHP 5.3 ON A CENTOS 5 DISTRO</p>
<p>I am trying to install cahoots a StackOverflow clone but I am running Centos 5 and by default<br />
it comes with php 5.1.6 and I needed to install the Zend Framework.  If you tried to install the Zend<br />
framework you will realize that you need PHP 5.2 in order to use it.  </p>
<p>I know there are ways to install a new version of PHP on Centos 5, I would not recommend this steps<br />
on a production system at work because you will be using repos that are not supported by Redhat or Centos<br />
so if the maintainer of the repo decides to you are stuck with a version of PHP that is not maintained<br />
by anyone and if there are bugs or security risks you are stuck with a machine that is not supported anymore.<br />
<span id="more-672"></span></p>
<p>In my case this is my machine so I will install php 5.3 via the REMI repos</p>
<p>wget http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm<br />
wget http://rpms.famillecollet.com/enterprise/remi-release-5.rpm<br />
rpm -Uvh remi-release-5*.rpm epel-release-5*.rpm</p>
<p>Now upgrade php and mysql</p>
<p>yum &#8211;enablerepo=remi update php</p>
<p>you will see a bunch of rpm&#8217;s being dowloaded and then installed.  But you will see this error. </p>
<p>############ ERROR UPGRADING PHP 5.3 #################################################</p>
<p>Transaction Check Error:<br />
  file /etc/my.cnf from install of mysql-libs-5.1.41-1.el5.remi.i386 conflicts with file from package mysql-5.0.77-3.el5.i386<br />
  file /usr/share/mysql/charsets/Index.xml from install of mysql-libs-5.1.41-1.el5.remi.i386 conflicts with file from package mysql-5.0.77-3.el5.i386<br />
  file /usr/share/mysql/charsets/cp1250.xml from install of mysql-libs-5.1.41-1.el5.remi.i386 conflicts with file from package mysql-5.0.77-3.el5.i386<br />
  file /usr/share/mysql/czech/errmsg.sys from install of mysql-libs-5.1.41-1.el5.remi.i386 conflicts with file from package mysql-5.0.77-3.el5.i386<br />
  file /usr/share/mysql/danish/errmsg.sys from install of mysql-libs-5.1.41-1.el5.remi.i386 conflicts with file from package mysql-5.0.77-3.el5.i386<br />
  file /usr/share/mysql/dutch/errmsg.sys from install of mysql-libs-5.1.41-1.el5.remi.i386 conflicts with file from package mysql-5.0.77-3.el5.i386<br />
  file /usr/share/mysql/english/errmsg.sys from install of mysql-libs-5.1.41-1.el5.remi.i386 conflicts with file from package mysql-5.0.77-3.el5.i386<br />
  file /usr/share/mysql/estonian/errmsg.sys from install of mysql-libs-5.1.41-1.el5.remi.i386 conflicts with file from package mysql-5.0.77-3.el5.i386<br />
  file /usr/share/mysql/french/errmsg.sys from install of mysql-libs-5.1.41-1.el5.remi.i386 conflicts with file from package mysql-5.0.77-3.el5.i386<br />
  file /usr/share/mysql/german/errmsg.sys from install of mysql-libs-5.1.41-1.el5.remi.i386 conflicts with file from package mysql-5.0.77-3.el5.i386<br />
  file /usr/share/mysql/greek/errmsg.sys from install of mysql-libs-5.1.41-1.el5.remi.i386 conflicts with file from package mysql-5.0.77-3.el5.i386<br />
  file /usr/share/mysql/hungarian/errmsg.sys from install of mysql-libs-5.1.41-1.el5.remi.i386 conflicts with file from package mysql-5.0.77-3.el5.i386<br />
  file /usr/share/mysql/italian/errmsg.sys from install of mysql-libs-5.1.41-1.el5.remi.i386 conflicts with file from package mysql-5.0.77-3.el5.i386<br />
  file /usr/share/mysql/japanese/errmsg.sys from install of mysql-libs-5.1.41-1.el5.remi.i386 conflicts with file from package mysql-5.0.77-3.el5.i386<br />
  file /usr/share/mysql/korean/errmsg.sys from install of mysql-libs-5.1.41-1.el5.remi.i386 conflicts with file from package mysql-5.0.77-3.el5.i386<br />
  file /usr/share/mysql/norwegian-ny/errmsg.sys from install of mysql-libs-5.1.41-1.el5.remi.i386 conflicts with file from package mysql-5.0.77-3.el5.i386<br />
  file /usr/share/mysql/norwegian/errmsg.sys from install of mysql-libs-5.1.41-1.el5.remi.i386 conflicts with file from package mysql-5.0.77-3.el5.i386<br />
  file /usr/share/mysql/polish/errmsg.sys from install of mysql-libs-5.1.41-1.el5.remi.i386 conflicts with file from package mysql-5.0.77-3.el5.i386<br />
  file /usr/share/mysql/portuguese/errmsg.sys from install of mysql-libs-5.1.41-1.el5.remi.i386 conflicts with file from package mysql-5.0.77-3.el5.i386<br />
  file /usr/share/mysql/romanian/errmsg.sys from install of mysql-libs-5.1.41-1.el5.remi.i386 conflicts with file from package mysql-5.0.77-3.el5.i386<br />
  file /usr/share/mysql/russian/errmsg.sys from install of mysql-libs-5.1.41-1.el5.remi.i386 conflicts with file from package mysql-5.0.77-3.el5.i386<br />
  file /usr/share/mysql/serbian/errmsg.sys from install of mysql-libs-5.1.41-1.el5.remi.i386 conflicts with file from package mysql-5.0.77-3.el5.i386<br />
  file /usr/share/mysql/slovak/errmsg.sys from install of mysql-libs-5.1.41-1.el5.remi.i386 conflicts with file from package mysql-5.0.77-3.el5.i386<br />
  file /usr/share/mysql/spanish/errmsg.sys from install of mysql-libs-5.1.41-1.el5.remi.i386 conflicts with file from package mysql-5.0.77-3.el5.i386<br />
  file /usr/share/mysql/swedish/errmsg.sys from install of mysql-libs-5.1.41-1.el5.remi.i386 conflicts with file from package mysql-5.0.77-3.el5.i386<br />
  file /usr/share/mysql/ukrainian/errmsg.sys from install of mysql-libs-5.1.41-1.el5.remi.i386 conflicts with file from package mysql-5.0.77-3.el5.i386</p>
<p>######### HOW TO FIX THE ABOVE ERROR ##############################</p>
<p>Well that sucked right.  It seems some files are conflicting with my original install of MySQL the problem here is that<br />
I am updating PHP but I also needed to update my MySQL to work with php 5.3 so i did the following </p>
<p>[root@penguin-web1 ZendFramework-1.7.8]# yum &#8211;enablerepo=remi update mysql</p>
<p>Dependency Installed:<br />
  libXaw.i386 0:1.0.2-8.1                     libXmu.i386 0:1.0.2-5                 libedit.i386 0:2.11-2.20080712cvs.el5      mysql-libs.i386 0:5.1.41-1.el5.remi<br />
  mysqlclient15.i386 0:5.0.67-1.el5.remi      sqlite2.i386 0:2.8.17-2.el5.remi      t1lib.i386 0:5.1.1-7.el5                  </p>
<p>Updated:<br />
  mysql.i386 0:5.1.41-1.el5.remi                                                                                                                                         </p>
<p>Dependency Updated:<br />
  mysql-bench.i386 0:5.1.41-1.el5.remi        mysql-server.i386 0:5.1.41-1.el5.remi        php.i386 0:5.3.1-1.el5.remi            php-cli.i386 0:5.3.1-1.el5.remi<br />
  php-common.i386 0:5.3.1-1.el5.remi          php-devel.i386 0:5.3.1-1.el5.remi            php-gd.i386 0:5.3.1-1.el5.remi         php-ldap.i386 0:5.3.1-1.el5.remi<br />
  php-mbstring.i386 0:5.3.1-1.el5.remi        php-mysql.i386 0:5.3.1-1.el5.remi            php-pdo.i386 0:5.3.1-1.el5.remi        php-snmp.i386 0:5.3.1-1.el5.remi<br />
  php-xml.i386 0:5.3.1-1.el5.remi             php-xmlrpc.i386 0:5.3.1-1.el5.remi          </p>
<p>Complete!<br />
[root@penguin-web1 ZendFramework</p>
<p>################## VERIFY THAT PHP 5.3 HAS BEEN INSTALLED ##########################</p>
<p>[root@penguin-web1 ZendFramework-1.7.8]# php &#8211;version<br />
PHP 5.3.1 (cli) (built: Nov 20 2009 17:51:14)<br />
Copyright (c) 1997-2009 The PHP Group<br />
Zend Engine v2.3.0, Copyright (c) 1998-2009 Zend Technologies<br />
[root@penguin-web1 ZendFramework-1.7.8]# </p>
<p>Well this is great, now just reload the httpd server so it can use the new version of php</p>
<p>[root@penguin-web1 ZendFramework-1.7.8]# service httpd reload<br />
Reloading httpd:                                           [  OK  ]<br />
[root@penguin-web1 ZendFramework-1.7.8]# </p>
<p>##################### I SCREW UP MY SYSTEM I FUCKED UP AND NOW I AM STUCK WITH A BROKEN APPLICATION OR SYSTEM ##########</p>
<p>Yes what if you had an application that is not working anymore or even apache might not work in that case do this</p>
<p>yum –disablerepo=remi<br />
yum remove php php-cli php-common (It didn’t remove dependencies when uninstalling just php)</p>
<p>yum install php (Reverts back to PHP version in Red Hat’s repositories)</p>
<p>Then restart httpd</p>
<p>Well so those are the steps to upgrade your system to php 5.3 </p>
<p>Ciao my fellow Penguin readers</p>
]]></content:encoded>
			<wfw:commentRss>http://www.penguinlinux.com/blog/lamp/how-to-upgrade-to-php-53-on-a-centos-5-distro/feed/</wfw:commentRss>
		</item>
		<item>
		<title>MySQL Backup Table Schema Structure and Backup only Data</title>
		<link>http://www.penguinlinux.com/blog/databases/mysql-backup-table-schema-structure-and-backup-only-data/</link>
		<comments>http://www.penguinlinux.com/blog/databases/mysql-backup-table-schema-structure-and-backup-only-data/#comments</comments>
		<pubDate>Fri, 02 Oct 2009 16:50:39 +0000</pubDate>
		<dc:creator>tepezcuintle</dc:creator>
		
		<category><![CDATA[Databases]]></category>

		<guid isPermaLink="false">http://www.penguinlinux.com/blog/?p=670</guid>
		<description><![CDATA[
This is a reminder of how to backup the schema of a complete database
mysqldump &#8211;no-data -h localhost -u root -ppassword mydatabase > mydatabase_backup
This is if you want to only backup certain tables schema.
mysqldump &#8211;no-data -h localhost -u root -ppassword mydatabase table1 table2 > mydatabase_backup.sql

More info at 
http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html#option_mysqldump_no-data
http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html
Here is a cool shell script you can use [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.cyberciti.biz/tips/wp-content/uploads/2007/08/300px-mysql_proxy_sakila_switchboard.jpg" alt="Dolphin" /></p>
<p>This is a reminder of how to backup the schema of a complete database</p>
<p>mysqldump &#8211;no-data -h localhost -u root -ppassword mydatabase > mydatabase_backup</p>
<p>This is if you want to only backup certain tables schema.</p>
<p>mysqldump &#8211;no-data -h localhost -u root -ppassword mydatabase table1 table2 > mydatabase_backup.sql</p>
<p><span id="more-670"></span><br />
More info at </p>
<p>http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html#option_mysqldump_no-data</p>
<p>http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html</p>
<p>Here is a cool shell script you can use to backup shema and data only. </p>
<p>#! /bin/bash</p>
<p># backup-mysql.sh<br />
#<br />
# Craig Sanders &lt;cas@taz.net.au&gt;<br />
# this script is in the public domain.  do whatever you want with it.</p>
<p>MYUSER=&#8221;USERNAME&#8221;<br />
MYPWD=&#8221;PASSWD&#8221;</p>
<p>ARGS=&#8221;&#8211;single-transaction &#8211;flush-logs &#8211;complete-insert&#8221;</p>
<p>DATABASES=$( mysql -D mysql &#8211;skip-column-names -B -e &#8217;show databases;&#8217; | egrep -v &#8216;information_schema&#8217; );</p>
<p>BACKUPDIR=/var/backups/mysql</p>
<p>YEAR=$(date +&#8221;%Y&#8221;)<br />
MONTH=$(date +&#8221;%m&#8221;)<br />
DAY=$(date +&#8221;%d&#8221;)</p>
<p>DATE=&#8221;$YEAR-$MONTH/$YEAR-$MONTH-$DAY&#8221;</p>
<p>mkdir -p $BACKUPDIR/$DATE<br />
cd $BACKUPDIR/$DATE</p>
<p>for i in $DATABASES ; do<br />
  echo -n &#8220;backing up $i: schema&#8230;&#8221;<br />
  mysqldump $ARGS &#8211;no-data -u$MYUSER -p$MYPWD $i > $i.schema.sql</p>
<p>  echo -n &#8220;data&#8230;&#8221;<br />
  mysqldump $ARGS &#8211;skip-opt &#8211;no-create-db &#8211;no-create-info -u$MYUSER -p$MYPWD $i > $i.data.sql</p>
<p>  echo -n &#8220;compressing&#8230;&#8221;<br />
  gzip -9fq $i.schema.sql $i.data.sql<br />
  echo &#8220;done.&#8221;<br />
done</p>
<p># delete backup files older than 30 days<br />
OLD=$(find $BACKUPDIR -type d -mtime +30)<br />
if [ -n "$OLD" ] ; then<br />
        echo deleting old backup files: $OLD<br />
        echo $OLD | xargs rm -rfv<br />
fi</p>
]]></content:encoded>
			<wfw:commentRss>http://www.penguinlinux.com/blog/databases/mysql-backup-table-schema-structure-and-backup-only-data/feed/</wfw:commentRss>
		</item>
		<item>
		<title>The Most Common OpenSSL Commands</title>
		<link>http://www.penguinlinux.com/blog/general-linux/the-most-common-openssl-commands/</link>
		<comments>http://www.penguinlinux.com/blog/general-linux/the-most-common-openssl-commands/#comments</comments>
		<pubDate>Fri, 02 Oct 2009 16:36:21 +0000</pubDate>
		<dc:creator>tepezcuintle</dc:creator>
		
		<category><![CDATA[General Linux]]></category>

		<category><![CDATA[Linux Hacking]]></category>

		<guid isPermaLink="false">http://www.penguinlinux.com/blog/?p=669</guid>
		<description><![CDATA[
The Most Common OpenSSL Commands

One of the most versatile SSL tools is OpenSSL which is an open source implementation of the SSL protocol. There are versions of OpenSSL for nearly every platform, including Windows, Linux, and Mac OS X. OpenSSL is commonly used to create the CSR and private key for many different platforms, including [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://blog.securitymonks.com/images/hackers.jpg" alt="Hackers" /></p>
<h1>The Most Common OpenSSL Commands</h1>
</p>
<p>One of the most versatile SSL tools is <a href="http://www.openssl.org/">OpenSSL</a> which is an open source implementation of the SSL protocol. There are versions of OpenSSL for nearly every platform, including <a href="http://www.slproweb.com/products/Win32OpenSSL.html">Windows</a>, Linux, and Mac OS X. OpenSSL is commonly used to create the <a href="http://www.sslshopper.com/what-is-a-csr-certificate-signing-request.html">CSR</a> and private key for many different platforms, including Apache. However, it also has hundreds of different functions that allow you to view the details of a CSR or certificate, compare an MD5 hash of the certificate and private key (to make sure they match), verify that a certificate is installed properly on any website, and convert the certificate to a different format. </p>
<p><span id="more-669"></span></p>
<p>A compiled version of <a href="http://www.slproweb.com/products/Win32OpenSSL.html">OpenSSL for Windows can be found here</a>.</p>
<p>If you don&#8217;t want to bother with OpenSSL, you can do many of the same things with our <a href="http://www.sslshopper.com/ssl-certificate-tools.html">SSL Certificate Tools</a>. Below, we have listed the most common OpenSSL commands and their usage:</p>
<h2>General OpenSSL Commands</h2>
<p>These commands allow you to generate CSRs, Certificates, Private Keys and do other miscellaneous tasks.</p>
<ul>
<li><strong>Generate a new private key and Certificate Signing Request</strong>
<pre>openssl req -out <u>CSR.csr</u> -pubkey -new -keyout <u>privateKey.key</u></pre>
</li>
<li><strong>Generate a self-signed certificate</strong>
<pre>openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout <u>privateKey.key</u> -out <u>certificate.crt</u></pre>
</li>
<li><strong>Generate a certificate signing request (CSR) for an existing private key</strong>
<pre>openssl req -out <u>CSR.csr</u> -key <u>privateKey.key</u> -new</pre>
</li>
<li><strong>Generate a certificate signing request based on an existing certificate</strong>
<pre>openssl x509 -x509toreq -in <u>certificate.crt</u> -out <u>CSR.csr</u> -signkey <u>privateKey.key</u></pre>
</li>
<li><strong>Remove a passphrase from a private key</strong>
<pre>openssl rsa -in <u>privateKey.pem</u> -out <u>newPrivateKey.pem</u></pre>
</li>
</ul>
<h2>Checking Using OpenSSL</h2>
<p>If you need to check the information within a Certificate, CSR or Private Key, use these commands. You can also <a href="http://www.sslshopper.com/csr-decoder.html">check CSR</a>s and <a href="http://www.sslshopper.com/certificate-decoder.html">check certificates</a> using our online tools.</p>
<ul>
<li><strong>Check a Certificate Signing Request (CSR)</strong>
<pre>openssl req -text -noout -verify -in <u>CSR.csr</u></pre>
</li>
<li><strong>Check a private key</strong>
<pre>openssl rsa -in <u>privateKey.key</u> -check</pre>
</li>
<li><strong>Check a certificate</strong>
<pre>openssl x509 -in <u>certificate.crt</u> -text -noout</pre>
</li>
<li><strong>Check a PKCS#12 file (.pfx or .p12)</strong>
<pre>openssl pkcs12 -info -in <u>keyStore.p12</u></pre>
</li>
</ul>
<h2>Debugging Using OpenSSL</h2>
<p>If you are receiving an error that the private doesn&#8217;t match the certificate or that a certificate that you installed to a site is not trusted, try one of these commands. If you are trying to verify that an SSL certificate is installed correctly, be sure to check out the <a href="http://www.sslshopper.com/ssl-checker.html">SSL Checker</a>.</p>
<ul>
<li><strong>Check an MD5 hash of the public key to ensure that it matches with what is in a CSR or private key</strong>
<pre>openssl x509 -noout -modulus -in <u>certificate.crt</u> | openssl md5openssl rsa -noout -modulus -in <u>privateKey.key</u> | openssl md5openssl req -noout -modulus -in <u>CSR.csr</u> | openssl md5</pre>
</li>
<li><strong>Check an SSL connection. All the certificates (including Intermediates) should be displayed</strong>
<pre>openssl s_client -connect <u>www.paypal.com</u>:443</pre>
</li>
</ul>
<h2>Converting Using OpenSSL</h2>
<p>These commands allow you to convert certificates and keys to different formats to make them compatible with specific types of servers or software. For example, you can convert a normal PEM file that would work with Apache to a PFX (PKCS#12) file and use it with Tomcat or IIS. Use our <a href="https://www.sslshopper.com/ssl-converter.html">SSL Converter to convert certificates</a> without messing with OpenSSL.</p>
<ul>
<li><strong>Convert a DER file (.crt .cer .der) to PEM</strong>
<pre>openssl x509 -inform der -in <u>certificate.cer</u> -out <u>certificate.pem</u></pre>
</li>
<li><strong>Convert a PEM file to DER</strong>
<pre>openssl x509 -outform der -in <u>certificate.pem</u> -out <u>certificate.der</u></pre>
</li>
<li><strong>Convert a PKCS#12 file (</strong><strong>.pfx .p12</strong><strong>) containing a private key and certificates to PEM</strong>
<pre>openssl pkcs12 -in <u>keyStore.pfx</u> -out <u>keyStore.pem</u> -nodes</pre>
<p>You can add -nocerts to only output the private key or add -nokeys to only output the certificates.</p>
</li>
<li><strong>Convert a PEM certificate file and a private key to PKCS#12 (.pfx .p12)</strong>
<pre>openssl pkcs12 -export -out <u>certificate.pfx</u> -inkey <u>privateKey.key</u> -in <u>certificate.crt</u> -certfile <u>CACert.crt</u></pre>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.penguinlinux.com/blog/general-linux/the-most-common-openssl-commands/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Useful OpenSSL Tricks</title>
		<link>http://www.penguinlinux.com/blog/general-linux/useful-openssl-tricks/</link>
		<comments>http://www.penguinlinux.com/blog/general-linux/useful-openssl-tricks/#comments</comments>
		<pubDate>Fri, 02 Oct 2009 16:31:17 +0000</pubDate>
		<dc:creator>tepezcuintle</dc:creator>
		
		<category><![CDATA[General Linux]]></category>

		<category><![CDATA[Linux Security]]></category>

		<guid isPermaLink="false">http://www.penguinlinux.com/blog/?p=668</guid>
		<description><![CDATA[
Introduction
OpenSSL deserves a lot of credit.  It is an extremely useful, valuable Open Source project.  When
people talk about how successful Apache is, rock-solid crypto toolkits like OpenSSL and OpenSSH should
also be mentioned.  Here are a few (of the many) functions that I have found useful, along with examples of
how to use them:
 [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://blogs.ua.es/jgaliana/files/2008/07/openssl.gif" alt="Gif" /></p>
<h3>Introduction</h3>
<p>OpenSSL deserves a lot of credit.  It is an extremely useful, valuable Open Source project.  When<br />
people talk about how successful Apache is, rock-solid crypto toolkits like OpenSSL and OpenSSH should<br />
also be mentioned.  Here are a few (of the many) functions that I have found useful, along with examples of<br />
how to use them:</p>
<p> <span id="more-668"></span></p>
<ul>
<li>Base64 Encoding and Decoding</li>
<li>Symmetric Encryption and Decryption of Files</li>
<li>Cryptographic Hashing of Files</li>
<li>S_CLIENT SSL/TLS Test Utility</li>
</ul>
<p>These examples assume that you are using a Unix-like OS, with OpenSSL 0.9.6b or higher.</p>
<div>
<hr /></div>
<h3>Base64 Encode/Decode</h3>
<p>Base64 encoding is a standard method for converting 8-bit binary information into a limited subset<br />
of ASCII characters for safe transport through e-mail systems, and other systems that are not 8-bit<br />
safe.  With OpenSSL, it is very easy to encode and decode Base64 data:</p>
<pre>
$ <b>openssl enc -base64 -in myfile -out myfile.b64</b>

$ <b>openssl enc -d -base64 -in myfile.b64 -out myfile.decrypt</b>
</pre>
<h3>Symmetric Encryption/Decryption of Files</h3>
<p>As you can imagine, being able to encrypt and decrypt files with strong ciphers is a useful function.<br />
With OpenSSL, you can even use the commands in shell scripts.  Here are some command line examples<br />
using the Blowfish, Triple DES, and CAST5 ciphers:</p>
<pre>
$ <b>openssl enc -e -a -salt -bf -in tomcat.jpg -out tomcat.blowfish</b>
enter bf-cbc encryption password:
Verifying password - enter bf-cbc encryption password:

$ <b>openssl enc -d -a -bf -in tomcat.blowfish -out tomcat-decrypt.jpg</b>
enter bf-cbc decryption password:

$ <b>openssl enc -e -a -salt -des3 -in tomcat.jpg -out tomcat.des3</b>
enter des-ede3-cbc encryption password:
Verifying password - enter des-ede3-cbc encryption password:

$ <b>openssl enc -d -a -des3 -in tomcat.des3 -out tomcat-des3.jpg</b>
enter des-ede3-cbc decryption password:

$ <b>openssl enc -e -a -salt -cast5-cbc -in tomcat.jpg -out tomcat.cast5</b>
enter cast5-cbc encryption password:
Verifying password - enter cast5-cbc encryption password:

$ <b>openssl enc -d -a -cast5-cbc -in tomcat.cast5 -out tomcat-cast5.jpg</b>
enter cast5-cbc decryption password:
</pre>
<p>If the file will not be transported as an e-mail attachment, you can forego the<br />
<tt>-a</tt> argument, which base64 encodes and decodes the ciphertext.  Sometimes this is<br />
referred to as &#8220;ASCII armor&#8221;.  The non-base64 encoded files should be smaller.  Here is an example<br />
using the CAST5-CBC algorithm:</p>
<pre>
$ <b>openssl enc -e -salt -cast5-cbc -in tomcat.jpg -out tomcat.nob64</b>
enter cast5-cbc encryption password:
Verifying password - enter cast5-cbc encryption password:

$ <b>openssl enc -d -cast5-cbc -in tomcat.nob64 -out tomcat-nob64.jpg</b>
enter cast5-cbc decryption password:
</pre>
<h3>Cryptographic Hashing Functions</h3>
<p>What if you want to check to see that a file has not been tampered with?  One simple way to do this<br />
is a cryptographic <i>hashing</i> function.  This will give you a fixed-length string (called a<br />
message digest) given an input<br />
file of any length. SHA-1 and RIPE-MD160 are considered current; MD-5 is considered outdated.</p>
<pre>
$ <b>openssl dgst -sha1 -c tomcat.jpg</b>
SHA1(tomcat.jpg)= 92:b1:9b:96:ef:45:c3:89:b4:2e:e6:96:5b:43:bf:02:66:4a:47:8f

$ <b>openssl dgst -ripemd160 -c tomcat.jpg</b>
RIPEMD160(tomcat.jpg)= 68:f2:05:a9:9d:52:f1:cc:04:ed:d7:1e:42:80:0a:b8:c0:e6:cc:6d

$ <b>openssl dgst -md5 -c tomcat.jpg</b>
MD5(tomcat.jpg)= e7:13:d6:a7:cc:16:e3:da:0a:f7:ab:5a:fa:e3:3b:34
</pre>
<p>You can see that the <tt>md5sum</tt> utility that is shipped with most GNU/Linux distributions returns the<br />
same value as the openssl md5 message digest:</p>
<pre>
$ <b>md5sum tomcat.jpg</b>
e713d6a7cc16e3da0af7ab5afae33b34  tomcat.jpg
</pre>
<p>The OpenSSL <tt>dgst</tt> (message digest/hashing) command also has numerous options for signing digests,<br />
verifying signatures, etc.</p>
<h3>S_CLIENT SSL/TLS Test Utility</h3>
<p>OpenSSL has a great test utility available, called <tt>s_client</tt>.  This lets you test servers<br />
that use SSL/TLS with a powerful command line utility.  The following is an example of using<br />
<tt>s_client</tt> to view information about a secure web server:</p>
<pre>
$ <b>openssl s_client -connect www.redhat.com:443</b>

CONNECTED(00000003)
depth=0 /C=US/ST=North Carolina/L=Durham/O=Red Hat, Inc./OU=Web Operations/CN=www.redhat.com
verify error:num=20:unable to get local issuer certificate
verify return:1
depth=0 /C=US/ST=North Carolina/L=Durham/O=Red Hat, Inc./OU=Web Operations/CN=www.redhat.com
verify error:num=27:certificate not trusted
verify return:1
depth=0 /C=US/ST=North Carolina/L=Durham/O=Red Hat, Inc./OU=Web Operations/CN=www.redhat.com
verify error:num=21:unable to verify the first certificate
verify return:1
&#8212;
Certificate chain
 0 s:/C=US/ST=North Carolina/L=Durham/O=Red Hat, Inc./OU=Web Operations/CN=www.redhat.com
   i:/C=US/O=RSA Data Security, Inc./OU=Secure Server Certification Authority
&#8212;
Server certificate
&#8212;&#8211;BEGIN CERTIFICATE&#8212;&#8211;
MIID3TCCA0qgAwIBAgIQC4A9mzg//B7clolOw0V4WzANBgkqhkiG9w0BAQQFADBf
MQswCQYDVQQGEwJVUzEgMB4GA1UEChMXUlNBIERhdGEgU2VjdXJpdHksIEluYy4x
LjAsBgNVBAsTJVNlY3VyZSBTZXJ2ZXIgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkw
HhcNMDExMTE0MDAwMDAwWhcNMDMxMjA1MjM1OTU5WjCBgTELMAkGA1UEBhMCVVMx
FzAVBgNVBAgTDk5vcnRoIENhcm9saW5hMQ8wDQYDVQQHFAZEdXJoYW0xFjAUBgNV
BAoUDVJlZCBIYXQsIEluYy4xFzAVBgNVBAsUDldlYiBPcGVyYXRpb25zMRcwFQYD
VQQDFA53d3cucmVkaGF0LmNvbTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA
4MFi5Xg1rYKETCZ4inSeLJwK4/g/WcOI8JUpH7aK/Hm/e8Lz0uwagzEg/EQnACGl
o6HZsAwlNwV/H4LDXhf4I7NIfgLHmrp6qY1e3SX5qfAAPbxFl4ghiGzNdlTR2Pkn
XQhj/0eW8Pt7NdmQ6LDaMHxb2WchBQYVTYC/cK2zU+8CAwEAAaOCAXkwggF1MAkG
A1UdEwQCMAAwCwYDVR0PBAQDAgWgMDwGA1UdHwQ1MDMwMaAvoC2GK2h0dHA6Ly9j
cmwudmVyaXNpZ24uY29tL1JTQVNlY3VyZVNlcnZlci5jcmwwgawGA1UdIASBpDCB
oTCBngYLYIZIAYb4RQEHAQEwgY4wKAYIKwYBBQUHAgEWHGh0dHBzOi8vd3d3LnZl
cmlzaWduLmNvbS9DUFMwYgYIKwYBBQUHAgIwVjAVFg5WZXJpU2lnbiwgSW5jLjAD
AgEBGj1WZXJpU2lnbidzIENQUyBpbmNvcnAuIGJ5IHJlZmVyZW5jZSBsaWFiLiBs
dGQuIChjKTk3IFZlcmlTaWduMB0GA1UdJQQWMBQGCCsGAQUFBwMBBggrBgEFBQcD
AjAZBgpghkgBhvhFAQYPBAsWCTg3ODA1MTU1NjA0BggrBgEFBQcBAQQoMCYwJAYI
KwYBBQUHMAGGGGh0dHA6Ly9vY3NwLnZlcmlzaWduLmNvbTANBgkqhkiG9w0BAQQF
AAN+AEBUhe0gnMw8OWcnKA5XnoglC3V9v//UIZh7lVJCaMA/K2tFAiRlmkGPsim7
H8rHpZhtTOUBqZl6PuA/VJD2wCECJ+uUYx0zUh1dKwoJKWgcaBQOQ6GsCgxsOB2a
i6wMUcAlqHZULjF1mDkM4bu0gNmLXpIMIsw9UotTvz/O
&#8212;&#8211;END CERTIFICATE&#8212;&#8211;
subject=/C=US/ST=North Carolina/L=Durham/O=Red Hat, Inc./OU=Web Operations/CN=www.redhat.com
issuer=/C=US/O=RSA Data Security, Inc./OU=Secure Server Certification Authority
&#8212;
No client certificate CA names sent
&#8212;
SSL handshake has read 1549 bytes and written 314 bytes
&#8212;
New, TLSv1/SSLv3, Cipher is EDH-RSA-DES-CBC3-SHA
Server public key is 1024 bit
SSL-Session:
    Protocol  : TLSv1
    Cipher    : EDH-RSA-DES-CBC3-SHA
    Session-ID: 97D3E2DF903F5757AF8BED807F5FD9665F43300F139BDFCD1701974D97E5C5CA
    Session-ID-ctx:
    Master-Key: 4B2295AEDCE520F4615769135FB65EBD6E2345C88FCE4EB7450B71B17FD1A2B4460D751DC3DF05C311DA54B02A7B04D1
    Key-Arg   : None
    Start Time: 1063899107
    Timeout   : 300 (sec)
    Verify return code: 21 (unable to verify the first certificate)
&#8212;
</pre>
<p>Once you have connected, you can manually type in any commands you want, such as &#8220;<tt>GET /</tt>&#8221; and<br />
&#8220;<tt>HEAD / HTTP/1.0</tt>&#8221; for secure web servers.  There are also options<br />
like <tt>-no_tls1</tt> and <tt>-no_ssl2</tt> that let you specify which version of SSL/TLS that you want to<br />
connect with.</p>
<p>The <tt>-showcerts</tt> and <tt>-debug</tt> options are also worth a look.</p>
<div>
<hr /></div>
<h3>Resources</h3>
<ul>
<li><a href="http://www.openssl.org/">OpenSSL home page</a></li>
<li><tt>man openssl</tt></li>
<li><tt>man enc</tt></li>
<li><tt>man dgst</tt></li>
<li><tt>man s_client</tt></li>
</ul>
<div>
<hr /></div>
<div class=center>
<p></p>
]]></content:encoded>
			<wfw:commentRss>http://www.penguinlinux.com/blog/general-linux/useful-openssl-tricks/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Search and Replace String MySQL</title>
		<link>http://www.penguinlinux.com/blog/databases/search-and-replace-string-mysql/</link>
		<comments>http://www.penguinlinux.com/blog/databases/search-and-replace-string-mysql/#comments</comments>
		<pubDate>Mon, 17 Aug 2009 15:25:23 +0000</pubDate>
		<dc:creator>tepezcuintle</dc:creator>
		
		<category><![CDATA[Databases]]></category>

		<guid isPermaLink="false">http://www.penguinlinux.com/blog/?p=667</guid>
		<description><![CDATA[A day will eventually come when your need to find and replace a string of text in your database. You don’t know which row, or which column, or which table. Heck, you may not even know which database. Your options are: spend the rest of the summer hunting down the elusive table cells, or use [...]]]></description>
			<content:encoded><![CDATA[<p>A day will eventually come when your need to find and replace a string of text in your database. You don’t know which row, or which column, or which table. Heck, you may not even know which database. Your options are: spend the rest of the summer hunting down the elusive table cells, or use the weapon of mass replacement described below. Naturally and as usual, you absolutely must back up your database (or databases) before attempting any far-reaching scripted mumbo jumbo.<br />
<span id="more-667"></span></p>
<p><code><br />
#!/bin/bash<br />
echo -n "Enter username: " ; read db_user<br />
echo -n "Enter $db_user password: " ; stty -echo ; read db_passwd ; stty echo ; echo ""<br />
echo -n "Enter database name: " ; read db_name<br />
echo -n "Enter search string: " ; read search_string<br />
echo -n "Enter replacement string: " ; read replacement_string</p>
<p>MYSQL="/usr/bin/mysql --skip-column-names -u${db_user} -p${db_passwd}"</p>
<p>echo "SHOW TABLES;" | $MYSQL $db_name | while read db_table<br />
do<br />
	echo "SHOW COLUMNS FROM $db_table;" | $MYSQL $db_name| \<br />
	awk -F'\t' '{print $1}' | while read tbl_column<br />
	do<br />
		echo "update $db_table set ${tbl_column} = replace(${tbl_column}, '${search_string}', '${replacement_string}');" |\<br />
		$MYSQL $db_name<br />
	done<br />
done</p>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.penguinlinux.com/blog/databases/search-and-replace-string-mysql/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Create your own PGP Public Key</title>
		<link>http://www.penguinlinux.com/blog/advanced-stuff/create-your-own-pgp-public-key/</link>
		<comments>http://www.penguinlinux.com/blog/advanced-stuff/create-your-own-pgp-public-key/#comments</comments>
		<pubDate>Fri, 14 Aug 2009 17:30:18 +0000</pubDate>
		<dc:creator>tepezcuintle</dc:creator>
		
		<category><![CDATA[Advanced Stuff]]></category>

		<guid isPermaLink="false">http://www.penguinlinux.com/blog/?p=666</guid>
		<description><![CDATA[
Linux create your own GnuPG private and public key
GNU gpg is encryption and signing tool. 
The GNU Privacy Guard (GnuPG or GPG) is a free software replacement for the PGP suite of cryptographic software.
GnuPG encrypts messages using asymmetric keypairs individually generated by GnuPG users. The resulting public keys can be exchanged with other users in [...]]]></description>
			<content:encoded><![CDATA[<p><code><br />
Linux create your own GnuPG private and public key<br />
GNU gpg is encryption and signing tool. </p>
<p>The GNU Privacy Guard (GnuPG or GPG) is a free software replacement for the PGP suite of cryptographic software.</p>
<p>GnuPG encrypts messages using asymmetric keypairs individually generated by GnuPG users. The resulting public keys can be exchanged with other users in a variety of ways, such as Internet key servers. They must always be exchanged carefully to prevent identity spoofing by corrupting public key ? 'owner' identity correspondences. It is also possible to add a cryptographic digital signature to a message, so the message integrity and sender can be verified, if a particular correspondence relied upon has not been corrupted.</p>
<p><span id="more-666"></span></p>
<p>How do I create my own GnuPG private and public key<br />
1) Login to your shell account</p>
<p>2) Use gpg command to create the keys</p>
<p>$ gpg &#8211;gen-key<br />
Output:</p>
<p>gpg (GnuPG) 1.4.1; Copyright (C) 2005 Free Software Foundation, Inc.<br />
This program comes with ABSOLUTELY NO WARRANTY.<br />
This is free software, and you are welcome to redistribute it<br />
under certain conditions. See the file COPYING for details.</p>
<p>gpg: directory `/home/vivek/.gnupg&#8217; created<br />
gpg: new configuration file `/home/vivek/.gnupg/gpg.conf&#8217; created<br />
gpg: WARNING: options in `/home/vivek/.gnupg/gpg.conf&#8217; are not yet active during this run<br />
gpg: keyring `/home/vivek/.gnupg/secring.gpg&#8217; created<br />
gpg: keyring `/home/vivek/.gnupg/pubring.gpg&#8217; created<br />
Please select what kind of key you want:<br />
   (1) DSA and Elgamal (default)<br />
   (2) DSA (sign only)<br />
   (5) RSA (sign only)<br />
Your selection? Press [Enter] Key<br />
DSA keypair will have 1024 bits.<br />
ELG-E keys may be between 1024 and 4096 bits long.<br />
What keysize do you want? (2048) Press [Enter] Key<br />
Requested keysize is 2048 bits<br />
Please specify how long the key should be valid.<br />
         0 = key does not expire<br />
        = key expires in n days<br />
      w = key expires in n weeks<br />
      m = key expires in n months<br />
      y = key expires in n years<br />
Key is valid for? (0) Press [Enter] Key<br />
Key does not expire at all<br />
Is this correct? (y/N) y</p>
<p>You need a user ID to identify your key; the software constructs the user ID<br />
from the Real Name, Comment and Email Address in this form:<br />
    &#8220;Heinrich Heine (Der Dichter) &#8221;</p>
<p>Real name: Vivek Gite<br />
Email address: vivek@nixcraftcorp.com<br />
Comment:[Enter] key<br />
You selected this USER-ID:<br />
    &#8220;Vivek Gite &#8221;</p>
<p>Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O<br />
You need a Passphrase to protect your secret key.</p>
<p>Enter passphrase: [Enter password twice]<br />
We need to generate a lot of random bytes. It is a good idea to perform<br />
some other action (type on the keyboard, move the mouse, utilize the<br />
disks) during the prime generation; this gives the random number<br />
generator a better chance to gain enough entropy.<br />
.+++++&#8230;.+++++++++++++++..++++++++++..++++++++++&#8230;++++++++++++++++++++.+++++++++++++++++++++++++++++++++++.+++++..++++++++++++++++++++.++++++++++..+++++.+++++.+++++>+++++&#8230;.+++++>.+++++&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.+++++^^^^^^^^^^^<br />
gpg: /home/vivek/.gnupg/trustdb.gpg: trustdb created<br />
gpg: key 8E19F126 marked as ultimately trusted<br />
public and secret key created and signed.</p>
<p>gpg: checking the trustdb<br />
gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model<br />
gpg: depth: 0  valid:   1  signed:   0  trust: 0-, 0q, 0n, 0m, 0f, 1u<br />
pub   1024D/8E19F126 2007-02-10<br />
      Key fingerprint = A7AF E25D 3E8D 6946 37CC  8CCE 12C4 8DC1 8E19 F126<br />
uid                  Vivek Gite<br />
sub   2048g/032824B9 2007-02-10<br />
3) Now keys generated, you can list your own key using:</p>
<p>$ gpg -K<br />
OR</p>
<p>$ gpg &#8211;list-keys<br />
Output:</p>
<p>/home/vivek/.gnupg/pubring.gpg<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
pub   1024D/CA7A8402 2007-02-10<br />
uid                  Vivek Gite<br />
sub   2048g/0A7B4F93 2007-02-10<br />
Let us try to understand the line pub 1024D/CA7A8402 2007-02-10:</p>
<p>?pub : Public key<br />
?1024D : The number of bits in the key<br />
?CA7A8402 : The key ID<br />
?2007-02-10 : The date of key creation<br />
?Vivek Gite : The user real name<br />
?<vivek@nixcraftcorp.com> : The email id<br />
Most important is the key ID i.e. CA7A8402. Make sure you use powerful passphrase to protect keys and not the easy one.</p>
<p>4) To list secret key, type the command:</p>
<p>$ gpg &#8211;list-secret-keys<br />
Output:</p>
<p>/home/vivek/.gnupg/secring.gpg<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
sec   1024D/CA7A8402 2007-02-10<br />
uid                  Vivek Gite<br />
ssb   2048g/0A7B4F93 2007-02-10<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.penguinlinux.com/blog/advanced-stuff/create-your-own-pgp-public-key/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How to Drop all Tables on a MySQL database</title>
		<link>http://www.penguinlinux.com/blog/bash-scripting/how-to-drop-all-tables-on-a-mysql-database/</link>
		<comments>http://www.penguinlinux.com/blog/bash-scripting/how-to-drop-all-tables-on-a-mysql-database/#comments</comments>
		<pubDate>Thu, 13 Aug 2009 19:17:28 +0000</pubDate>
		<dc:creator>tepezcuintle</dc:creator>
		
		<category><![CDATA[Bash Scripting]]></category>

		<guid isPermaLink="false">http://www.penguinlinux.com/blog/?p=664</guid>
		<description><![CDATA[
Let&#8217;s say you need to drop all tables in a mysql database. How do you do that?
You could use a gui, but that&#8217;s not fun.
You&#8217;re a shell jockey so you want a commandline:
 mysql -u uname dbname -e "show tables" &#124; grep -v Tables_in &#124; grep -v "+" &#124; \
gawk '{print "drop table " $1 [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://blogs.sun.com/datacharmer/resource/sakila_quiz.jpg" alt="Shark" /></p>
<p>Let&#8217;s say you need to drop all tables in a mysql database. How do you do that?</p>
<p>You could use a gui, but that&#8217;s not fun.</p>
<p>You&#8217;re a shell jockey so you want a commandline:</p>
<p><code> mysql -u uname dbname -e "show tables" | grep -v Tables_in | grep -v "+" | \<br />
gawk '{print "drop table " $1 ";"}' | mysql -u uname dbname<br />
</code></p>
<p>(that&#8217;s all one line, but if I do it as a line then it screws up my theme - go figure).</p>
<p>This assumes that you are running in passwordless mode. See &#8220;man mysql&#8221; for tips on how to pass in passwords in another manner.</p>
<p>What this does is</p>
<p>1.connect to a specific mysql database and execute the command for showing tables<br />
2.find lines that match &#8220;Tables_in&#8221; and not show them<br />
3.find lines that match the + character and not show them<br />
4.use gawk to print out the words &#8220;drop table&#8221; followed by the table name (which is in $1) and then a semicolon<br />
5.pipe all of that back to the database you got the list from to drop those tables<br />
Fun stuff and very handy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.penguinlinux.com/blog/bash-scripting/how-to-drop-all-tables-on-a-mysql-database/feed/</wfw:commentRss>
		</item>
		<item>
		<title>A Simple Monitoring Script to monitor devices or hosts</title>
		<link>http://www.penguinlinux.com/blog/bash-scripting/a-simple-monitor-script/</link>
		<comments>http://www.penguinlinux.com/blog/bash-scripting/a-simple-monitor-script/#comments</comments>
		<pubDate>Fri, 01 May 2009 21:38:04 +0000</pubDate>
		<dc:creator>tepezcuintle</dc:creator>
		
		<category><![CDATA[Bash Scripting]]></category>

		<guid isPermaLink="false">http://www.penguinlinux.com/blog/?p=663</guid>
		<description><![CDATA[
At work we have a few routers,  switches and servers that if they go down we want to know right away. The last thing we want is the CEO coming to our desk asking why the mail server is down or why the webserver it not responding.  
I wrote a little script a [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.linuxhotbox.com/fun/linux-penguin/linux-20010531144615-marinha.jpg" alt="Monitor" /><br />
At work we have a few routers,  switches and servers that if they go down we want to know right away. The last thing we want is the CEO coming to our desk asking why the mail server is down or why the webserver it not responding.  </p>
<p>I wrote a little script a very simple one that given a list of hosts and IP addresses will ping a host and if it is detected as down it will send you an email right away.  </p>
<p>########## Instructions on how to use this monitor script ############</p>
<p> Make a directory called scripts<br />
mkdir /scripts  then inside create using your favorite text editor the following script </p>
<p><code><br />
#!/bin/bash<br />
#  Ping Alert Monitor by Marco Maldonado V 1.0<br />
#  Create a hosts file and save it somewhere on your server<br />
#  specify a path and an email address where you want to send alerts<br />
#<br />
#  Note: Your hosts file should have the IP address of the host followed by a space and the name<br />
#  of the server: Example Below<br />
#<br />
#  69.147.76.15  www.yahoo.com<br />
#  209.85.165.147 wwww.google.com<br />
#</p>
<p># Path to your hosts file</p>
<p>HOSTS="/scripts/hosts"</p>
<p># Email address where to send alerts, you can add more addresses followed by a comma</p>
<p>EMAIL="yourname@yourdomain,someaddres@gmail.com"</p>
<p>### Do not edit anything below ############</p>
<p>for myHost in `cat $HOSTS | cut -d' ' -f1` ; do<br />
     ping -c 1 $myHost > /dev/null<br />
 if [ $? -ne 0 ] ; then<br />
    echo &#8220;Server `grep $myHost $HOSTS` is down reported down at `date`&#8221; | mail -s &#8220;Ping Alert Server `grep $myHost $HOSTS` might be down&#8221; $EMAIL<br />
 fi ;<br />
 done</p>
<p></code></p>
<p><span id="more-663"></span><br />
replace the email addresses listed there you can put only one or multiple email addresses separated by a comma.  I put my gmail address because in case my mail server goes down i can still get a report to another address.   </p>
<p>Save the script and make it executable  chmod 755 /scripts/ping_alert.sh </p>
<p>Create a host file of the hosts you want to monitor starting with the IP address of the server and then some details about the server example</p>
<p><code></p>
<p>10.1.29.100 Exchange Server<br />
120.12.45.2  External webserver www.yourdomain.com ( Phone support 212-453-### )<br />
10.1.30.22    Cisco Catalist for Segment XYZ<br />
10.1.30.33    Lexmark TCP IP Printer<br />
</code></p>
<p>save the file and name it hosts.  You are almost done. </p>
<p>Now create a crontab entry on your crontab file that will monitor the above IP addresses by the minute. </p>
<p>here is a quick way to edit your crontab. </p>
<p>crontab -l > mycrontab.txt </p>
<p>this will dump your crontab into the mycrontab.txt file.   Edit that file and add the following line to it. </p>
<p>* * * * * /scripts/ping_alert.sh >> /dev/null 2>&#038;1</p>
<p>as an example here is my current crontab. </p>
<p><code></p>
<p>[root@penguincares scripts]# crontab -l > mycrontab.txt<br />
[root@penguincares scripts]# more mycrontab.txt<br />
* * * * * /usr/bin/php /opt/projects/mrtg/serverstats/update.php >> /dev/null 2>&#038;1<br />
* * * * * /scripts/ping_alert.sh >> /dev/null 2>&#038;1<br />
*/5 * * * * php /opt/projects/mrtg/cacti/poller.php > /dev/null 2>&#038;1</p>
<p></code></p>
<p>Then to load this new crontab all you have to do is type </p>
<p>crontab mycrontab.txt and that will load the new changes that you added. </p>
<p>######### NOW WHAT ? #################</p>
<p>That&#8217;s it your crontab entry is monitoring those devices by sending a ping request it they go down<br />
you will get an email right away telling you which IP address failed.   You can test to see if it is working or not by putting a fake ip address and a server name next to it. </p>
<p>When the script detects the downed server you should recieve and emal saying the following </p>
<p>Subject:Ping Alert Server 216.21.3.33 Exchange Server might be down</p>
<p>Body: Server 216.21.3.33 Exchange Server is down reported down at Fri May  1 17:07:11 EDT 2009</p>
<p>This is a simple monitor not the greatest way to monitor a server but you can be sure you will know when a certain server or device fails.  I will be adding other checks to this script in about a few more days, one of the checks i will  add is to stop sending email right after 5 alerts.  This is to prevent having hundreds of emails flooding your inbox.  </p>
<p>I&#8217;ve been running the script for a few weeks and it has helped me catch problems on our network and people always ask me how do i know when things go down so fast :) well know you know. </p>
<p>Good luck Penguins</p>
]]></content:encoded>
			<wfw:commentRss>http://www.penguinlinux.com/blog/bash-scripting/a-simple-monitor-script/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Your File System became read only. What gives?</title>
		<link>http://www.penguinlinux.com/blog/general-linux/your-file-system-became-read-only-what-gives/</link>
		<comments>http://www.penguinlinux.com/blog/general-linux/your-file-system-became-read-only-what-gives/#comments</comments>
		<pubDate>Mon, 27 Apr 2009 13:38:40 +0000</pubDate>
		<dc:creator>tepezcuintle</dc:creator>
		
		<category><![CDATA[General Linux]]></category>

		<guid isPermaLink="false">http://www.penguinlinux.com/blog/?p=662</guid>
		<description><![CDATA[If your system abruptly loses power, or if a RAID card is beginning to fail, you might see an ominous message like this within your logs:
EXT3-fs error (device hda3) in start_transaction: Journal has aborted
Basically, the system is telling you that it&#8217;s detected a filesystem/journal mismatch, and it can&#8217;t utilize the journal any longer.  When [...]]]></description>
			<content:encoded><![CDATA[<p>If your system abruptly loses power, or if a RAID card is beginning to fail, you might see an ominous message like this within your logs:</p>
<p><code>EXT3-fs error (device hda3) in start_transaction: Journal has aborted</code></p>
<p>Basically, the system is telling you that it&#8217;s detected a filesystem/journal mismatch, and it can&#8217;t utilize the journal any longer.  When this situation pops up, the filesystem gets mounted read-only almost immediately.  To fix the situation, you can remount the partition as ext2 (if it isn&#8217;t your active root partition), or you can commence the repair operations.</p>
<p><span id="more-662"></span></p>
<p>If you&#8217;re working with an active root partition, you will need to boot into some rescue media and perform these operations there.  If this error occurs with an additional partition besides the root partition, simply unmount the broken filesystem and proceed with these operations.</p>
<p>Remove the journal from the filesystem (effectively turning it into ext2):</p>
<p><code># tune2fs -O ^has_journal /dev/hda3</code></p>
<p>Now, you will need to fsck it to correct any possible problems (throw in a -y flag to say yes to all repairs, -C for a progress bar):</p>
<p><code># e2fsck /dev/hda3 </code></p>
<p><code>Once that's finished, make a new journal which effectively makes the partition an ext3 filesystem again</code></p>
<p><code># tune2fs -j /dev/hda3 </code></p>
<p>You should be able to mount the partition as an ext3 partition at this time:</p>
<p><code># mount -t ext3 /dev/hda3 /mnt/fixed</code></p>
<p>Be sure to check your dmesg output for any additional errors after you&#8217;re finished!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.penguinlinux.com/blog/general-linux/your-file-system-became-read-only-what-gives/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Configure Postfix with smart host</title>
		<link>http://www.penguinlinux.com/blog/email-servers-and-spam/configure-postfix-with-smart-host/</link>
		<comments>http://www.penguinlinux.com/blog/email-servers-and-spam/configure-postfix-with-smart-host/#comments</comments>
		<pubDate>Tue, 21 Apr 2009 16:45:35 +0000</pubDate>
		<dc:creator>tepezcuintle</dc:creator>
		
		<category><![CDATA[Email Servers and Spam]]></category>

		<guid isPermaLink="false">http://www.penguinlinux.com/blog/?p=661</guid>
		<description><![CDATA[At work i setup a programming environment for developers.  The server is on a natted IP address range and could not send email to our internal mail server because of some weird firewall issues.  
All email going to external sites was working fine but to send to our internal domain it wouldn&#8217;t work [...]]]></description>
			<content:encoded><![CDATA[<p><img src='http://sqlgrey.sourceforge.net/mysza_postfix.gif' alt='Postfix mouse' class='alignleft' />At work i setup a programming environment for developers.  The server is on a natted IP address range and could not send email to our internal mail server because of some weird firewall issues.  </p>
<p>All email going to external sites was working fine but to send to our internal domain it wouldn&#8217;t work so i had to figure out how to get emails out.   I am running postfix on the server so what I did i had postfix relay the mail to my ISP&#8217;s mail server.  I had done this in the past using sendmail but with postfix I had to do the following. </p>
<p><span id="more-661"></span></p>
<div style='float:right;margin-top:0px;margin-left:5px;'><a href='http://www.cyberciti.biz/faq/category/email-servers/' title='See all Postfix Mail Server related FAQ'><img src='http://figs.cyberciti.biz/3rdparty/postfix-logo.gif' border='0' /></a></div>
<p><span class="drop_cap">M</span>y ISP requires that mail from my dynamic IP to our small business email addresses uses their outgoing SMTP servers. This is probably done to reduce abuse and spam but now I&#8217;m not able to send email and local Postfix log file displays authentication failure message.  How do I relay mail through my mail ISP servers using Postfix SMTP under Linux / UNIX like operating systems?<br />
<span id="more-3433"></span><br />
Postfix has a method of authentication using SASL. It can use a text file or MySQL table as a special password database. </p>
<h2>Configure SMTP AUTH for mail servers</h2>
<p>Create a text file as follows:<br />
<code># P=/etc/postfix/password<br />
# vi $P</code><br />
The format of the client password file is as follows:</p>
<pre>#smtp.isp.com       username:password
smtp.vsnl.in         vivek@vsnl.in:mySecretePassword</pre>
<p>Save and close the file. Set permissions:<br />
<code># chown root:root $P<br />
# chmod 0600 $P<br />
# postmap hash:$P</code></p>
<h3>Enable SMTP AUTH</h3>
<p>Open main.cf file, enter:<br />
<code># vi /etc/postfix/main.cf</code><br />
Append following config directives:</p>
<pre class="ini"> <span style="color: #000099;">relayhost </span>=<span style="color: #660066;"> smtp.vsnl.in</span>
<span style="color: #000099;">smtp_sasl_auth_enable </span>=<span style="color: #660066;"> yes</span>
<span style="color: #000099;">smtp_sasl_password_maps </span>=<span style="color: #660066;"> hash:/etc/postfix/password</span>
<span style="color: #000099;">smtp_sasl_security_options </span>=</pre>
<p>Where,</p>
<ul>
<li><strong>relayhost = smtp.vsnl.in</strong> : Rely all mail via smtp.vsnl.in ISP mail server.</li>
<li><strong>smtp_sasl_auth_enable = yes</strong> : Cyrus-SASL support for authentication of mail servers.</li>
<li><strong>smtp_sasl_password_maps = hash:/etc/postfix/password</strong> : Set path to sasl_passwd.</li>
<li><strong>smtp_sasl_security_options = </strong>: Finally, allow Postfix to use anonymous and plaintext authentication by leaving it empty.</li>
</ul>
<p>Save and close the file.</p>
<p>Then run postmap /etc/postfix/password </p>
<p> Restart Postfix:<br />
<code># /etc/init.d/postfix reload</code><br />
Test your setup by sending a text email:<br />
<code>$ echo 'This is a test.' > /tmp/test<br />
$ mail -s &#8216;Test&#8217; you@example.com < /tmp/test<br />
# tail -f /var/log/maillog<br />
# rm /tmp/test<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.penguinlinux.com/blog/email-servers-and-spam/configure-postfix-with-smart-host/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
