<?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>pingd.org</title>
	<atom:link href="http://pingd.org/feed" rel="self" type="application/rss+xml" />
	<link>http://pingd.org</link>
	<description>Heart Beat of the Internet</description>
	<lastBuildDate>Mon, 20 May 2013 21:24:39 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Understanding suPHP Permissions &#8211; Why am I getting 500 Internal Server Error?</title>
		<link>http://pingd.org/2013/understanding-suphp-permissions-why-am-i-getting-500-internal-server-error.html</link>
		<comments>http://pingd.org/2013/understanding-suphp-permissions-why-am-i-getting-500-internal-server-error.html#comments</comments>
		<pubDate>Thu, 25 Apr 2013 23:22:26 +0000</pubDate>
		<dc:creator>pingd</dc:creator>
				<category><![CDATA[Bash One-Liners]]></category>
		<category><![CDATA[cPanel Guides]]></category>
		<category><![CDATA[Linux Guides]]></category>
		<category><![CDATA[500 error]]></category>
		<category><![CDATA[500 internal server error]]></category>
		<category><![CDATA[500 ise]]></category>
		<category><![CDATA[cPanel]]></category>
		<category><![CDATA[internal server error]]></category>
		<category><![CDATA[lamp]]></category>
		<category><![CDATA[linux ownership]]></category>
		<category><![CDATA[linux permissions]]></category>
		<category><![CDATA[php 500 error]]></category>
		<category><![CDATA[php error]]></category>
		<category><![CDATA[php suexec]]></category>
		<category><![CDATA[suexec]]></category>
		<category><![CDATA[suphp]]></category>
		<category><![CDATA[world writable]]></category>

		<guid isPermaLink="false">http://pingd.org/?p=363</guid>
		<description><![CDATA[I see this topic come up a lot with users who migrate to one of our servers or to their own setup with cPanel and suPHP. The user or their customers will install a PHP script such as wordpress, concrete5, &#8230; <a href="http://pingd.org/2013/understanding-suphp-permissions-why-am-i-getting-500-internal-server-error.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>I see this topic come up a lot with users who migrate to one of our servers or to their own setup with cPanel and suPHP. The user or their customers will install a PHP script such as wordpress, concrete5, etc&#8230; Upon testing their installation they will get 500 ISE (Internal Server Error) in their web browser, served from Apache. Many less experienced users freak out and think something is wrong with the server. The reality is that permissions or file ownership is the cause of the error in the VAST majority of cases. <span id="more-363"></span></p>
<p>Often times these scripts provide documentation geared towards basic LAMP (Linux, Apache, MySQL, PHP) setups with regular mod_php. The documentation suggests that certain directories and files should be set to world writable (i.e. 777 or 666.) Often times the PHP files that are part of this script are distributed with the executable permission of 755.</p>
<p>On a modern server running suPHP (common with cPanel servers) Apache does not use mod_php and scripts are not executed by the &#8216;apache&#8217; or &#8216;nobody&#8217; user. Instead suPHP will be used and the PHP process will run as the user that the file belongs to. For security purposes there are several considerations, which are true regardless of the script&#8217;s documentation:</p>
<ul>
<li><span style="line-height: 16px;">The files and directories should be owned to the proper user that they belong to. If the username is &#8216;robert&#8217; the files should be owned and grouped to robert.</span></li>
<li>The files and directories should NOT be owned to &#8216;root&#8217;, &#8216;nobody&#8217; or &#8216;apache&#8217;.</li>
<li>All directories should be set to permission level of 0755 and all files should be set to permission level of 0644.</li>
<li>You should NOT have any world writable files or directories with permission levels such as 0777, 0666, 0770, 0660, etc&#8230;</li>
<li>Your PHP script files (.php) should not be executable, such as 0755.</li>
</ul>
<p>If you follow the above instructions. You won&#8217;t have any problems. Here is a sample of an incorrect setup:</p>
<pre class="brush: bash; title: ; notranslate">root@server [~]# cd /home/robert/public_html/
root@server [/home/robert/public_html]# ll
total 196
drwxr-x---. 23 robert nobody   4096 Nov 12  2011 ./
drwx--x--x. 14 robert robert  4096 Mar 26  2012 ../
drwxrwxrwx.  2 robert robert  4096 Jan  6  2011 blocks/
drwxrwxrwx.  2 robert robert  4096 Jan  6  2011 config/
drwxrwxrwx.  2 robert robert  4096 Jan  6  2011 css/
-rw-rw-rw-.  1 robert robert    42 Jan  6  2011 index.php
drwxrwxrwx.  2 robert robert  4096 Jan  6  2011 js/
drwxrwxrwx.  2 robert robert  4096 Jan  6  2011 languages/
drwxrwxrwx.  2 robert robert  4096 Jan  6  2011 libraries/
drwxrwxrwx.  2 robert robert  4096 Jan  6  2011 models/
drwxrwxrwx. 13 robert robert  4096 Mar 26  2012 packages/
-rw-rw-rw-.  1 robert robert   347 Jan  6  2011 robots.txt
-rw-rw-rw-.  1 robert robert  2467 Mar  6  2012 sitemap.xml
drwxrwxrwx.  2 robert robert  4096 Jan  6  2011 themes/
root@server [/home/robert/public_html]#</pre>
<p>As you can see the permissions are all wrong. The index.php is 666, the directories are all 777. What a mess, this won&#8217;t ever work on suPHP! At least they&#8217;re all owned to the proper user (&#8216;robert&#8217;).</p>
<p>You could go through each directory and fix permissions, but we have a quicker way to do this via two bash one liners:</p>
<pre class="brush: bash; title: ; notranslate">root@server [~]# cd /home/robert/public_html/
root@server [/home/robert/public_html]# find -type f | while read LINE; do chmod -v 644 $LINE; done
root@server [/home/robert/public_html]# find -type d | grep -v '^\.$' | while read LINE; do chmod -v 755 $LINE; done</pre>
<p>This will change all the files inside the current directory structure (and sub-directories) to be mode 644. The second command will change each directory in the current directory (and sub-directories) to be mode 755. Make sure you&#8217;re in the proper directory, if you&#8217;re not you might change permissions on stuff you didn&#8217;t mean to, like the whole OS></p>
]]></content:encoded>
			<wfw:commentRss>http://pingd.org/2013/understanding-suphp-permissions-why-am-i-getting-500-internal-server-error.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MyISAM Repair all MySQL Databases &amp; Tables</title>
		<link>http://pingd.org/2013/myisam-repair-all-mysql-databases-tables.html</link>
		<comments>http://pingd.org/2013/myisam-repair-all-mysql-databases-tables.html#comments</comments>
		<pubDate>Mon, 22 Apr 2013 23:45:32 +0000</pubDate>
		<dc:creator>pingd</dc:creator>
				<category><![CDATA[Bash One-Liners]]></category>
		<category><![CDATA[Linux Guides]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[corrupt myisam]]></category>
		<category><![CDATA[corrupt table]]></category>
		<category><![CDATA[database corruption]]></category>
		<category><![CDATA[myisam]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[repair all tables]]></category>
		<category><![CDATA[repair myisam table]]></category>
		<category><![CDATA[repair mysql]]></category>
		<category><![CDATA[repair table]]></category>

		<guid isPermaLink="false">http://pingd.org/?p=358</guid>
		<description><![CDATA[So you&#8217;ve probably not made the switch to InnoDB or XtraDB yet, shame on you! But tonight your server crashed, ran out of disk space or otherwise corrupted all of your active tables across various databases. Ouch! How are we &#8230; <a href="http://pingd.org/2013/myisam-repair-all-mysql-databases-tables.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>So you&#8217;ve probably not made the switch to InnoDB or XtraDB yet, shame on you! But tonight your server crashed, ran out of disk space or otherwise corrupted all of your active tables across various databases. Ouch! How are we going to fix this one?</p>
<p>Many admins try using the myisamchk tool from shell in an attempt to repair the MYI files. This may or may not work. I generally don&#8217;t recommend it as a primary means to a repair, especially if you are going to continue running mysqld and attempting to use the crashed tables.<span id="more-358"></span></p>
<p>First you will want to identify weather or not tables are marked as crashed. This will be evident in the mysqld log file, typically in /var/lib/mysql, /var/log/, /var/log/mysql or possibly another location depending on your my.cnf. You should look for messages like:</p>
<pre class="brush: bash; title: ; notranslate">130422 17:43:34 [ERROR] /usr/sbin/mysqld: Incorrect key file for table './socialforum/wp_posts.MYI'; try to repair it
130422 17:43:47 [ERROR] /usr/sbin/mysqld: Incorrect key file for table './socialforum/wp_options.MYI'; try to repair it</pre>
<p>Alternatively you can also look at table status via the mysql CLI.</p>
<p>So now that we know we have indeed experienced corruption, we need to do something about it. If you have just one corrupt table you could fix it via the mysql CLI like so:</p>
<pre class="brush: bash; title: ; notranslate">root@server [/var/lib/mysql]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1691
Server version: 5.0.96-community-log MySQL Community Edition (GPL)

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql&gt; REPAIR TABLE socialforum.wp_posts;
+-------------------------+--------+----------+----------+
| Table                   | Op     | Msg_type | Msg_text |
+-------------------------+--------+----------+----------+
| socialforum.wp_posts    | repair | status   | OK       | 
+-------------------------+--------+----------+----------+
1 row in set (0.00 sec)

mysql&gt; exit
Bye
root@server [/var/lib/mysql]#</pre>
<p>That should repair the table and stop the errors. However, what if you have a TON of tables, let&#8217;s say hundreds across several databases? What do we do then? We can&#8217;t just sit around entering each repair command manually. No way!</p>
<p>What we will do instead is cycle through each MyISAM table across all database and repair those tables via a bash script.</p>
<p>First you will want to &#8216;cd&#8217; into your mysql directory that has all the databases. Typically it&#8217;s /var/lib/mysql:</p>
<pre class="brush: bash; title: ; notranslate">root@server [~]# cd /var/lib/mysql
root@server [/var/lib/mysql]#</pre>
<p>Now let&#8217;s run this one-liner, note that it finds all the files, greps for MYI (indicating a MyISAM table) figures out the db name ($1) and table name ($2). I recommend first removing the while loop at the end and making sure that each statement makes sense before running it with the while loop:</p>
<pre class="brush: bash; title: ; notranslate">find . | grep MYI | cut -d / -f 2,3 | cut -d . -f 1 | awk -F &quot;/&quot; '{print &quot;REPAIR TABLE &quot; $1 &quot;.&quot; $2 &quot;;&quot;}' | while read LINE; do mysql -e &quot;$LINE&quot;; done</pre>
<p>Note it may take a while to run especially with very large tables. However once finished you will be error free. Make sure you have enough disk space for the repair, if you had corruption due to running out of disk space you need to free space first before repairing.</p>
]]></content:encoded>
			<wfw:commentRss>http://pingd.org/2013/myisam-repair-all-mysql-databases-tables.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reset Supermicro IPMI Password From Windows</title>
		<link>http://pingd.org/2013/reset-supermicro-ipmi-password-from-windows.html</link>
		<comments>http://pingd.org/2013/reset-supermicro-ipmi-password-from-windows.html#comments</comments>
		<pubDate>Fri, 12 Apr 2013 07:58:35 +0000</pubDate>
		<dc:creator>pingd</dc:creator>
				<category><![CDATA[Server Hardware]]></category>
		<category><![CDATA[default ipmi password]]></category>
		<category><![CDATA[ipmi]]></category>
		<category><![CDATA[ipmi password]]></category>
		<category><![CDATA[ipmi password reset]]></category>
		<category><![CDATA[ipmicfg]]></category>
		<category><![CDATA[ipmicfg-windows]]></category>
		<category><![CDATA[ipmicfg-windows.exe]]></category>
		<category><![CDATA[ipmitool]]></category>
		<category><![CDATA[supermicro]]></category>
		<category><![CDATA[supermicro default ipmi password]]></category>
		<category><![CDATA[windows ipmi]]></category>

		<guid isPermaLink="false">http://pingd.org/?p=354</guid>
		<description><![CDATA[I recently had an issue where we lost the password for IPMI to a brand new Supermicro server. The server was running Windows 2008 STD. Not wanting to mess around rebooting the box to a livecd I had to find &#8230; <a href="http://pingd.org/2013/reset-supermicro-ipmi-password-from-windows.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>I recently had an issue where we lost the password for IPMI to a brand new Supermicro server. The server was running Windows 2008 STD. Not wanting to mess around rebooting the box to a livecd I had to find a solution to reset the password. This could be very useful for those of you buying a used Supermicro server or if someone fat fingers a password or logs it incorrectly into your management system.<span id="more-354"></span></p>
<p>First you will need the IPMI Configuration utility. I got a copy for windows (32-bit and 64-bit) here:</p>
<p><a href="ftp://ftp.supermicro.com/CDR-B9_1.00_for_Intel_B9_platform/IPMI/IPMICFG/Windows/IPMICFG-Windows_v1.10.zip">Download IPMICFG-Windows.exe</a></p>
<p>Unzip your download and place either the 32-bit, 64-bit, or both directories somewhere accessible to you from a command prompt. I&#8217;m using 64-bit so I just copied that directory. Boot up the Administrator command prompt and &#8216;cd&#8217; into the appropriate directory.</p>
<p>Once there, here are the commands we&#8217;re going to run:</p>
<pre class="brush: bash; title: ; notranslate">C:\Users\Administrator\Desktop\64bit&gt;IPMICFG-Windows.exe -fd
Reset to the factory default completed.
C:\Users\Administrator\Desktop\64bit&gt;IPMICFG-Windows.exe -dhcp off
Successfully disable DHCP.
C:\Users\Administrator\Desktop\64bit&gt;IPMICFG-Windows.exe -m x.x.x.x
IP=x.x.x.x
C:\Users\Administrator\Desktop\64bit&gt;IPMICFG-Windows.exe -k 255.255.255.xxx
Subnet Mask=255.255.255.x
C:\Users\Administrator\Desktop\64bit&gt;IPMICFG-Windows.exe -g x.x.x.x
Gatway=x.x.x.x</pre>
<p>Obviously you will need to specify the correct IP adress, subnet mask and gateway. The application will echo back the result to you. It&#8217;s important you turn DHCP off if you are going to use a static IP. Otherwise just leave DHCP on, and reset it to default with the first command and pass it the empty &#8216;m&#8217; flag to see the current IP from DHCP.</p>
<p>Once your IPMI is online you should be able to login to it via the default username and password of ADMIN. Once logged in as the &#8216;ADMIN&#8217; user, you will want to change your password, because &#8216;ADMIN&#8217; is not a secure password. Do so from the configuration menu.</p>
]]></content:encoded>
			<wfw:commentRss>http://pingd.org/2013/reset-supermicro-ipmi-password-from-windows.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>suPHP on CentOS 6 from Source Code</title>
		<link>http://pingd.org/2013/suphp-on-centos-6-from-source-code.html</link>
		<comments>http://pingd.org/2013/suphp-on-centos-6-from-source-code.html#comments</comments>
		<pubDate>Fri, 15 Feb 2013 05:07:11 +0000</pubDate>
		<dc:creator>pingd</dc:creator>
				<category><![CDATA[Linux Guides]]></category>
		<category><![CDATA[centos 6]]></category>
		<category><![CDATA[fastcgi]]></category>
		<category><![CDATA[lamp]]></category>
		<category><![CDATA[mod_suphp]]></category>
		<category><![CDATA[mod_suphp.so]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php.conf]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[source code]]></category>
		<category><![CDATA[suphp]]></category>
		<category><![CDATA[suphp-0.7.1]]></category>
		<category><![CDATA[suphp.conf]]></category>

		<guid isPermaLink="false">http://pingd.org/?p=319</guid>
		<description><![CDATA[So you&#8217;ve decided that you must run php as suPHP on your CentOS 6 based LAMP stack. This is a great idea for security on a multi-site or multi-user environment. Of course management panels like cPanel make running suPHP very &#8230; <a href="http://pingd.org/2013/suphp-on-centos-6-from-source-code.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>So you&#8217;ve decided that you must run php as suPHP on your CentOS 6 based LAMP stack. This is a great idea for security on a multi-site or multi-user environment. Of course management panels like cPanel make running suPHP very easy, but what about the rest of us? Many of us do not use cPanel, perhaps because of the cost or because it&#8217;s resource intensive. Personally I like cPanel as a product, but I choose to forgo cPanel on servers requiring a high degree of security in an effort to minimize the amount of services that must be secured and updated. However I still want things like suPHP. <span id="more-319"></span></p>
<p>Without cPanel your choices for suPHP on CentOS are either using RPMForge or building it from source. I personally don&#8217;t like having the standard repos, plus EPEL, plus RPMForge, so I typically will keep EPEL and opt for installing the other stuff from source in an effort to keep updates from conflicting. So let&#8217;s do it from source.</p>
<p>I&#8217;m assuming you already have apache running, perhaps with mod_php. If not go ahead and install it from yum and configure it to your liking. Set? Let&#8217;s go!</p>
<p>First let&#8217;s grab a copy of the latest suPHP and unpack it: <a href="http://www.suphp.org/Download.html">suPHP.org</a></p>
<pre class="brush: bash; title: ; notranslate">cd /root/
wget http://www.suphp.org/download/suphp-0.7.1.tar.gz
tar xvzpf suphp-0.7.1.tar.gz</pre>
<p>You will want to make sure you have all the compilers and developer tools needed to build stuff from source. We are assuming you have httpd installed and do NOT have php built from source, so we will make sure php is installed as well as httpd development tools:</p>
<pre class="brush: bash; title: ; notranslate">yum groupinstall &quot;Development Tools&quot;
yum install php php-devel php-mysql apr-devel httpd-devel</pre>
<p>Now let&#8217;s build this sucker and throw it into /opt/suphp:</p>
<pre class="brush: bash; title: ; notranslate">cd /root/suphp-0.7.1
./configure '--prefix=/opt/suphp' '--sysconfdir=/opt/suphp/etc' '--with-apr=/usr/bin/apr-1-config' '--with-apxs=/usr/sbin/apxs' '--with-apache-user=apache' '--with-setid-mode=owner' '--with-php=/usr/bin/php-cgi' '--with-logfile=/var/log/httpd/suphp_log' '--enable-SUPHP_USE_USERGROUP=yes'
make
make install</pre>
<p>If there were no errors through that entire process, you&#8217;re almost there. You will now find that mod_suphp.so has been installed in /usr/lib64/httpd/modules/mod_suphp.so (assuming you&#8217;re on x86_64.)</p>
<p>We must now modify the file /etc/httpd/conf.d/php.conf, clear it out and make it looks like so:</p>
<pre class="brush: bash; title: ; notranslate">#
# PHP is an HTML-embedded scripting language which attempts to make it
# easy for developers to write dynamically generated webpages.
#

LoadModule suphp_module modules/mod_suphp.so

suPHP_Engine on
AddType application/x-httpd-suphp .php5 .php .php3 .php2 .phtml
&lt;Directory /&gt;
    suPHP_AddHandler application/x-httpd-suphp
&lt;/Directory&gt;


DirectoryIndex index.php</pre>
<p>So for a final step let&#8217;s make a new directory and write a suphp.conf file:</p>
<pre class="brush: bash; title: ; notranslate">mkdir /opt/suphp/etc
nano -w /opt/suphp/etc/suphp.conf</pre>
<p>Setup the suphp.conf file as follows:</p>
<pre class="brush: bash; title: ; notranslate">[global]
logfile=/var/log/httpd/suphp.log
loglevel=info
webserver_user=apache
docroot=/
allow_file_group_writeable=true
allow_file_others_writeable=false
allow_directory_group_writeable=true
allow_directory_others_writeable=false
check_vhost_docroot=true
errors_to_browser=false
env_path=/bin:/usr/bin
umask=0077
min_uid=100
min_gid=100

[handlers]
application/x-httpd-suphp=&quot;php:/usr/bin/php-cgi&quot;
x-suphp-cgi=&quot;execute:!self&quot;</pre>
<p>Now you can restart Apache with the changes you made:</p>
<pre class="brush: bash; title: ; notranslate">service httpd restart</pre>
<p>If there were no errors displayed, you did well.</p>
<p>If you wish to test within your vhost that suphp is indeed working, try setting up a php script with the following content, place it in the webroot (i.e. public_html) and own it to the proper user (ie. &#8216;mywebuser&#8217;):</p>
<pre class="brush: php; title: ; notranslate">&lt;?php
	exec(&quot;touch /home/mywebuser/public_html/omg.txt&quot;);
	echo exec(&quot;ls -al /home/mywebuser/public_html/omg.txt&quot;);
?&gt;</pre>
<p>When you visit that page it should create a file called omg.txt and show you that it&#8217;s owned by the &#8216;mywebuser&#8217;. This means that PHP ran as the proper user. You can also debug and see which user stuff runs as via the /var/log/httpd/suphp.log</p>
<p>Have fun!</p>
]]></content:encoded>
			<wfw:commentRss>http://pingd.org/2013/suphp-on-centos-6-from-source-code.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AWK to win friends and influence women</title>
		<link>http://pingd.org/2012/awk-to-win-friends-and-influence-women.html</link>
		<comments>http://pingd.org/2012/awk-to-win-friends-and-influence-women.html#comments</comments>
		<pubDate>Fri, 26 Oct 2012 01:30:04 +0000</pubDate>
		<dc:creator>pingd</dc:creator>
				<category><![CDATA[Bash One-Liners]]></category>
		<category><![CDATA[/dev/urandom]]></category>
		<category><![CDATA[awk]]></category>
		<category><![CDATA[awk script]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[bash script]]></category>
		<category><![CDATA[head]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[oneliner]]></category>
		<category><![CDATA[onliners]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[substr]]></category>
		<category><![CDATA[tolower]]></category>
		<category><![CDATA[tr]]></category>

		<guid isPermaLink="false">http://pingd.org/?p=304</guid>
		<description><![CDATA[AWK is a powerful tool, a language really, that every administrator needs to know. I recommend everyone read about awk and learn how to use it. It can really make your day when you need to do something, quick and &#8230; <a href="http://pingd.org/2012/awk-to-win-friends-and-influence-women.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>AWK is a powerful tool, a language really, that every administrator needs to know. I recommend everyone read about awk and learn how to use it. It can really make your day when you need to do something, quick and dirty. </p>
<p>You will definitely win some friends with your awk skills, but probably not too many women <img src='http://pingd.org/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> .<span id="more-304"></span></p>
<p>I recently had to add a large volume of users to a database. Each user would need a username, password, and their full name entered into the database. I was only given their first and last name. There was no interface to use in order to register these users, hence why the project fell to me.</p>
<p>Like any good admin, I didn&#8217;t feel like writing queries and entering made up passwords by hand. AWK came to the rescue. Here is what I was given:</p>
<pre class="brush: bash; title: ; notranslate">
[root@secure ~]# cat /tmp/test
Napoleon Ravelo
Nella Faucher
Mira Penrose
Jeanmarie Hadfield
Earnest Chillemi
Gloria Grays
Nila Carvajal
Edie Higuchi
Alfredo Baskerville
Hildegarde Bent
Bryanna Faunce
Garnett Godsey
Christene Topping
Trenton Conti
Tereasa Noell
Lara Rudnick
Lonnie Ells
Renata Brogden
Latrisha Bara
Yuonne Granado
[root@secure~]#
</pre>
<p>I decided I would use awk&#8217;s variable functionality along with /dev/urandom and tr to generate unique passwords for each user, for security. Furthermore I used the awk tolower and substr functions to generate usernames. I wanted something like:</p>
<pre class="brush: bash; title: ; notranslate">Latrisha Bra, ojSkl32Fjk213, lbra</pre>
<p>But in a query format. I decided to go ahead and make my dirty awk script along with a bash while loop to generate some queries!</p>
<pre class="brush: bash; title: ; notranslate">
[root@secure~]# cat /tmp/test | while read LINE; do echo $LINE | awk -v pass=`cat /dev/urandom |tr -cd &quot;[:alnum:]&quot; | head -c ${1:-18}` '{print &quot;INSERT IGNORE personnel(fullname,password,username,company,admin,valid) VALUES('&quot;'&quot;'&quot; $1 &quot; &quot; $2 &quot;'&quot;'&quot;'&quot; &quot;,md5('&quot;'&quot;'&quot; pass &quot;'&quot;'&quot;'),&quot; &quot;'&quot;'&quot;'&quot; tolower(substr($1,0,1)) tolower($2)&quot;'&quot;'&quot;'&quot; &quot;,4,0,1);&quot;}'; done
INSERT IGNORE personnel(fullname,password,username,company,admin,valid) VALUES('Napoleon Ravelo',md5('bxZwqeZRs13udaifeG'),'nravelo',4,0,1);
INSERT IGNORE personnel(fullname,password,username,company,admin,valid) VALUES('Nella Faucher',md5('dXFxcg57IhFvYhweQ8'),'nfaucher',4,0,1);
INSERT IGNORE personnel(fullname,password,username,company,admin,valid) VALUES('Mira Penrose',md5('bB1ZZIZILctCbJOl3w'),'mpenrose',4,0,1);
INSERT IGNORE personnel(fullname,password,username,company,admin,valid) VALUES('Jeanmarie Hadfield',md5('uo4jfydvHAx8nRKeIt'),'jhadfield',4,0,1);
INSERT IGNORE personnel(fullname,password,username,company,admin,valid) VALUES('Earnest Chillemi',md5('x5ePNOKHfbzefT0peS'),'echillemi',4,0,1);
INSERT IGNORE personnel(fullname,password,username,company,admin,valid) VALUES('Gloria Grays',md5('h0GNUNQKVx7N0OTRQZ'),'ggrays',4,0,1);
INSERT IGNORE personnel(fullname,password,username,company,admin,valid) VALUES('Nila Carvajal',md5('p8D0epKBtiw465boYR'),'ncarvajal',4,0,1);
INSERT IGNORE personnel(fullname,password,username,company,admin,valid) VALUES('Edie Higuchi',md5('oqMx0RAbvoW7uhQgGk'),'ehiguchi',4,0,1);
INSERT IGNORE personnel(fullname,password,username,company,admin,valid) VALUES('Alfredo Baskerville',md5('9yB6EANilg1MxPMoec'),'abaskerville',4,0,1);
INSERT IGNORE personnel(fullname,password,username,company,admin,valid) VALUES('Hildegarde Bent',md5('yqyjy7GTXcIXS1YKRM'),'hbent',4,0,1);
INSERT IGNORE personnel(fullname,password,username,company,admin,valid) VALUES('Bryanna Faunce',md5('tXNxf3uuY8I3wrgh6B'),'bfaunce',4,0,1);
INSERT IGNORE personnel(fullname,password,username,company,admin,valid) VALUES('Garnett Godsey',md5('HBqNV7b8bODo6HXGOb'),'ggodsey',4,0,1);
INSERT IGNORE personnel(fullname,password,username,company,admin,valid) VALUES('Christene Topping',md5('fD0TSAxFLRNkqcqTR5'),'ctopping',4,0,1);
INSERT IGNORE personnel(fullname,password,username,company,admin,valid) VALUES('Trenton Conti',md5('lcp1BaQQBmPlvvWpaM'),'tconti',4,0,1);
INSERT IGNORE personnel(fullname,password,username,company,admin,valid) VALUES('Tereasa Noell',md5('7NNSYf3lbh0ZLOFTQt'),'tnoell',4,0,1);
INSERT IGNORE personnel(fullname,password,username,company,admin,valid) VALUES('Lara Rudnick',md5('BXuuSHRmZXKpY4h2B7'),'lrudnick',4,0,1);
INSERT IGNORE personnel(fullname,password,username,company,admin,valid) VALUES('Lonnie Ells',md5('fsIG0n7MoagoHshV2H'),'lells',4,0,1);
INSERT IGNORE personnel(fullname,password,username,company,admin,valid) VALUES('Renata Brogden',md5('aFZGu0LzjjDurpxd10'),'rbrogden',4,0,1);
INSERT IGNORE personnel(fullname,password,username,company,admin,valid) VALUES('Latrisha Bara',md5('KQQvumZBdrWAqN0ZzP'),'lbara',4,0,1);
INSERT IGNORE personnel(fullname,password,username,company,admin,valid) VALUES('Yuonne Granado',md5('to6eCOFhJ6CS9Eav4K'),'ygranado',4,0,1);
[root@secure ~]# 
</pre>
<p>Here is the full dirty one-liner broken down into steps:</p>
<pre class="brush: bash; title: ; notranslate">
cat /tmp/test | while read LINE; # Start our loop
do echo $LINE | # Echo each line into a pipe
# Call awk and define a password variable
# the password variable uses /dev/urandom
# and tr to generate a password, we use
# head to get 18 characters only.
awk -v pass=`cat /dev/urandom |tr -cd &quot;[:alnum:]&quot; | head -c ${1:-18}`
# Now we start printing the query:
'{print &quot;INSERT IGNORE personnel(fullname,password,username,company,admin,valid)
# Now we start adding the query variables:
VALUES('&quot;'&quot;'&quot; $1 &quot; &quot; $2 &quot;'&quot;'&quot;'&quot; &quot;,md5('&quot;'&quot;'&quot; pass &quot;'&quot;'&quot;'),&quot; &quot;'&quot;'&quot;'&quot; 
# We need to make the username variable now
# we use tolower and substr to make it the
# first letter of their first name and their
# last name:
tolower(substr($1,0,1)) tolower($2)&quot;'&quot;'&quot;'&quot; &quot;,4,0,1);&quot;}';
done # End the loop
</pre>
<p>And this is why we should all know awk. The sample list I used here was only 20 names, imagine if it were thousands or tens of thousands, there is no way it could have been done by hand, and the awk script was quicker to make than writing a perl or php script to do the same thing. It took just a few minutes <img src='http://pingd.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
]]></content:encoded>
			<wfw:commentRss>http://pingd.org/2012/awk-to-win-friends-and-influence-women.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>CRON ERROR: failed to open PAM security session: Protocol not supported</title>
		<link>http://pingd.org/2012/cron-error-failed-to-open-pam-security-session-protocol-not-supported.html</link>
		<comments>http://pingd.org/2012/cron-error-failed-to-open-pam-security-session-protocol-not-supported.html#comments</comments>
		<pubDate>Sat, 13 Oct 2012 01:31:43 +0000</pubDate>
		<dc:creator>pingd</dc:creator>
				<category><![CDATA[Linux Guides]]></category>
		<category><![CDATA[cron error]]></category>
		<category><![CDATA[crond]]></category>
		<category><![CDATA[crons]]></category>
		<category><![CDATA[hard limit]]></category>
		<category><![CDATA[limits.conf]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[maxlogins]]></category>
		<category><![CDATA[pam]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[ulimit]]></category>
		<category><![CDATA[ulimits]]></category>

		<guid isPermaLink="false">http://pingd.org/?p=301</guid>
		<description><![CDATA[Got an interesting report of an error on one of our servers. I was told crons for a user account on our server weren&#8217;t running. I tailed the cron log (/var/log/cron) and came to find these errors: I&#8217;ve never seen &#8230; <a href="http://pingd.org/2012/cron-error-failed-to-open-pam-security-session-protocol-not-supported.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Got an interesting report of an error on one of our servers. I was told crons for a user account on our server weren&#8217;t running. I tailed  the cron log (/var/log/cron) and came to find these errors:</p>
<pre class="brush: bash; title: ; notranslate">Oct 13 06:32:01 secure crond[4558]: CRON (clients) ERROR: failed to open PAM security session: Protocol not supported
Oct 13 06:32:01 secure crond[4558]: CRON (clients) ERROR: cannot set security context</pre>
<p><span id="more-301"></span><br />
I&#8217;ve never seen the error before. I dug around in various PAM and related security configs, but didn&#8217;t see any issues. I then wanted to run the cron manually via the user, and tried to sudo down into the user&#8217;s account.</p>
<pre class="brush: bash; title: ; notranslate">[root@secure~]# sudo su - clients
Too many logins for 'clients'.
could not open session
[root@secure~]#</pre>
<p>There is the problem! Cron can&#8217;t run because two techs were logged into the &#8216;clients&#8217; user account and it was being limited. In this case I decided to bump the limit to 5 users. Here is what I did:</p>
<pre class="brush: bash; title: ; notranslate">[root@secure~]# nano -w /etc/security/limits.conf</pre>
<p>Now I added the following line:</p>
<pre class="brush: bash; title: ; notranslate">clients	hard	maxlogins	5</pre>
<p>The crons were now running, problem solved. </p>
]]></content:encoded>
			<wfw:commentRss>http://pingd.org/2012/cron-error-failed-to-open-pam-security-session-protocol-not-supported.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ZFS on Linux RC10 released!</title>
		<link>http://pingd.org/2012/zfs-on-linux-rc10-released.html</link>
		<comments>http://pingd.org/2012/zfs-on-linux-rc10-released.html#comments</comments>
		<pubDate>Thu, 16 Aug 2012 21:52:02 +0000</pubDate>
		<dc:creator>pingd</dc:creator>
				<category><![CDATA[Linux Guides]]></category>
		<category><![CDATA[linux zfs]]></category>
		<category><![CDATA[new zfs released]]></category>
		<category><![CDATA[spl]]></category>
		<category><![CDATA[zfs]]></category>
		<category><![CDATA[zfs 0.6.0-rc10]]></category>
		<category><![CDATA[zfs on centos]]></category>
		<category><![CDATA[zfs on linux]]></category>

		<guid isPermaLink="false">http://pingd.org/?p=296</guid>
		<description><![CDATA[The ZFS on linux team has released a new version of SPL and ZFS with multiple benefits to users. The new version is 0.6.0-rc10 and our guide found here is being updated now: Installing ZFS RAID-Z on CentOS 6.2 with &#8230; <a href="http://pingd.org/2012/zfs-on-linux-rc10-released.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>The ZFS on linux team has released a new version of SPL and ZFS with multiple benefits to users. The new version is 0.6.0-rc10 and our guide found here is being updated now:</p>
<p><a href="http://pingd.org/2012/installing-zfs-raid-z-on-centos-6-2-with-ssd-caching.html">Installing ZFS RAID-Z on CentOS 6.2 with SSD Caching</a></p>
]]></content:encoded>
			<wfw:commentRss>http://pingd.org/2012/zfs-on-linux-rc10-released.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pick random line from text file with bash and shuf.</title>
		<link>http://pingd.org/2012/pick-random-line-from-text-file-with-bash-and-shuf.html</link>
		<comments>http://pingd.org/2012/pick-random-line-from-text-file-with-bash-and-shuf.html#comments</comments>
		<pubDate>Sun, 15 Jul 2012 06:44:11 +0000</pubDate>
		<dc:creator>pingd</dc:creator>
				<category><![CDATA[Bash One-Liners]]></category>
		<category><![CDATA[Linux Guides]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[coreutils]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[random]]></category>
		<category><![CDATA[random line]]></category>
		<category><![CDATA[shuf]]></category>
		<category><![CDATA[text lists]]></category>
		<category><![CDATA[text manipulation]]></category>

		<guid isPermaLink="false">http://pingd.org/?p=293</guid>
		<description><![CDATA[So lets say you have a text file called list.txt with entries like: What if you wanted to pick a random entry? The easiest solution is to use the &#8216;shuf&#8217; tool, which is standard on CentOS as part of coreutils. &#8230; <a href="http://pingd.org/2012/pick-random-line-from-text-file-with-bash-and-shuf.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>So lets say you have a text file called list.txt with entries like:</p>
<pre class="brush: bash; title: ; notranslate">
apple
orange
peach
pear
strawberry
grape
lemon
lime
</pre>
<p>What if you wanted to pick a random entry? The easiest solution is to use the &#8216;shuf&#8217; tool, which is standard on CentOS as part of coreutils.</p>
<pre class="brush: bash; title: ; notranslate">
shuf -n 1 list.txt
</pre>
<p>The output would be a random line from our file!</p>
]]></content:encoded>
			<wfw:commentRss>http://pingd.org/2012/pick-random-line-from-text-file-with-bash-and-shuf.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New ZFS on Linux release (RC9).</title>
		<link>http://pingd.org/2012/new-zfs-on-linux-release-rc9.html</link>
		<comments>http://pingd.org/2012/new-zfs-on-linux-release-rc9.html#comments</comments>
		<pubDate>Fri, 15 Jun 2012 07:20:39 +0000</pubDate>
		<dc:creator>pingd</dc:creator>
				<category><![CDATA[Linux Guides]]></category>
		<category><![CDATA[updated guide]]></category>
		<category><![CDATA[zfs]]></category>
		<category><![CDATA[zfs on centos]]></category>
		<category><![CDATA[zfs on linux]]></category>
		<category><![CDATA[zfs rc9]]></category>

		<guid isPermaLink="false">http://pingd.org/?p=288</guid>
		<description><![CDATA[We have one of the most comprehensive guides on the internet for ZFS. Please check the updated guide for assistance with installing ZFS on Linux, specifically CentOS 6.2 here: Installing ZFS RAID-Z on CentOS 6.2 with SSD Caching]]></description>
				<content:encoded><![CDATA[<p>We have one of the most comprehensive guides on the internet for ZFS. Please check the updated guide for assistance with installing ZFS on Linux, specifically CentOS 6.2 here:</p>
<p><a href="http://pingd.org/2012/installing-zfs-raid-z-on-centos-6-2-with-ssd-caching.html">Installing ZFS RAID-Z on CentOS 6.2 with SSD Caching</a></p>
]]></content:encoded>
			<wfw:commentRss>http://pingd.org/2012/new-zfs-on-linux-release-rc9.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>No module named cElementTree yum update error</title>
		<link>http://pingd.org/2012/no-module-named-celementtree-yum-update-error.html</link>
		<comments>http://pingd.org/2012/no-module-named-celementtree-yum-update-error.html#comments</comments>
		<pubDate>Mon, 04 Jun 2012 20:43:30 +0000</pubDate>
		<dc:creator>pingd</dc:creator>
				<category><![CDATA[Linux Guides]]></category>
		<category><![CDATA[cElementTree]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[centos updates]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[python-elementtree]]></category>
		<category><![CDATA[yum]]></category>
		<category><![CDATA[yum updates]]></category>

		<guid isPermaLink="false">http://pingd.org/?p=280</guid>
		<description><![CDATA[Found yum broken on a legacy CentOS 5.x server while installing updates. The error was: root # yum update There was a problem importing one of the Python modules required to run yum. The error leading to this problem was: &#8230; <a href="http://pingd.org/2012/no-module-named-celementtree-yum-update-error.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Found yum broken on a legacy CentOS 5.x server while installing updates. The error was:</p>
<pre>root # yum update
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:

   No module named cElementTree

Please install a package which provides this module, or
verify that the module is installed correctly.

It's possible that the above module doesn't match the
current version of Python, which is:
2.4.3 (#1, May  5 2011, 16:39:10) 
[GCC 4.1.2 20080704 (Red Hat 4.1.2-50)]

If you cannot solve this problem yourself, please go to 
the yum faq at:

http://wiki.linux.duke.edu/YumFaq

root #</pre>
<p>The fix was actually pretty simple, you have an incorrect version of python-elementtree installed. You will need to get the proper version from the CentOS mirror (for your version of CentOS). Here is what I did for CentOS 5.7 on x86_64:</p>
<pre class="brush: bash; title: ; notranslate">wget http://mirrors.usc.edu/pub/linux/distributions/centos/5.7/os/x86_64/CentOS/python-elementtree-1.2.6-5.x86_64.rpm
rpm -Uvh --oldpackage python-elementtree-1.2.6-5.x86_64.rpm</pre>
<p>After that yum worked just fine! Note, if you&#8217;re still having trouble check /etc/redhat-release for your current version of CentOS and uname -a for your architecture type.</p>
]]></content:encoded>
			<wfw:commentRss>http://pingd.org/2012/no-module-named-celementtree-yum-update-error.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced
Database Caching 4/12 queries in 0.004 seconds using disk

 Served from: pingd.org @ 2013-06-19 03:55:04 by W3 Total Cache -->