<?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>Seventh Sense &#187; Scripts</title>
	<atom:link href="http://sgowtham.net/blog/category/technology/scripts/feed/" rel="self" type="application/rss+xml" />
	<link>http://sgowtham.net/blog</link>
	<description>Rambling about life&#039;s little things, in 7 ≡ 1 (mod 6) fashion</description>
	<lastBuildDate>Tue, 28 Feb 2012 23:25:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<image>
	<title>Seventh Sense</title>
	<url>http://sgowtham.net/images/sg_logo_rss.png</url>
	<link>http://sgowtham.net/blog</link>
	<width>32</width>
	<height>32</height>
	</image>
		<item>
		<title>HPCC 1.4.1 Benchmark With GCC 4.1.2 On Rocks 5.4.2</title>
		<link>http://sgowtham.net/blog/2012/02/28/hpcc-1-4-1-benchmark-with-gcc-4-1-2-on-rocks-5-4-2/</link>
		<comments>http://sgowtham.net/blog/2012/02/28/hpcc-1-4-1-benchmark-with-gcc-4-1-2-on-rocks-5-4-2/#comments</comments>
		<pubDate>Tue, 28 Feb 2012 18:27:14 +0000</pubDate>
		<dc:creator>Gowtham</dc:creator>
				<category><![CDATA[BASH]]></category>
		<category><![CDATA[Clusters]]></category>
		<category><![CDATA[HPCC]]></category>
		<category><![CDATA[HPL]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[MPI]]></category>
		<category><![CDATA[Rocks]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://sgowtham.net/blog/?p=3411</guid>
		<description><![CDATA[Disclaimer The instructions/steps given below worked for me (and Michigan Technological University) running NPACI Rocks 5.4.2 (with CentOS 5.5) &#8211; as has been a common practice for several years now, a full version of Operating System was installed. These instructions may very well work for you (or your institution), on Rocks-like or other linux clusters. [...]]]></description>
			<content:encoded><![CDATA[<h3 class="blog">Disclaimer</h3>
<p>The instructions/steps given below worked for me (and <a href="http://www.mtu.edu/" target="_blank" class="underline">Michigan Technological University</a>) running <a href="http://www.rocksclusters.org/" class="underline" target="_blank">NPACI Rocks</a> 5.4.2 (with CentOS 5.5) &#8211; as has been a common practice for several years now, a full version of Operating System was installed. These instructions may very well work for you (or your institution), on Rocks-like or other linux clusters. Please note that if you decide to use these instructions on your machine, you are doing so entirely at your very own discretion and that neither this site, <em>sgowtham.net</em>, nor its author (or Michigan Technological University) is responsible for any/all damage – intellectual and/or otherwise.</p>
<p><br clear="all"></p>
<h3 class="blog">A Bit About HPCC</h3>
<p>Citing <a href="http://icl.cs.utk.edu/hpcc/" target="_blank" clas="underline">HPCC website</a>,</p>
<blockquote><p>
HPCC benchmark suite has been released by <a href="http://www.darpa.mil/Our_Work/MTO/Programs/High_Productivity_Computing_Systems_%28HPCS%29.aspx" target="_blank" class="underline">DARPA High Productivity Computing Systems (HPCS)</a> program to help define the performance boundaries of future Petascale computing systems. HPCC is a suite of tests that examine the performance of HPC architectures using kernels with memory access patterns more challenging than those of the HPL benchmark used in <a href="http://www.top500.org/" target="_blank" class="underline">Top500</a>. This suite is designed to augment the list, providing benchmarks that bound the performance of many real applications as a function of memory access characteristics. For e.g., spatial and temporal locality, and providing a framework for including additional tests. HPCC consists of seven tests that attempt to span high and low spatial and temporal locality space. </p>
<p>By design, the HPCC tests are scalable with the size of data sets being a function of the largest HPL matrix tested for the system. Since HPCC kernels consist of simple mathematical operations, it provides a unique opportunity to look at language and parallel programming issues. To characterize the architecture of the system, the following three scenarios are considered:</p>
<ol>
<li><strong>Local</strong> &#8211; only a single processor is performing the computations</li>
<li><strong><a href="http://en.wikipedia.org/wiki/Embarrassingly_parallel" target="_blank" class="underline">Embarrassingly Parallel</a></strong> &#8211; each processor in the entire system is performing the computations but without explicit communication with each other</li>
<li><strong>Global</strong> &#8211; all processors in the system are performing the computations with explicit communication with each other</li>
</ol>
<p>The seven tests that make up HPCC benchmark are as follows:</p>
<ol>
<li><strong><a href="http://www.netlib.org/benchmark/hpl/" target="_blank" class="underline">HPL</a></strong> &#8211; the Linpack TPP benchmark which measures the floating point rate of execution for solving a linear system of equations</li>
<li><strong><a href="http://en.wikipedia.org/wiki/General_Matrix_Multiply" target="_blank" class="underline">DGEMM</a></strong> &#8211; measures the floating point rate of execution of double precision real matrix-matrix multiplication</li>
<li><strong><a href="http://www.cs.virginia.edu/stream/" target="_blank" class="underline">STREAM</a></strong> &#8211; a simple synthetic benchmark program that measures sustainable memory bandwidth (in GB/s) and the corresponding computation rate for simple vector kernel</li>
<li><strong><a href="http://www.netlib.org/parkbench/html/matrix-kernels.html" target="_blank" class="underline">PTRANS</a> (parallel matrix transpose)</strong> &#8211; exercises the communications where pairs of processors communicate with each other simultaneously. It is a useful test of the total communications capacity of the network</li>
<li><strong><a href="http://icl.cs.utk.edu/projectsfiles/hpcc/RandomAccess/" target="_blank" class="underline">RandomAccess</a></strong> &#8211; measures the rate of integer random updates of memory (GUPS)</li>
<li><strong><a href="http://www.ffte.jp/" target="_blank" class="underline">FFT</a></strong> &#8211; measures the floating point rate of execution of double precision complex one-dimensional Discrete Fourier Transform (DFT)</li>
<li><strong><a href="https://fs.hlrs.de/projects/par/mpi/b_eff/" target="_blank" class="underline">Communication bandwidth and latency</a></strong> &#8211; a set of tests to measure latency and bandwidth of a number of simultaneous communication patterns; based on b<sub>eff</sub> (effective bandwidth benchmark)</li>
</ol>
</blockquote>
<p><br clear="all"></p>
<h3 class="blog">Pre-requisites: MPI &#038; Goto BLAS</h3>
<p>Please refer to the corresponding sections in <a href="http://sgowtham.net/blog/2012/02/27/hpl-2-0-benchmark-with-gcc-4-1-2-on-rocks-5-4-2/" class="underline" target="_blank">HPL 2.0 Benchmark With GCC 4.1.2 On Rocks 5.4.2</a> to learn more about required pre-requisites as well as instructions for installing/compiling them. Following Rocks recommendations, pre-requisites will be installed under <code>/share/apps/</code>; software installed by me, in clusters at Michigan Tech, have the following template for their folder structure:</p>
<p class="bpcaption"><code>/share/apps/Software/Software_Version/Compiler/Compiler_Version</code></p>
<p><br clear="all"></p>
<h3 class="blog">HPCC Installation/Compilation</h3>
<p>With MPICH2 and Goto BLAS2 in place, HPCC 1.4.1 will be installed under</p>
<p class="bpcaption"><code>/share/apps/hpcc/1.4.1/mpich2/1.4.1p1/gcc/4.1.2</code></p>
<p><br clear="all"><br />
The following script, used in installation, will assume that one has downloaded HPCC 1.4.1 from <a href="http://icl.cs.utk.edu/hpcc/software/" target="_blank" class="underline">here</a> &#038; the necessary <code>Make.MPICH2141p1_GCC412.HPCC</code> (listed below; it does look identical to the one used when compiling HPL 2.0 &#8211; the only difference is in the definition of <code>TOPdir</code> variable) and placed them in <code>/share/apps/tmp/</code></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
</pre></td><td class="code"><pre class="make" style="font-family:monospace;"><span style="color: #339900; font-style: italic;">#</span>
<span style="color: #339900; font-style: italic;"># Makefile (Make.MPICH2141p1_GCC412) used to compile HPCC </span>
<span style="color: #339900; font-style: italic;"># on HPC clusters running NPACI Rocks (5.4.2) with CentOS (5.5)</span>
<span style="color: #339900; font-style: italic;"># at Michigan Technological University.</span>
<span style="color: #339900; font-style: italic;"># </span>
<span style="color: #339900; font-style: italic;"># Disclaimer:</span>
<span style="color: #339900; font-style: italic;"># Please note that you are using these instructions </span>
<span style="color: #339900; font-style: italic;"># at your very own risk and that Michigan Technological</span>
<span style="color: #339900; font-style: italic;"># University is not responsible for any/all damage caused to </span>
<span style="color: #339900; font-style: italic;"># your property, intellectual or otherwise.</span>
<span style="color: #339900; font-style: italic;"># </span>
<span style="color: #339900; font-style: italic;"># For additional help and/or comments, questions, suggestions,</span>
<span style="color: #339900; font-style: italic;"># please contact </span>
<span style="color: #339900; font-style: italic;">#</span>
<span style="color: #339900; font-style: italic;"># Gowtham</span>
<span style="color: #339900; font-style: italic;"># Information Technology Services &amp; Security</span>
<span style="color: #339900; font-style: italic;"># Michigan Technological University</span>
<span style="color: #339900; font-style: italic;"># g@mtu.edu</span>
<span style="color: #339900; font-style: italic;">#</span>
<span style="color: #339900; font-style: italic;"># * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *</span>
<span style="color: #339900; font-style: italic;">#</span>
<span style="color: #339900; font-style: italic;">#</span>
<span style="color: #339900; font-style: italic;">#  -- High Performance Computing Linpack Benchmark (HPL)                </span>
<span style="color: #339900; font-style: italic;">#     HPL - 2.0 - September 10, 2008                          </span>
<span style="color: #339900; font-style: italic;">#     Antoine P. Petitet                                                </span>
<span style="color: #339900; font-style: italic;">#     University of Tennessee, Knoxville                                </span>
<span style="color: #339900; font-style: italic;">#     Innovative Computing Laboratory                                 </span>
<span style="color: #339900; font-style: italic;">#     (C) Copyright 2000-2008 All Rights Reserved                       </span>
<span style="color: #339900; font-style: italic;">#                                                                       </span>
<span style="color: #339900; font-style: italic;">#  -- Copyright notice and Licensing terms:                             </span>
<span style="color: #339900; font-style: italic;">#                                                                       </span>
<span style="color: #339900; font-style: italic;">#  Redistribution and use in source and binary forms, with or without</span>
<span style="color: #339900; font-style: italic;">#  modification, are permitted provided that the following conditions</span>
<span style="color: #339900; font-style: italic;">#  are met:                                                             </span>
<span style="color: #339900; font-style: italic;">#                                                                       </span>
<span style="color: #339900; font-style: italic;">#  1. Redistributions of source code must retain the above copyright</span>
<span style="color: #339900; font-style: italic;">#  notice, this list of conditions and the following disclaimer.        </span>
<span style="color: #339900; font-style: italic;">#                                                                       </span>
<span style="color: #339900; font-style: italic;">#  2. Redistributions in binary form must reproduce the above copyright</span>
<span style="color: #339900; font-style: italic;">#  notice, this list of conditions, and the following disclaimer in the</span>
<span style="color: #339900; font-style: italic;">#  documentation and/or other materials provided with the distribution. </span>
<span style="color: #339900; font-style: italic;">#                                                                       </span>
<span style="color: #339900; font-style: italic;">#  3. All advertising materials mentioning features or use of this</span>
<span style="color: #339900; font-style: italic;">#  software must display the following acknowledgement:                 </span>
<span style="color: #339900; font-style: italic;">#  This product includes software developed at the University of</span>
<span style="color: #339900; font-style: italic;">#  Tennessee, Knoxville, Innovative Computing Laboratory.             </span>
<span style="color: #339900; font-style: italic;">#                                                                       </span>
<span style="color: #339900; font-style: italic;">#  4. The name of the University, the name of the Laboratory, or the</span>
<span style="color: #339900; font-style: italic;">#  names of its contributors may not be used to endorse or promote</span>
<span style="color: #339900; font-style: italic;">#  products derived from this software without specific written</span>
<span style="color: #339900; font-style: italic;">#  permission.</span>
<span style="color: #339900; font-style: italic;">#</span>
<span style="color: #339900; font-style: italic;">#  -- Disclaimer:</span>
<span style="color: #339900; font-style: italic;">#                                                                       </span>
<span style="color: #339900; font-style: italic;">#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS</span>
<span style="color: #339900; font-style: italic;">#  ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT</span>
<span style="color: #339900; font-style: italic;">#  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR</span>
<span style="color: #339900; font-style: italic;">#  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY</span>
<span style="color: #339900; font-style: italic;">#  OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,</span>
<span style="color: #339900; font-style: italic;">#  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT</span>
<span style="color: #339900; font-style: italic;">#  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,</span>
<span style="color: #339900; font-style: italic;">#  DATA OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY</span>
<span style="color: #339900; font-style: italic;">#  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT</span>
<span style="color: #339900; font-style: italic;">#  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE</span>
<span style="color: #339900; font-style: italic;">#  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span>
<span style="color: #339900; font-style: italic;">#  </span>
&nbsp;
<span style="color: #339900; font-style: italic;">#</span>
<span style="color: #339900; font-style: italic;"># Shell Details</span>
SHELL        <span style="color: #004400;">=</span> <span style="color: #004400;">/</span>bin<span style="color: #004400;">/</span>sh
CD           <span style="color: #004400;">=</span> cd
CP           <span style="color: #004400;">=</span> cp
LN_S         <span style="color: #004400;">=</span> ln <span style="color: #004400;">-</span>s
MKDIR        <span style="color: #004400;">=</span> mkdir
RM           <span style="color: #004400;">=</span> <span style="color: #004400;">/</span>bin<span style="color: #004400;">/</span>rm <span style="color: #004400;">-</span>f
TOUCH        <span style="color: #004400;">=</span> touch
&nbsp;
<span style="color: #339900; font-style: italic;">#</span>
<span style="color: #339900; font-style: italic;"># Platform Identifier</span>
ARCH         <span style="color: #004400;">=</span> MPICH2141p1_GCC412
&nbsp;
<span style="color: #339900; font-style: italic;">#</span>
<span style="color: #339900; font-style: italic;"># HPL Directory Structure / HPL library</span>
TOPdir       <span style="color: #004400;">=</span> <span style="color: #004400;">../../..</span>
INCdir       <span style="color: #004400;">=</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">TOPdir</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">/</span><span style="color: #666622; font-weight: bold;">include</span>
BINdir       <span style="color: #004400;">=</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">TOPdir</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">/</span>bin<span style="color: #004400;">/$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">ARCH</span><span style="color: #004400;">&#41;</span>
LIBdir       <span style="color: #004400;">=</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">TOPdir</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">/</span>lib<span style="color: #004400;">/$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">ARCH</span><span style="color: #004400;">&#41;</span>
HPLlib       <span style="color: #004400;">=</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">LIBdir</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">/</span>libhpl<span style="color: #004400;">.</span>a 
&nbsp;
<span style="color: #339900; font-style: italic;">#</span>
<span style="color: #339900; font-style: italic;"># Message Passing library (MPI)</span>
MPdir        <span style="color: #004400;">=</span> <span style="color: #004400;">/</span>share<span style="color: #004400;">/</span>apps<span style="color: #004400;">/</span>mpich2<span style="color: #004400;">/</span>1<span style="color: #004400;">.</span>4<span style="color: #004400;">.</span>1p1<span style="color: #004400;">/</span>gcc<span style="color: #004400;">/</span>4<span style="color: #004400;">.</span>1<span style="color: #004400;">.</span>2
MPinc        <span style="color: #004400;">=</span> <span style="color: #004400;">-</span>I<span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">MPdir</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">/</span><span style="color: #666622; font-weight: bold;">include</span>
MPlib        <span style="color: #004400;">=</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">MPdir</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">/</span>lib<span style="color: #004400;">/</span>libmpich<span style="color: #004400;">.</span>a
&nbsp;
<span style="color: #339900; font-style: italic;">#</span>
<span style="color: #339900; font-style: italic;"># Linear Algebra library (BLAS)</span>
LAlib        <span style="color: #004400;">=</span> <span style="color: #004400;">/</span>share<span style="color: #004400;">/</span>apps<span style="color: #004400;">/</span>gotoblas2<span style="color: #004400;">/</span><span style="color: #CC2200;">1.13</span><span style="color: #004400;">/</span>gcc<span style="color: #004400;">/</span>4<span style="color: #004400;">.</span>1<span style="color: #004400;">.</span>2<span style="color: #004400;">/</span>libgoto2<span style="color: #004400;">.</span>a
&nbsp;
<span style="color: #339900; font-style: italic;">#</span>
<span style="color: #339900; font-style: italic;"># F77 / C Interface</span>
<span style="color: #339900; font-style: italic;"># You can skip this section if and only if you are not planning to use</span>
<span style="color: #339900; font-style: italic;"># a BLAS library featuring a Fortran 77 interface. Otherwise, it is</span>
<span style="color: #339900; font-style: italic;"># necessary to fill out the F2CDEFS variable with the appropriate</span>
<span style="color: #339900; font-style: italic;"># options. **One and only one** option should be chosen in **each** of</span>
<span style="color: #339900; font-style: italic;"># the 3 following categories:</span>
<span style="color: #339900; font-style: italic;">#</span>
<span style="color: #339900; font-style: italic;"># 1) name space (How C calls a Fortran 77 routine)</span>
<span style="color: #339900; font-style: italic;">#</span>
<span style="color: #339900; font-style: italic;"># -DAdd_              : all lower case and a suffixed underscore (Suns,</span>
<span style="color: #339900; font-style: italic;">#                       Intel, ...) [default]</span>
<span style="color: #339900; font-style: italic;"># -DNoChange          : all lower case (IBM RS6000)</span>
<span style="color: #339900; font-style: italic;"># -DUpCase            : all upper case (Cray)</span>
<span style="color: #339900; font-style: italic;"># -DAdd__             : the FORTRAN compiler in use is f2c</span>
<span style="color: #339900; font-style: italic;">#</span>
<span style="color: #339900; font-style: italic;"># 2) C and Fortran 77 integer mapping</span>
<span style="color: #339900; font-style: italic;">#</span>
<span style="color: #339900; font-style: italic;"># -DF77_INTEGER=int   : Fortran 77 INTEGER is a C int [default]</span>
<span style="color: #339900; font-style: italic;"># -DF77_INTEGER=long  : Fortran 77 INTEGER is a C long</span>
<span style="color: #339900; font-style: italic;"># -DF77_INTEGER=short : Fortran 77 INTEGER is a C short</span>
<span style="color: #339900; font-style: italic;">#</span>
<span style="color: #339900; font-style: italic;"># 3) Fortran 77 string handling</span>
<span style="color: #339900; font-style: italic;">#</span>
<span style="color: #339900; font-style: italic;"># -DStringSunStyle    : The string address is passed at the string location</span>
<span style="color: #339900; font-style: italic;">#                       on the stack, and the string length is then</span>
<span style="color: #339900; font-style: italic;">#                       passed as an F77_INTEGER after all explicit</span>
<span style="color: #339900; font-style: italic;">#                       stack arguments [default]</span>
<span style="color: #339900; font-style: italic;"># -DStringStructPtr   : The address of a structure is passed by a</span>
<span style="color: #339900; font-style: italic;">#                       Fortran 77 string, and the structure is of the</span>
<span style="color: #339900; font-style: italic;">#                       form: struct {char *cp; F77_INTEGER len;}</span>
<span style="color: #339900; font-style: italic;"># -DStringStructVal   : A structure is passed by value for each Fortran</span>
<span style="color: #339900; font-style: italic;">#                       77 string, and the structure is of the form:</span>
<span style="color: #339900; font-style: italic;">#                       struct {char *cp; F77_INTEGER len;}</span>
<span style="color: #339900; font-style: italic;"># -DStringCrayStyle   : Special option for Cray machines, which uses</span>
<span style="color: #339900; font-style: italic;">#                       Cray fcd (fortran character descriptor) for</span>
<span style="color: #339900; font-style: italic;">#                       interoperation</span>
F2CDEFS      <span style="color: #004400;">=</span>  <span style="color: #004400;">-</span>DAdd_
&nbsp;
<span style="color: #339900; font-style: italic;">#</span>
<span style="color: #339900; font-style: italic;"># HPL Includes / Libraries / Specifics</span>
HPL_INCLUDES <span style="color: #004400;">=</span> <span style="color: #004400;">-</span>I<span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">INCdir</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">-</span>I<span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">INCdir</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">/$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">ARCH</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">LAinc</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">MPinc</span><span style="color: #004400;">&#41;</span>
HPL_LIBS     <span style="color: #004400;">=</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">HPLlib</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">LAlib</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">MPlib</span><span style="color: #004400;">&#41;</span>
&nbsp;
<span style="color: #339900; font-style: italic;">#</span>
<span style="color: #339900; font-style: italic;"># HPL Compile Time Options</span>
<span style="color: #339900; font-style: italic;"># -DHPL_COPY_L           force the copy of the panel L before bcast</span>
<span style="color: #339900; font-style: italic;"># -DHPL_CALL_CBLAS       call the cblas interface</span>
<span style="color: #339900; font-style: italic;"># -DHPL_CALL_VSIPL       call the vsip library</span>
<span style="color: #339900; font-style: italic;"># -DHPL_DETAILED_TIMING  enable detailed timers</span>
<span style="color: #339900; font-style: italic;">#</span>
<span style="color: #339900; font-style: italic;"># By default HPL will:</span>
<span style="color: #339900; font-style: italic;">#    *) not copy L before broadcast</span>
<span style="color: #339900; font-style: italic;">#    *) call the BLAS Fortran 77 interface</span>
<span style="color: #339900; font-style: italic;">#    *) not display detailed timing information</span>
HPL_OPTS     <span style="color: #004400;">=</span> <span style="color: #004400;">-</span>DHPL_COPY_L <span style="color: #004400;">-</span>DHPL_CALL_CBLAS <span style="color: #004400;">-</span>DHPL_DETAILED_TIMING 
&nbsp;
<span style="color: #339900; font-style: italic;">#</span>
<span style="color: #339900; font-style: italic;"># HPL Definitions</span>
HPL_DEFS     <span style="color: #004400;">=</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">F2CDEFS</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">HPL_OPTS</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">HPL_INCLUDES</span><span style="color: #004400;">&#41;</span>
&nbsp;
<span style="color: #339900; font-style: italic;">#</span>
<span style="color: #339900; font-style: italic;"># Compilers / linkers - Optimization Flags</span>
CC           <span style="color: #004400;">=</span> mpicc
CCNOOPT      <span style="color: #004400;">=</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">HPL_DEFS</span><span style="color: #004400;">&#41;</span>
CCFLAGS      <span style="color: #004400;">=</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">HPL_DEFS</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">-</span>fomit<span style="color: #004400;">-</span>frame<span style="color: #004400;">-</span>pointer <span style="color: #004400;">-</span>O3 <span style="color: #004400;">-</span>funroll<span style="color: #004400;">-</span>loops <span style="color: #004400;">-</span>W <span style="color: #004400;">-</span>Wall
&nbsp;
<span style="color: #339900; font-style: italic;">#</span>
<span style="color: #339900; font-style: italic;"># On some platforms, it is necessary to use the Fortran linker </span>
<span style="color: #339900; font-style: italic;"># to find the Fortran internals used in the BLAS library</span>
LINKER       <span style="color: #004400;">=</span> mpif77
LINKFLAGS    <span style="color: #004400;">=</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">CCFLAGS</span><span style="color: #004400;">&#41;</span>
ARCHIVER     <span style="color: #004400;">=</span> ar
ARFLAGS      <span style="color: #004400;">=</span> r
RANLIB       <span style="color: #004400;">=</span> echo
<span style="color: #339900; font-style: italic;">#</span></pre></td></tr></table></div>

<p><br clear="all"></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#! /bin/bash</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># install_hpcc.sh</span>
<span style="color: #666666; font-style: italic;"># BASH script to install HPCC 1.4.1 (compiled against MPICH2 1.4.1p1) on a</span>
<span style="color: #666666; font-style: italic;"># Rocks 5.4.2 cluster's front end</span>
<span style="color: #666666; font-style: italic;"># Must be root (or at least have sudo privilege) to run this script</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Begin root-check IF</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$UID</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>;
<span style="color: #000000; font-weight: bold;">then</span>
  <span style="color: #c20cb9; font-weight: bold;">clear</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  You must be logged in as root!&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  Exiting...&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span>
  <span style="color: #7a0874; font-weight: bold;">exit</span>
<span style="color: #000000; font-weight: bold;">else</span>
  <span style="color: #666666; font-style: italic;"># Set necessary variables</span>
  <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">HPCC_VERSION</span>=<span style="color: #ff0000;">&quot;1.4.1&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">MPICH2_VERSION</span>=<span style="color: #ff0000;">&quot;1.4.1p1&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">GCC_VERSION</span>=<span style="color: #ff0000;">&quot;4.1.2&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">HPCC_INSTALL</span>=<span style="color: #ff0000;">&quot;/share/apps/hpcc/<span style="color: #007800;">${HPCC_VERSION}</span>/mpich2/<span style="color: #007800;">${MPICH2_VERSION}</span>/gcc/<span style="color: #007800;">${GCC_VERSION}</span>&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">MAKEFILE_ARCH</span>=<span style="color: #ff0000;">&quot;MPICH2141p1_GCC412&quot;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;"># Begin HPCC-${HPCC_VERSION}.tar.gz check IF</span>
  <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;/share/apps/tmp/hpcc-<span style="color: #007800;">${HPCC_VERSION}</span>.tar.gz&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
  <span style="color: #000000; font-weight: bold;">then</span>
&nbsp;
    <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>apps<span style="color: #000000; font-weight: bold;">/</span>hpcc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${HPCC_VERSION}</span><span style="color: #000000; font-weight: bold;">/</span>mpich2<span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${MPICH2_VERSION}</span><span style="color: #000000; font-weight: bold;">/</span>gcc<span style="color: #000000; font-weight: bold;">/</span>
    <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>apps<span style="color: #000000; font-weight: bold;">/</span>hpcc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${HPCC_VERSION}</span><span style="color: #000000; font-weight: bold;">/</span>mpich2<span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${MPICH2_VERSION}</span><span style="color: #000000; font-weight: bold;">/</span>gcc<span style="color: #000000; font-weight: bold;">/</span>
    <span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-zxvf</span> <span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>apps<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>hpcc-<span style="color: #800000;">${HPCC_VERSION}</span>.tar.gz
    <span style="color: #c20cb9; font-weight: bold;">mv</span> hpcc-<span style="color: #800000;">${HPCC_VERSION}</span> <span style="color: #800000;">${GCC_VERSION}</span>
&nbsp;
    <span style="color: #7a0874; font-weight: bold;">echo</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  Step #0: copy the makefile, make clean and make&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #800000;">${HPCC_INSTALL}</span>
    <span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>apps<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>Make.<span style="color: #800000;">${MAKEFILE_ARCH}</span>.HPCC .<span style="color: #000000; font-weight: bold;">/</span>hpl<span style="color: #000000; font-weight: bold;">/</span>Make.<span style="color: #800000;">${MAKEFILE_ARCH}</span>
&nbsp;
    <span style="color: #c20cb9; font-weight: bold;">make</span> clean <span style="color: #007800;">arch</span>=<span style="color: #800000;">${MAKEFILE_ARCH}</span>
    <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #007800;">arch</span>=<span style="color: #800000;">${MAKEFILE_ARCH}</span>
&nbsp;
    <span style="color: #7a0874; font-weight: bold;">echo</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  Step #1: Update <span style="color: #007800;">$HOME</span>/.bashrc&quot;</span>
    <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #cc0000; font-style: italic;">&lt;&lt;EOF
&nbsp;
  Add the following lines to $HOME/.bashrc and remember to source it
&nbsp;
  # HPCC (${HPCC_VERSION}) settings
  export HPCC=&quot;${HPCC_INSTALL}&quot;
  export PATH=&quot;\${PATH}:\${HPCC}/bin/${MAKEFILE_ARCH}&quot;
  export LD_LIBRARY_PATH=&quot;\${LD_LIBRARY_PATH}:\${HPCC}/${MAKEFILE_ARCH}&quot;
&nbsp;
EOF</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">fi</span>
  <span style="color: #666666; font-style: italic;"># End hpcc-${HPCC_VERSION}.tar.gz check IF</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">fi</span> 
<span style="color: #666666; font-style: italic;"># End root-check IF</span></pre></td></tr></table></div>

<p><br clear="all"></p>
<h3 class="blog">Running HPCC Benchmark</h3>
<p>Please refer to the corresponding sections in <a href="http://sgowtham.net/blog/2012/02/27/hpl-2-0-benchmark-with-gcc-4-1-2-on-rocks-5-4-2/" class="underline" target="_blank">HPL 2.0 Benchmark With GCC 4.1.2 On Rocks 5.4.2</a> to learn how to get a fix on <code>N</code>, <code>NB</code>, etc., given the hardware configuration of compute nodes. Running HPCC benchmark is very similar to running HPL 2.0 benchmark.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fsgowtham.net%2Fblog%2F2012%2F02%2F28%2Fhpcc-1-4-1-benchmark-with-gcc-4-1-2-on-rocks-5-4-2%2F&amp;title=HPCC%201.4.1%20Benchmark%20With%20GCC%204.1.2%20On%20Rocks%205.4.2" id="wpa2a_2"><img src="http://sgowtham.net/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://sgowtham.net/blog/2012/02/28/hpcc-1-4-1-benchmark-with-gcc-4-1-2-on-rocks-5-4-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HPL 2.0 Benchmark With GCC 4.1.2 On Rocks 5.4.2</title>
		<link>http://sgowtham.net/blog/2012/02/27/hpl-2-0-benchmark-with-gcc-4-1-2-on-rocks-5-4-2/</link>
		<comments>http://sgowtham.net/blog/2012/02/27/hpl-2-0-benchmark-with-gcc-4-1-2-on-rocks-5-4-2/#comments</comments>
		<pubDate>Mon, 27 Feb 2012 23:44:17 +0000</pubDate>
		<dc:creator>Gowtham</dc:creator>
				<category><![CDATA[BASH]]></category>
		<category><![CDATA[Clusters]]></category>
		<category><![CDATA[HPL]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[MichiganTech]]></category>
		<category><![CDATA[MPI]]></category>
		<category><![CDATA[Rocks]]></category>
		<category><![CDATA[Science]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://sgowtham.net/blog/?p=3361</guid>
		<description><![CDATA[Disclaimer The instructions/steps given below worked for me (and Michigan Technological University) running NPACI Rocks 5.4.2 (with CentOS 5.5) &#8211; as has been a common practice for several years now, a full version of Operating System was installed. These instructions may very well work for you (or your institution), on Rocks-like or other linux clusters. [...]]]></description>
			<content:encoded><![CDATA[<h3 class="blog">Disclaimer</h3>
<p>The instructions/steps given below worked for me (and <a href="http://www.mtu.edu/" target="_blank" class="underline">Michigan Technological University</a>) running <a href="http://www.rocksclusters.org/" class="underline" target="_blank">NPACI Rocks</a> 5.4.2 (with CentOS 5.5) &#8211; as has been a common practice for several years now, a full version of Operating System was installed. These instructions may very well work for you (or your institution), on Rocks-like or other linux clusters. Please note that if you decide to use these instructions on your machine, you are doing so entirely at your very own discretion and that neither this site, <em>sgowtham.net</em>, nor its author (or Michigan Technological University) is responsible for any/all damage – intellectual and/or otherwise.</p>
<p><br clear="all"></p>
<h3 class="blog">A Bit About HPL</h3>
<blockquote><p><a href="http://netlib.org/linpack/" class="underline" target="_blank">LINPACK</a> is a software library for performing numerical linear algebra on computers. It was written in FORTRAN by Jack Dongarra, Jim Bunch, Cleve Moler and Gilbert Stewart. LINPACK makes use of the <a href="http://www.netlib.org/blas/" class="underline" target="_blank">BLAS</a> libraries for performing basic vector and matrix operations. It has largely been superseded by LAPACK, which runs more efficiently on modern architectures.</p>
<p>The LINPACK benchmarks are a measure of a system&#8217;s floating point computing power. Introduced by Jack Dongarra, they measure how fast a computer solves a dense <code>N * N</code> system of linear equations, <code>Ax = b</code>. The solution is obtained by <em>Gaussian Elimination with Partial Pivoting</em>, with</p>
<p class="bpcaption"><img src='http://s.wordpress.com/latex.php?latex=%5Cfrac%7B2%7D%7B3%7D%5C%3AN%5E3%20%5C%3A%2B%5C%3A%202%5C%3AN%5E2%20%5C%3A%2B%5C%3A%20%5Cmathcal%7BO%7D%5Cleft%28N%5Cright%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\frac{2}{3}\:N^3 \:+\: 2\:N^2 \:+\: \mathcal{O}\left(N\right)' title='\frac{2}{3}\:N^3 \:+\: 2\:N^2 \:+\: \mathcal{O}\left(N\right)' class='latex' /></p>
<p>floating point iterations. The result is often expressed in billions of floating point operations per second (<code>GFLOPS</code>). <a href="http://netlib.org/benchmark/hpl/" class="underline" target="_blank">HPL</a>, a portable implementation of <em>High Performance LINPACK Benchmark</em>, is used as a performance measure for ranking the supercomputers in the <a href="http://www.top500.org/" target="_blank" class="underline">Top500</a> list.
</p></blockquote>
<p><br clear="all"></p>
<h3 class="blog">Pre-requisite #1: MPI</h3>
<p>Following Rocks recommendations, this and other pre-requisites will be installed under <code>/share/apps/</code>; software installed by me, in clusters at Michigan Tech, have the following template for their folder structure:</p>
<p class="bpcaption"><code>/share/apps/Software/Software_Version/Compiler/Compiler_Version</code></p>
<p><br clear="all"><br />
Rocks 5.4.2 installation has an instance (of few flavors) of MPI but I prefer to compile <a href="http://www.mcs.anl.gov/research/projects/mpich2/" class="underline" target="_blank">MPICH2</a> using GCC 4.1.2. At the time of writing this post, the latest stable version of MPICH2 is 1.4.1p1 and it may be downloaded from <a href="http://www.mcs.anl.gov/research/projects/mpich2/" target="_blank" class="underline">here</a>.  Following folder structure/template mentioned above, it will be installed under</p>
<p class="bpcaption"><code>/share/apps/mpich2/1.4.1p1/gcc/4.1.2</code></p>
<p><br clear="all"><br />
To avoid confusion and/or missed steps leading to undesired results, steps associated with installation of MPICH2 have been put in the following script:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#! /bin/bash</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># install_mpich2.sh</span>
<span style="color: #666666; font-style: italic;"># BASH script to install MPICH2 (compiled against GCC 4.1.2) on a</span>
<span style="color: #666666; font-style: italic;"># Rocks 5.4.2 cluster's front end</span>
<span style="color: #666666; font-style: italic;"># Must be root (or at least have sudo privilege) to run this script</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Begin root-check IF</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$UID</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>;
<span style="color: #000000; font-weight: bold;">then</span>
  <span style="color: #c20cb9; font-weight: bold;">clear</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  You must be logged in as root!&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  Exiting...&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span>
  <span style="color: #7a0874; font-weight: bold;">exit</span>
<span style="color: #000000; font-weight: bold;">else</span>
  <span style="color: #666666; font-style: italic;"># Set necessary variables</span>
  <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">CC</span>=<span style="color: #ff0000;">&quot;gcc&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">CXX</span>=<span style="color: #ff0000;">&quot;g++&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">FC</span>=<span style="color: #ff0000;">&quot;gfortran&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">F77</span>=<span style="color: #ff0000;">&quot;gfortran&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">MPICH2_VERSION</span>=<span style="color: #ff0000;">&quot;1.4.1p1&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">GCC_VERSION</span>=<span style="color: #ff0000;">&quot;4.1.2&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">MPICH2_INSTALL</span>=<span style="color: #ff0000;">&quot;/share/apps/mpich2/<span style="color: #007800;">${MPICH2_VERSION}</span>/gcc/<span style="color: #007800;">${GCC_VERSION}</span>&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">ANL</span>=<span style="color: #ff0000;">&quot;http://www.mcs.anl.gov/research/projects/mpich2/downloads/tarballs&quot;</span>
&nbsp;
  <span style="color: #7a0874; font-weight: bold;">echo</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  Step #0: Download MPICH2 to /share/apps/tmp&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>apps<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>
  <span style="color: #c20cb9; font-weight: bold;">wget</span> <span style="color: #800000;">${ANL}</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${MPICH2_VERSION}</span><span style="color: #000000; font-weight: bold;">/</span>mpich2-<span style="color: #800000;">${MPICH2_VERSION}</span>.tar.gz
&nbsp;
  <span style="color: #666666; font-style: italic;"># Begin mpich2-${MPICH2_VERSION}.tar.gz check IF</span>
  <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;mpich2-<span style="color: #007800;">${MPICH2_VERSION}</span>.tar.gz&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
  <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  Step #1: configure, make clean, make and make install&quot;</span>
&nbsp;
    <span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-zxpf</span> mpich2-<span style="color: #800000;">${MPICH2_VERSION}</span>.tar.gz
    <span style="color: #7a0874; font-weight: bold;">cd</span> mpich2-<span style="color: #800000;">${MPICH2_VERSION}</span><span style="color: #000000; font-weight: bold;">/</span>
    .<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--prefix</span>=<span style="color: #800000;">${MPICH2_INSTALL}</span>
    <span style="color: #c20cb9; font-weight: bold;">make</span> clean
    <span style="color: #c20cb9; font-weight: bold;">make</span>
    <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span>
&nbsp;
    <span style="color: #7a0874; font-weight: bold;">echo</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  Step #2: Update <span style="color: #007800;">$HOME</span>/.bashrc&quot;</span>
    <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #cc0000; font-style: italic;">&lt;&lt;EOF
&nbsp;
  Add the following lines to $HOME/.bashrc and remember to source it
&nbsp;
  # MPICH2 (${MPICH2_VERSION}) settings
  export MPICH2=&quot;${MPICH2_INSTALL}&quot;
  export PATH=&quot;\${PATH}:\${MPICH2}/bin:\${MPICH2}/sbin&quot;
  export MANPATH=&quot;\${MANPATH}:\${MPICH2}/man&quot;
  export LD_LIBRARY_PATH=&quot;\${LD_LIBRARY_PATH}:\${MPICH2}/lib&quot;
&nbsp;
EOF</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">fi</span>
  <span style="color: #666666; font-style: italic;"># End mpich2-${MPICH2_VERSION}.tar.gz check IF</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">fi</span> 
<span style="color: #666666; font-style: italic;"># End root-check IF</span></pre></td></tr></table></div>

<p><br clear="all"><br />
A good test of a successful installation is that <em>which mpicc</em>, <em>which mpif77</em>, etc. return the respective commands located in <code>${MPICH2_INSTALL}</code>.</p>
<p><br clear="all"></p>
<h3 class="blog">Pre-requisite #2: Goto BLAS</h3>
<p>As in the case of pre-requisite #1, this one will be installed under</p>
<p class="bpcaption"><code>/share/apps/gotoblas2/1.13/gcc/4.1.2</code></p>
<p><br clear="all"><br />
The following script, used in installation, will assume that one has downloaded Goto BLAS2 1.13 from <a href="http://www.tacc.utexas.edu/tacc-projects/gotoblas2" target="_blank" class="underline">here</a> and placed it in<br />
<code>/share/apps/tmp/</code></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#! /bin/bash</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># install_gotoblas2.sh</span>
<span style="color: #666666; font-style: italic;"># BASH script to install Goto BLAS2 (compiled against GCC 4.1.2) on a</span>
<span style="color: #666666; font-style: italic;"># Rocks 5.4.2 cluster's front end</span>
<span style="color: #666666; font-style: italic;"># Must be root (or at least have sudo privilege) to run this script</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Begin root-check IF</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$UID</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>;
<span style="color: #000000; font-weight: bold;">then</span>
  <span style="color: #c20cb9; font-weight: bold;">clear</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  You must be logged in as root!&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  Exiting...&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span>
  <span style="color: #7a0874; font-weight: bold;">exit</span>
<span style="color: #000000; font-weight: bold;">else</span>
  <span style="color: #666666; font-style: italic;"># Set necessary variables</span>
  <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">CC</span>=<span style="color: #ff0000;">&quot;gcc&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">CXX</span>=<span style="color: #ff0000;">&quot;g++&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">FC</span>=<span style="color: #ff0000;">&quot;gfortran&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">F77</span>=<span style="color: #ff0000;">&quot;gfortran&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">GOTOBLAS2_VERSION</span>=<span style="color: #ff0000;">&quot;1.13&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">GCC_VERSION</span>=<span style="color: #ff0000;">&quot;4.1.2&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">GOTOBLAS2_INSTALL</span>=<span style="color: #ff0000;">&quot;/share/apps/gotoblas2/<span style="color: #007800;">${GOTOBLAS2_VERSION}</span>/gcc/<span style="color: #007800;">${GCC_VERSION}</span>&quot;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;"># Begin GotoBLAS2-${GOTOBLAS2_VERSION}.tar.gz check IF</span>
  <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;/share/apps/tmp/GotoBLAS2-<span style="color: #007800;">${GOTOBLAS2_VERSION}</span>.tar.gz&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
  <span style="color: #000000; font-weight: bold;">then</span>
&nbsp;
    <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>apps<span style="color: #000000; font-weight: bold;">/</span>gotoblas2<span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${GOTOBLAS2_VERSION}</span><span style="color: #000000; font-weight: bold;">/</span>gcc<span style="color: #000000; font-weight: bold;">/</span>
    <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>apps<span style="color: #000000; font-weight: bold;">/</span>gotoblas2<span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${GOTOBLAS2_VERSION}</span><span style="color: #000000; font-weight: bold;">/</span>gcc<span style="color: #000000; font-weight: bold;">/</span>
    <span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-zxvf</span> <span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>apps<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>GotoBLAS2-<span style="color: #800000;">${GOTOBLAS2_VERSION}</span>.tar.gz
    <span style="color: #c20cb9; font-weight: bold;">mv</span> GotoBLAS2 <span style="color: #800000;">${GCC_VERSION}</span>
&nbsp;
    <span style="color: #7a0874; font-weight: bold;">echo</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  Step #0: make clean and make&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #800000;">${GOTOBLAS2_INSTALL}</span>
    <span style="color: #c20cb9; font-weight: bold;">make</span> clean
    <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #007800;">BINARY</span>=<span style="color: #000000;">64</span>
&nbsp;
    <span style="color: #7a0874; font-weight: bold;">echo</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  Step #1: Update <span style="color: #007800;">$HOME</span>/.bashrc&quot;</span>
    <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #cc0000; font-style: italic;">&lt;&lt;EOF
&nbsp;
  Add the following lines to $HOME/.bashrc and remember to source it
&nbsp;
  # GOTOBLAS2 (${GOTOBLAS2_VERSION}) settings
  export GOTOBLAS2=&quot;${GOTOBLAS2_INSTALL}&quot;
  export LD_LIBRARY_PATH=&quot;\${LD_LIBRARY_PATH}:\${GOTOBLAS2}&quot;
&nbsp;
EOF</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">fi</span>
  <span style="color: #666666; font-style: italic;"># End GotoBLAS2-${GOTOBLAS2_VERSION}.tar.gz check IF</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">fi</span> 
<span style="color: #666666; font-style: italic;"># End root-check IF</span></pre></td></tr></table></div>

<p><br clear="all"></p>
<h3 class="blog">HPL Installation/Compilation</h3>
<p>With MPICH2 and Goto BLAS2 in place, HPL 2.0 will be installed under</p>
<p class="bpcaption"><code>/share/apps/hpl/2.0/mpich2/1.4.1p1/gcc/4.1.2</code></p>
<p><br clear="all"><br />
The following script, used in installation, will assume that one has downloaded HPL 2.0 from <a href="http://netlib.org/benchmark/hpl/" target="_blank" class="underline">here</a> &#038; the necessary <code>Make.MPICH2141p1_GCC412.HPL</code> (listed below) and placed them in <code>/share/apps/tmp/</code></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
</pre></td><td class="code"><pre class="make" style="font-family:monospace;"><span style="color: #339900; font-style: italic;">#</span>
<span style="color: #339900; font-style: italic;"># Makefile (Make.MPICH2141p1_GCC412) used to compile HPL </span>
<span style="color: #339900; font-style: italic;"># on HPC clusters running NPACI Rocks (5.4.2) with CentOS (5.5)</span>
<span style="color: #339900; font-style: italic;"># at Michigan Technological University.</span>
<span style="color: #339900; font-style: italic;"># </span>
<span style="color: #339900; font-style: italic;"># Disclaimer:</span>
<span style="color: #339900; font-style: italic;"># Please note that you are using these instructions </span>
<span style="color: #339900; font-style: italic;"># at your very own risk and that Michigan Technological</span>
<span style="color: #339900; font-style: italic;"># University is not responsible for any/all damage caused to </span>
<span style="color: #339900; font-style: italic;"># your property, intellectual or otherwise.</span>
<span style="color: #339900; font-style: italic;"># </span>
<span style="color: #339900; font-style: italic;"># For additional help and/or comments, questions, suggestions,</span>
<span style="color: #339900; font-style: italic;"># please contact </span>
<span style="color: #339900; font-style: italic;">#</span>
<span style="color: #339900; font-style: italic;"># Gowtham</span>
<span style="color: #339900; font-style: italic;"># Information Technology Services &amp; Security</span>
<span style="color: #339900; font-style: italic;"># Michigan Technological University</span>
<span style="color: #339900; font-style: italic;"># g@mtu.edu</span>
<span style="color: #339900; font-style: italic;">#</span>
<span style="color: #339900; font-style: italic;"># * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *</span>
<span style="color: #339900; font-style: italic;">#</span>
<span style="color: #339900; font-style: italic;">#</span>
<span style="color: #339900; font-style: italic;">#  -- High Performance Computing Linpack Benchmark (HPL)                </span>
<span style="color: #339900; font-style: italic;">#     HPL - 2.0 - September 10, 2008                          </span>
<span style="color: #339900; font-style: italic;">#     Antoine P. Petitet                                                </span>
<span style="color: #339900; font-style: italic;">#     University of Tennessee, Knoxville                                </span>
<span style="color: #339900; font-style: italic;">#     Innovative Computing Laboratory                                 </span>
<span style="color: #339900; font-style: italic;">#     (C) Copyright 2000-2008 All Rights Reserved                       </span>
<span style="color: #339900; font-style: italic;">#                                                                       </span>
<span style="color: #339900; font-style: italic;">#  -- Copyright notice and Licensing terms:                             </span>
<span style="color: #339900; font-style: italic;">#                                                                       </span>
<span style="color: #339900; font-style: italic;">#  Redistribution and use in source and binary forms, with or without</span>
<span style="color: #339900; font-style: italic;">#  modification, are permitted provided that the following conditions</span>
<span style="color: #339900; font-style: italic;">#  are met:                                                             </span>
<span style="color: #339900; font-style: italic;">#                                                                       </span>
<span style="color: #339900; font-style: italic;">#  1. Redistributions of source code must retain the above copyright</span>
<span style="color: #339900; font-style: italic;">#  notice, this list of conditions and the following disclaimer.        </span>
<span style="color: #339900; font-style: italic;">#                                                                       </span>
<span style="color: #339900; font-style: italic;">#  2. Redistributions in binary form must reproduce the above copyright</span>
<span style="color: #339900; font-style: italic;">#  notice, this list of conditions, and the following disclaimer in the</span>
<span style="color: #339900; font-style: italic;">#  documentation and/or other materials provided with the distribution. </span>
<span style="color: #339900; font-style: italic;">#                                                                       </span>
<span style="color: #339900; font-style: italic;">#  3. All advertising materials mentioning features or use of this</span>
<span style="color: #339900; font-style: italic;">#  software must display the following acknowledgement:                 </span>
<span style="color: #339900; font-style: italic;">#  This product includes software developed at the University of</span>
<span style="color: #339900; font-style: italic;">#  Tennessee, Knoxville, Innovative Computing Laboratory.             </span>
<span style="color: #339900; font-style: italic;">#                                                                       </span>
<span style="color: #339900; font-style: italic;">#  4. The name of the University, the name of the Laboratory, or the</span>
<span style="color: #339900; font-style: italic;">#  names of its contributors may not be used to endorse or promote</span>
<span style="color: #339900; font-style: italic;">#  products derived from this software without specific written</span>
<span style="color: #339900; font-style: italic;">#  permission.</span>
<span style="color: #339900; font-style: italic;">#</span>
<span style="color: #339900; font-style: italic;">#  -- Disclaimer:</span>
<span style="color: #339900; font-style: italic;">#                                                                       </span>
<span style="color: #339900; font-style: italic;">#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS</span>
<span style="color: #339900; font-style: italic;">#  ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT</span>
<span style="color: #339900; font-style: italic;">#  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR</span>
<span style="color: #339900; font-style: italic;">#  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY</span>
<span style="color: #339900; font-style: italic;">#  OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,</span>
<span style="color: #339900; font-style: italic;">#  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT</span>
<span style="color: #339900; font-style: italic;">#  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,</span>
<span style="color: #339900; font-style: italic;">#  DATA OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY</span>
<span style="color: #339900; font-style: italic;">#  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT</span>
<span style="color: #339900; font-style: italic;">#  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE</span>
<span style="color: #339900; font-style: italic;">#  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span>
<span style="color: #339900; font-style: italic;">#  </span>
&nbsp;
<span style="color: #339900; font-style: italic;">#</span>
<span style="color: #339900; font-style: italic;"># Shell Details</span>
SHELL        <span style="color: #004400;">=</span> <span style="color: #004400;">/</span>bin<span style="color: #004400;">/</span>sh
CD           <span style="color: #004400;">=</span> cd
CP           <span style="color: #004400;">=</span> cp
LN_S         <span style="color: #004400;">=</span> ln <span style="color: #004400;">-</span>s
MKDIR        <span style="color: #004400;">=</span> mkdir
RM           <span style="color: #004400;">=</span> <span style="color: #004400;">/</span>bin<span style="color: #004400;">/</span>rm <span style="color: #004400;">-</span>f
TOUCH        <span style="color: #004400;">=</span> touch
&nbsp;
<span style="color: #339900; font-style: italic;">#</span>
<span style="color: #339900; font-style: italic;"># Platform Identifier</span>
ARCH         <span style="color: #004400;">=</span> MPICH2141p1_GCC412
&nbsp;
<span style="color: #339900; font-style: italic;">#</span>
<span style="color: #339900; font-style: italic;"># HPL Directory Structure / HPL library</span>
TOPdir       <span style="color: #004400;">=</span> <span style="color: #004400;">/</span>share<span style="color: #004400;">/</span>apps<span style="color: #004400;">/</span>hpl<span style="color: #004400;">/</span><span style="color: #CC2200;">2.0</span><span style="color: #004400;">/</span>mpich2<span style="color: #004400;">/</span>1<span style="color: #004400;">.</span>4<span style="color: #004400;">.</span>1p1<span style="color: #004400;">/</span>gcc<span style="color: #004400;">/</span>4<span style="color: #004400;">.</span>1<span style="color: #004400;">.</span>2
INCdir       <span style="color: #004400;">=</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">TOPdir</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">/</span><span style="color: #666622; font-weight: bold;">include</span>
BINdir       <span style="color: #004400;">=</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">TOPdir</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">/</span>bin<span style="color: #004400;">/$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">ARCH</span><span style="color: #004400;">&#41;</span>
LIBdir       <span style="color: #004400;">=</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">TOPdir</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">/</span>lib<span style="color: #004400;">/$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">ARCH</span><span style="color: #004400;">&#41;</span>
HPLlib       <span style="color: #004400;">=</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">LIBdir</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">/</span>libhpl<span style="color: #004400;">.</span>a 
&nbsp;
<span style="color: #339900; font-style: italic;">#</span>
<span style="color: #339900; font-style: italic;"># Message Passing library (MPI)</span>
MPdir        <span style="color: #004400;">=</span> <span style="color: #004400;">/</span>share<span style="color: #004400;">/</span>apps<span style="color: #004400;">/</span>mpich2<span style="color: #004400;">/</span>1<span style="color: #004400;">.</span>4<span style="color: #004400;">.</span>1p1<span style="color: #004400;">/</span>gcc<span style="color: #004400;">/</span>4<span style="color: #004400;">.</span>1<span style="color: #004400;">.</span>2
MPinc        <span style="color: #004400;">=</span> <span style="color: #004400;">-</span>I<span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">MPdir</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">/</span><span style="color: #666622; font-weight: bold;">include</span>
MPlib        <span style="color: #004400;">=</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">MPdir</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">/</span>lib<span style="color: #004400;">/</span>libmpich<span style="color: #004400;">.</span>a
&nbsp;
<span style="color: #339900; font-style: italic;">#</span>
<span style="color: #339900; font-style: italic;"># Linear Algebra library (BLAS)</span>
LAlib        <span style="color: #004400;">=</span> <span style="color: #004400;">/</span>share<span style="color: #004400;">/</span>apps<span style="color: #004400;">/</span>gotoblas2<span style="color: #004400;">/</span><span style="color: #CC2200;">1.13</span><span style="color: #004400;">/</span>gcc<span style="color: #004400;">/</span>4<span style="color: #004400;">.</span>1<span style="color: #004400;">.</span>2<span style="color: #004400;">/</span>libgoto2<span style="color: #004400;">.</span>a
&nbsp;
<span style="color: #339900; font-style: italic;">#</span>
<span style="color: #339900; font-style: italic;"># F77 / C Interface</span>
<span style="color: #339900; font-style: italic;"># You can skip this section if and only if you are not planning to use</span>
<span style="color: #339900; font-style: italic;"># a BLAS library featuring a Fortran 77 interface. Otherwise, it is</span>
<span style="color: #339900; font-style: italic;"># necessary to fill out the F2CDEFS variable with the appropriate</span>
<span style="color: #339900; font-style: italic;"># options. **One and only one** option should be chosen in **each** of</span>
<span style="color: #339900; font-style: italic;"># the 3 following categories:</span>
<span style="color: #339900; font-style: italic;">#</span>
<span style="color: #339900; font-style: italic;"># 1) name space (How C calls a Fortran 77 routine)</span>
<span style="color: #339900; font-style: italic;">#</span>
<span style="color: #339900; font-style: italic;"># -DAdd_              : all lower case and a suffixed underscore (Suns,</span>
<span style="color: #339900; font-style: italic;">#                       Intel, ...) [default]</span>
<span style="color: #339900; font-style: italic;"># -DNoChange          : all lower case (IBM RS6000)</span>
<span style="color: #339900; font-style: italic;"># -DUpCase            : all upper case (Cray)</span>
<span style="color: #339900; font-style: italic;"># -DAdd__             : the FORTRAN compiler in use is f2c</span>
<span style="color: #339900; font-style: italic;">#</span>
<span style="color: #339900; font-style: italic;"># 2) C and Fortran 77 integer mapping</span>
<span style="color: #339900; font-style: italic;">#</span>
<span style="color: #339900; font-style: italic;"># -DF77_INTEGER=int   : Fortran 77 INTEGER is a C int [default]</span>
<span style="color: #339900; font-style: italic;"># -DF77_INTEGER=long  : Fortran 77 INTEGER is a C long</span>
<span style="color: #339900; font-style: italic;"># -DF77_INTEGER=short : Fortran 77 INTEGER is a C short</span>
<span style="color: #339900; font-style: italic;">#</span>
<span style="color: #339900; font-style: italic;"># 3) Fortran 77 string handling</span>
<span style="color: #339900; font-style: italic;">#</span>
<span style="color: #339900; font-style: italic;"># -DStringSunStyle    : The string address is passed at the string location</span>
<span style="color: #339900; font-style: italic;">#                       on the stack, and the string length is then</span>
<span style="color: #339900; font-style: italic;">#                       passed as an F77_INTEGER after all explicit</span>
<span style="color: #339900; font-style: italic;">#                       stack arguments [default]</span>
<span style="color: #339900; font-style: italic;"># -DStringStructPtr   : The address of a structure is passed by a</span>
<span style="color: #339900; font-style: italic;">#                       Fortran 77 string, and the structure is of the</span>
<span style="color: #339900; font-style: italic;">#                       form: struct {char *cp; F77_INTEGER len;}</span>
<span style="color: #339900; font-style: italic;"># -DStringStructVal   : A structure is passed by value for each Fortran</span>
<span style="color: #339900; font-style: italic;">#                       77 string, and the structure is of the form:</span>
<span style="color: #339900; font-style: italic;">#                       struct {char *cp; F77_INTEGER len;}</span>
<span style="color: #339900; font-style: italic;"># -DStringCrayStyle   : Special option for Cray machines, which uses</span>
<span style="color: #339900; font-style: italic;">#                       Cray fcd (fortran character descriptor) for</span>
<span style="color: #339900; font-style: italic;">#                       interoperation</span>
F2CDEFS      <span style="color: #004400;">=</span>  <span style="color: #004400;">-</span>DAdd_
&nbsp;
<span style="color: #339900; font-style: italic;">#</span>
<span style="color: #339900; font-style: italic;"># HPL Includes / Libraries / Specifics</span>
HPL_INCLUDES <span style="color: #004400;">=</span> <span style="color: #004400;">-</span>I<span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">INCdir</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">-</span>I<span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">INCdir</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">/$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">ARCH</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">LAinc</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">MPinc</span><span style="color: #004400;">&#41;</span>
HPL_LIBS     <span style="color: #004400;">=</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">HPLlib</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">LAlib</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">MPlib</span><span style="color: #004400;">&#41;</span>
&nbsp;
<span style="color: #339900; font-style: italic;">#</span>
<span style="color: #339900; font-style: italic;"># HPL Compile Time Options</span>
<span style="color: #339900; font-style: italic;"># -DHPL_COPY_L           force the copy of the panel L before bcast</span>
<span style="color: #339900; font-style: italic;"># -DHPL_CALL_CBLAS       call the cblas interface</span>
<span style="color: #339900; font-style: italic;"># -DHPL_CALL_VSIPL       call the vsip library</span>
<span style="color: #339900; font-style: italic;"># -DHPL_DETAILED_TIMING  enable detailed timers</span>
<span style="color: #339900; font-style: italic;">#</span>
<span style="color: #339900; font-style: italic;"># By default HPL will:</span>
<span style="color: #339900; font-style: italic;">#    *) not copy L before broadcast</span>
<span style="color: #339900; font-style: italic;">#    *) call the BLAS Fortran 77 interface</span>
<span style="color: #339900; font-style: italic;">#    *) not display detailed timing information</span>
HPL_OPTS     <span style="color: #004400;">=</span> <span style="color: #004400;">-</span>DHPL_COPY_L <span style="color: #004400;">-</span>DHPL_CALL_CBLAS <span style="color: #004400;">-</span>DHPL_DETAILED_TIMING 
&nbsp;
<span style="color: #339900; font-style: italic;">#</span>
<span style="color: #339900; font-style: italic;"># HPL Definitions</span>
HPL_DEFS     <span style="color: #004400;">=</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">F2CDEFS</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">HPL_OPTS</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">HPL_INCLUDES</span><span style="color: #004400;">&#41;</span>
&nbsp;
<span style="color: #339900; font-style: italic;">#</span>
<span style="color: #339900; font-style: italic;"># Compilers / linkers - Optimization Flags</span>
CC           <span style="color: #004400;">=</span> mpicc
CCNOOPT      <span style="color: #004400;">=</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">HPL_DEFS</span><span style="color: #004400;">&#41;</span>
CCFLAGS      <span style="color: #004400;">=</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">HPL_DEFS</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">-</span>fomit<span style="color: #004400;">-</span>frame<span style="color: #004400;">-</span>pointer <span style="color: #004400;">-</span>O3 <span style="color: #004400;">-</span>funroll<span style="color: #004400;">-</span>loops <span style="color: #004400;">-</span>W <span style="color: #004400;">-</span>Wall
&nbsp;
<span style="color: #339900; font-style: italic;">#</span>
<span style="color: #339900; font-style: italic;"># On some platforms, it is necessary to use the Fortran linker </span>
<span style="color: #339900; font-style: italic;"># to find the Fortran internals used in the BLAS library</span>
LINKER       <span style="color: #004400;">=</span> mpif77
LINKFLAGS    <span style="color: #004400;">=</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">CCFLAGS</span><span style="color: #004400;">&#41;</span>
ARCHIVER     <span style="color: #004400;">=</span> ar
ARFLAGS      <span style="color: #004400;">=</span> r
RANLIB       <span style="color: #004400;">=</span> echo
<span style="color: #339900; font-style: italic;">#</span></pre></td></tr></table></div>

<p><br clear="all"></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#! /bin/bash</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># install_hpl.sh</span>
<span style="color: #666666; font-style: italic;"># BASH script to install HPL 2.0 (compiled against MPICH2 1.4.1p1) on a</span>
<span style="color: #666666; font-style: italic;"># Rocks 5.4.2 cluster's front end</span>
<span style="color: #666666; font-style: italic;"># Must be root (or at least have sudo privilege) to run this script</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Begin root-check IF</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$UID</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>;
<span style="color: #000000; font-weight: bold;">then</span>
  <span style="color: #c20cb9; font-weight: bold;">clear</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  You must be logged in as root!&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  Exiting...&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span>
  <span style="color: #7a0874; font-weight: bold;">exit</span>
<span style="color: #000000; font-weight: bold;">else</span>
  <span style="color: #666666; font-style: italic;"># Set necessary variables</span>
  <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">HPL_VERSION</span>=<span style="color: #ff0000;">&quot;2.0&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">MPICH2_VERSION</span>=<span style="color: #ff0000;">&quot;1.4.1p1&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">GCC_VERSION</span>=<span style="color: #ff0000;">&quot;4.1.2&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">HPL_INSTALL</span>=<span style="color: #ff0000;">&quot;/share/apps/hpl/<span style="color: #007800;">${HPL_VERSION}</span>/mpich2/<span style="color: #007800;">${MPICH2_VERSION}</span>/gcc/<span style="color: #007800;">${GCC_VERSION}</span>&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">MAKEFILE_ARCH</span>=<span style="color: #ff0000;">&quot;MPICH2141p1_GCC412&quot;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;"># Begin hpl-${HPL_VERSION}.tar.gz check IF</span>
  <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;/share/apps/tmp/hpl-<span style="color: #007800;">${HPL_VERSION}</span>.tar.gz&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
  <span style="color: #000000; font-weight: bold;">then</span>
&nbsp;
    <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>apps<span style="color: #000000; font-weight: bold;">/</span>hpl<span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${HPL_VERSION}</span><span style="color: #000000; font-weight: bold;">/</span>mpich2<span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${MPICH2_VERSION}</span><span style="color: #000000; font-weight: bold;">/</span>gcc<span style="color: #000000; font-weight: bold;">/</span>
    <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>apps<span style="color: #000000; font-weight: bold;">/</span>hpl<span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${HPL_VERSION}</span><span style="color: #000000; font-weight: bold;">/</span>mpich2<span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${MPICH2_VERSION}</span><span style="color: #000000; font-weight: bold;">/</span>gcc<span style="color: #000000; font-weight: bold;">/</span>
    <span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-zxvf</span> <span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>apps<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>hpl-<span style="color: #800000;">${HPL_VERSION}</span>.tar.gz
    <span style="color: #c20cb9; font-weight: bold;">mv</span> hpl-<span style="color: #800000;">${HPL_VERSION}</span> <span style="color: #800000;">${GCC_VERSION}</span>
&nbsp;
    <span style="color: #7a0874; font-weight: bold;">echo</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  Step #0: copy the makefile, make clean and make&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #800000;">${HPL_INSTALL}</span>
    <span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>apps<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>Make.<span style="color: #800000;">${MAKEFILE_ARCH}</span>.HPC .<span style="color: #000000; font-weight: bold;">/</span>Make.<span style="color: #800000;">${MAKEFILE_ARCH}</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-d</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${HPL_INSTALL}</span>/bin/<span style="color: #007800;">${MAKEFILE_ARCH}</span>&quot;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
      <span style="color: #c20cb9; font-weight: bold;">make</span> clean <span style="color: #007800;">arch</span>=<span style="color: #800000;">${MAKEFILE_ARCH}</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$(ls -A ${HPL_INSTALL}/bin)</span>&quot;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>;
    <span style="color: #000000; font-weight: bold;">then</span>
      <span style="color: #c20cb9; font-weight: bold;">make</span> clean_arch_all <span style="color: #007800;">arch</span>=<span style="color: #800000;">${MAKEFILE_ARCH}</span> 
    <span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
    <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #007800;">arch</span>=<span style="color: #800000;">${MAKEFILE_ARCH}</span>
&nbsp;
    <span style="color: #7a0874; font-weight: bold;">echo</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  Step #1: Update <span style="color: #007800;">$HOME</span>/.bashrc&quot;</span>
    <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #cc0000; font-style: italic;">&lt;&lt;EOF
&nbsp;
  Add the following lines to $HOME/.bashrc and remember to source it
&nbsp;
  # HPL (${HPL_VERSION}) settings
  export HPL=&quot;${HPL_INSTALL}&quot;
  export PATH=&quot;\${PATH}:\${HPL}/bin/${MAKEFILE_ARCH}&quot;
  export LD_LIBRARY_PATH=&quot;\${LD_LIBRARY_PATH}:\${HPL}/${MAKEFILE_ARCH}&quot;
&nbsp;
EOF</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">fi</span>
  <span style="color: #666666; font-style: italic;"># End hpl-${HPL_VERSION}.tar.gz check IF</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">fi</span> 
<span style="color: #666666; font-style: italic;"># End root-check IF</span></pre></td></tr></table></div>

<p><br clear="all"></p>
<h3 class="blog">Running HPL Benchmark</h3>
<p>The amount of memory used by HPL is essentially the size of the co-efficient matrix, <code>A</code>. Following standard binary definition, 1 GB is 1024 * 1024 * 1024 bytes (<code>TOTAL_MEMORY_BYTES</code>). Most scientific/engineering computations use double precision numbers, with each such double precision number taking 8 bytes of memory. Thus, 1 GB can accommodate 134,217,728 double precision entities (<code>TOTAL_DP_ELEMENTS = TOTAL_MEMORY_BYTES/8</code>). Theoretically, <code>sqrt(TOTAL_DP_ELEMENTS)</code> represents the maximum possible value of <code>N</code>. However, operating system needs some memory to perform some necessary operations. As such, HPL benchmark is usually performed for the following values of <code>N</code> &#8211; with <code>m</code> representing the fraction of total memory &#8211; making sure that swapping did not occur (which would result in reduced performance).</p>
<p class="bpcaption"><img src='http://s.wordpress.com/latex.php?latex=N%20%5C%3A%3D%5C%3A%20m%5C%3A%5Csqrt%7B%5Cmathrm%7BTOTAL%5C_DP%5C_ELEMENTS%7D%7D%20%20%5Chspace%7B0.50in%7D%20m%3A%200.50%5C%3A%280.10%29%5C%3A0.80&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='N \:=\: m\:\sqrt{\mathrm{TOTAL\_DP\_ELEMENTS}}  \hspace{0.50in} m: 0.50\:(0.10)\:0.80' title='N \:=\: m\:\sqrt{\mathrm{TOTAL\_DP\_ELEMENTS}}  \hspace{0.50in} m: 0.50\:(0.10)\:0.80' class='latex' /></p>
<p><br clear="all"><br />
HPL uses the block size (<code>NB</code>) for the data distribution as well as for the computational granularity. From a data distribution perspective, the smaller <code>NB</code>, the better the load balance. From a computational perspective, too small of a value for <code>NB</code> may limit the computational performance by a large factor since almost no data re-use will occur in the highest level of the memory hierarchy. The number of messages will also increase. In my case, this benchmark was performed for <code>NB</code> values of 128, 256 and 512.</p>
<p>The results so obtained are compared with the theoretical peak value, <img src='http://s.wordpress.com/latex.php?latex=%5Cmathrm%7BGFLOPS%7D_%5Cmathrm%7BTheory%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\mathrm{GFLOPS}_\mathrm{Theory}' title='\mathrm{GFLOPS}_\mathrm{Theory}' class='latex' />, computed as follows:</p>
<p><br clear="all"></p>
<p class="bpcaption"><img src='http://s.wordpress.com/latex.php?latex=%20%5Cmbox%7B%5C%23%20of%20Nodes%7D%20%5C%3B%5Ctimes%5C%3B%20%5Cmbox%7B%5C%23%20of%20Sockets%2FNode%7D%20%5C%3B%5Ctimes%5C%3B%20%5Cmbox%7B%5C%23%20of%20Cores%2FSocket%7D%20%5C%3B%5Ctimes%5C%3B%20%5C%5C%5C%5C%5Cmbox%7BCPU%20Frequency%20%28Cycles%2Fsecond%29%7D%20%5C%3B%5Ctimes%5C%3B%20%5Cmbox%7B%5C%23%20of%20Floating%20Point%20Operations%2FCycle%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt=' \mbox{\# of Nodes} \;\times\; \mbox{\# of Sockets/Node} \;\times\; \mbox{\# of Cores/Socket} \;\times\; \\\\\mbox{CPU Frequency (Cycles/second)} \;\times\; \mbox{\# of Floating Point Operations/Cycle}' title=' \mbox{\# of Nodes} \;\times\; \mbox{\# of Sockets/Node} \;\times\; \mbox{\# of Cores/Socket} \;\times\; \\\\\mbox{CPU Frequency (Cycles/second)} \;\times\; \mbox{\# of Floating Point Operations/Cycle}' class='latex' /></p>
<p><br clear="all"><br />
For e.g., for a cluster with 16 identical <em>recent</em> Intel architecture compute nodes, each compute node with dual hex cores @ 3.00 GHz, <img src='http://s.wordpress.com/latex.php?latex=%5Cmathrm%7BGFLOPS%7D_%5Cmathrm%7BTheory%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\mathrm{GFLOPS}_\mathrm{Theory}' title='\mathrm{GFLOPS}_\mathrm{Theory}' class='latex' /> will be</p>
<p><br clear="all"></p>
<p class="bpcaption"><img src='http://s.wordpress.com/latex.php?latex=%20%5Cmbox%7B16%20%28%5C%23%20of%20Nodes%29%7D%20%5C%3B%5Ctimes%5C%3B%20%5Cmbox%7B2%20%28%5C%23%20of%20Sockets%2FNode%29%7D%20%5C%3B%5Ctimes%5C%3B%20%5Cmbox%7B6%20%28%5C%23%20of%20Cores%2FSocket%29%7D%20%5C%3B%5Ctimes%5C%3B%20%5C%5C%5C%5C%5Cmbox%7B3%20G%20%5BCPU%20Frequency%20%28Cycles%2Fsecond%29%5D%7D%20%5C%3B%5Ctimes%5C%3B%20%5Cmbox%7B4%20%28%5C%23%20of%20Floating%20Point%20Operations%2FCycle%29%7D%5C%5C%5C%5C%20%3D%202304%20%5Cmbox%7B%20GFLOPS%7D%20%5C%5C%5C%5C%20%5Capprox%202.3%20%5Cmbox%7B%20TFLOPS%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt=' \mbox{16 (\# of Nodes)} \;\times\; \mbox{2 (\# of Sockets/Node)} \;\times\; \mbox{6 (\# of Cores/Socket)} \;\times\; \\\\\mbox{3 G [CPU Frequency (Cycles/second)]} \;\times\; \mbox{4 (\# of Floating Point Operations/Cycle)}\\\\ = 2304 \mbox{ GFLOPS} \\\\ \approx 2.3 \mbox{ TFLOPS}' title=' \mbox{16 (\# of Nodes)} \;\times\; \mbox{2 (\# of Sockets/Node)} \;\times\; \mbox{6 (\# of Cores/Socket)} \;\times\; \\\\\mbox{3 G [CPU Frequency (Cycles/second)]} \;\times\; \mbox{4 (\# of Floating Point Operations/Cycle)}\\\\ = 2304 \mbox{ GFLOPS} \\\\ \approx 2.3 \mbox{ TFLOPS}' class='latex' /></p>
<p><br clear="all"><br />
If each of these nodes had 24 GB RAM, then <code>TOTAL_MEMORY_BYTES = 1024 * 1024 * 1024 * 24 * 16 = 412316860416</code><br />
and <code>TOTAL_DP_ELEMENTS = 412316860416/8 = 51539607552</code>. </p>
<p>As such, <code>N</code> values will be</p>
<p><br clear="all"></p>
<p class="bpcaption"><img src='http://s.wordpress.com/latex.php?latex=N%20%5C%3A%3D%5C%3A%20m%5C%3A%5Ctimes%5C%3A%20%5Csqrt%7B51539607552%7D%20%5C%3A%5Capprox%5C%3A%20m%5C%3A%5Ctimes%5C%3A%20227020%20%5Chspace%7B0.50in%7D%20m%3A%200.50%5C%3A%280.10%29%5C%3A0.80&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='N \:=\: m\:\times\: \sqrt{51539607552} \:\approx\: m\:\times\: 227020 \hspace{0.50in} m: 0.50\:(0.10)\:0.80' title='N \:=\: m\:\times\: \sqrt{51539607552} \:\approx\: m\:\times\: 227020 \hspace{0.50in} m: 0.50\:(0.10)\:0.80' class='latex' /></p>
<p><br clear="all"></p>
<h3 class="blog">What if the cluster has heterogeneous compute nodes?</h3>
<p>Computing <img src='http://s.wordpress.com/latex.php?latex=%5Cmathrm%7BGFLOPS%7D_%5Cmathrm%7BTheory%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\mathrm{GFLOPS}_\mathrm{Theory}' title='\mathrm{GFLOPS}_\mathrm{Theory}' class='latex' /> isn&#8217;t easy in this case; becomes even more so when these compute nodes belong to different generations as one has to account for <em>aging factor</em>. It has been a practice at Michigan Tech, in such cases, to split the cluster into different queues &#8211; one for each generation/type of compute nodes &#8211; and run the HPL benchmark separately.</p>
<p><br clear="all"></p>
<h3 class="blog">Thanks be to</h3>
<p><a href="http://marc.info/?l=npaci-rocks-discussion" target="_blank" class="underline">Rocks mailing list</a> and its participants.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fsgowtham.net%2Fblog%2F2012%2F02%2F27%2Fhpl-2-0-benchmark-with-gcc-4-1-2-on-rocks-5-4-2%2F&amp;title=HPL%202.0%20Benchmark%20With%20GCC%204.1.2%20On%20Rocks%205.4.2" id="wpa2a_4"><img src="http://sgowtham.net/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://sgowtham.net/blog/2012/02/27/hpl-2-0-benchmark-with-gcc-4-1-2-on-rocks-5-4-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>BASH &#8211; Smart Extract Utility</title>
		<link>http://sgowtham.net/blog/2011/05/04/bash-smart-extract-utility/</link>
		<comments>http://sgowtham.net/blog/2011/05/04/bash-smart-extract-utility/#comments</comments>
		<pubDate>Wed, 04 May 2011 19:38:34 +0000</pubDate>
		<dc:creator>Gowtham</dc:creator>
				<category><![CDATA[BASH]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://sgowtham.net/blog/?p=3090</guid>
		<description><![CDATA[Why This Script? As a systems administrator or as someone who dabbles in compilation technologies, it often becomes necessary to extract one or more variety of compressed files/folders. This script will automagically handle the options necessary for uncompressing different kinds of compressions. The Script 1 2 3 4 5 6 7 8 9 10 11 [...]]]></description>
			<content:encoded><![CDATA[<h3 class="blog">Why This Script?</h3>
<p>As a systems administrator or as someone who dabbles in compilation technologies, it often becomes necessary to extract one or more variety of compressed files/folders. This script will automagically handle the options necessary for uncompressing different kinds of compressions.</p>
<p><br clear="all"></p>
<h3 class="blog">The Script</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#! /bin/bash</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># BASH script to automagically uncompress different kinds of compressed files/folders</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Usage: extract.sh [COMPRESSED_FILENAME]</span>
<span style="color: #666666; font-style: italic;"># First written: Wed, 04 May 2011 05:14:10 -0400</span>
<span style="color: #666666; font-style: italic;"># Last modified: Wed, 04 May 2011 05:14:10 -0400</span>
<span style="color: #666666; font-style: italic;">#</span>
&nbsp;
<span style="color: #007800;">E_BADARGS</span>=<span style="color: #000000;">65</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$#</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>;
<span style="color: #000000; font-weight: bold;">then</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  Usage: <span style="color: #780078;">`basename $0`</span> [COMPRESSED_FILENAME]&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span>
  <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$E_BADARGS</span>
<span style="color: #000000; font-weight: bold;">else</span>
  <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> <span style="color: #007800;">$1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>;
  <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #007800;">$1</span> <span style="color: #000000; font-weight: bold;">in</span>
      <span style="color: #000000; font-weight: bold;">*</span>.tar<span style="color: #7a0874; font-weight: bold;">&#41;</span>       <span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-xvf</span>  <span style="color: #007800;">$1</span>  <span style="color: #000000; font-weight: bold;">;;</span>
      <span style="color: #000000; font-weight: bold;">*</span>.tgz<span style="color: #7a0874; font-weight: bold;">&#41;</span>       <span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-xvzf</span> <span style="color: #007800;">$1</span>  <span style="color: #000000; font-weight: bold;">;;</span>
      <span style="color: #000000; font-weight: bold;">*</span>.tar.gz<span style="color: #7a0874; font-weight: bold;">&#41;</span>    <span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-xvzf</span> <span style="color: #007800;">$1</span>  <span style="color: #000000; font-weight: bold;">;;</span>
      <span style="color: #000000; font-weight: bold;">*</span>.tbz2<span style="color: #7a0874; font-weight: bold;">&#41;</span>      <span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-xvjf</span> <span style="color: #007800;">$1</span>  <span style="color: #000000; font-weight: bold;">;;</span>
      <span style="color: #000000; font-weight: bold;">*</span>.tar.bz2<span style="color: #7a0874; font-weight: bold;">&#41;</span>   <span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-xvjf</span> <span style="color: #007800;">$1</span>  <span style="color: #000000; font-weight: bold;">;;</span>
      <span style="color: #000000; font-weight: bold;">*</span>.gz<span style="color: #7a0874; font-weight: bold;">&#41;</span>        <span style="color: #c20cb9; font-weight: bold;">gunzip</span>    <span style="color: #007800;">$1</span>  <span style="color: #000000; font-weight: bold;">;;</span>
      <span style="color: #000000; font-weight: bold;">*</span>.bz2<span style="color: #7a0874; font-weight: bold;">&#41;</span>       <span style="color: #c20cb9; font-weight: bold;">bunzip2</span>   <span style="color: #007800;">$1</span>  <span style="color: #000000; font-weight: bold;">;;</span>
      <span style="color: #000000; font-weight: bold;">*</span>.zip<span style="color: #7a0874; font-weight: bold;">&#41;</span>       <span style="color: #c20cb9; font-weight: bold;">unzip</span>     <span style="color: #007800;">$1</span>  <span style="color: #000000; font-weight: bold;">;;</span>
      <span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>           <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  '$1' file type unknown&quot;</span> <span style="color: #000000; font-weight: bold;">;;</span>
    <span style="color: #000000; font-weight: bold;">esac</span>
  <span style="color: #000000; font-weight: bold;">else</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  '$1' is not a regular file&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span>
  <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></td></tr></table></div>

<p><br clear="all"></p>
<h3 class="blog">Use it as a function!</h3>
<p>Add the following lines to <code>${HOME}/.bashrc</code> (and remember to source it).</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Smart extract function</span>
extract <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$#</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>;
  <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  Usage: extract [COMPRESSED_FILENAME]&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span>
  <span style="color: #000000; font-weight: bold;">else</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> <span style="color: #007800;">$1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>;
    <span style="color: #000000; font-weight: bold;">then</span>
      <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #007800;">$1</span> <span style="color: #000000; font-weight: bold;">in</span>
        <span style="color: #000000; font-weight: bold;">*</span>.tar<span style="color: #7a0874; font-weight: bold;">&#41;</span>       <span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-xvf</span>  <span style="color: #007800;">$1</span>  <span style="color: #000000; font-weight: bold;">;;</span>
        <span style="color: #000000; font-weight: bold;">*</span>.tgz<span style="color: #7a0874; font-weight: bold;">&#41;</span>       <span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-xvzf</span> <span style="color: #007800;">$1</span>  <span style="color: #000000; font-weight: bold;">;;</span>
        <span style="color: #000000; font-weight: bold;">*</span>.tar.gz<span style="color: #7a0874; font-weight: bold;">&#41;</span>    <span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-xvzf</span> <span style="color: #007800;">$1</span>  <span style="color: #000000; font-weight: bold;">;;</span>
        <span style="color: #000000; font-weight: bold;">*</span>.tbz2<span style="color: #7a0874; font-weight: bold;">&#41;</span>      <span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-xvjf</span> <span style="color: #007800;">$1</span>  <span style="color: #000000; font-weight: bold;">;;</span>
        <span style="color: #000000; font-weight: bold;">*</span>.tar.bz2<span style="color: #7a0874; font-weight: bold;">&#41;</span>   <span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-xvjf</span> <span style="color: #007800;">$1</span>  <span style="color: #000000; font-weight: bold;">;;</span>
        <span style="color: #000000; font-weight: bold;">*</span>.gz<span style="color: #7a0874; font-weight: bold;">&#41;</span>        <span style="color: #c20cb9; font-weight: bold;">gunzip</span>    <span style="color: #007800;">$1</span>  <span style="color: #000000; font-weight: bold;">;;</span>
        <span style="color: #000000; font-weight: bold;">*</span>.bz2<span style="color: #7a0874; font-weight: bold;">&#41;</span>       <span style="color: #c20cb9; font-weight: bold;">bunzip2</span>   <span style="color: #007800;">$1</span>  <span style="color: #000000; font-weight: bold;">;;</span>
        <span style="color: #000000; font-weight: bold;">*</span>.zip<span style="color: #7a0874; font-weight: bold;">&#41;</span>       <span style="color: #c20cb9; font-weight: bold;">unzip</span>     <span style="color: #007800;">$1</span>  <span style="color: #000000; font-weight: bold;">;;</span>
        <span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>           <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  '$1' file type unknown&quot;</span> <span style="color: #000000; font-weight: bold;">;;</span>
      <span style="color: #000000; font-weight: bold;">esac</span>
    <span style="color: #000000; font-weight: bold;">else</span>
      <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  '$1' is not a regular file&quot;</span>
      <span style="color: #7a0874; font-weight: bold;">echo</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
  <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></td></tr></table></div>

<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fsgowtham.net%2Fblog%2F2011%2F05%2F04%2Fbash-smart-extract-utility%2F&amp;title=BASH%20%26%238211%3B%20Smart%20Extract%20Utility" id="wpa2a_6"><img src="http://sgowtham.net/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://sgowtham.net/blog/2011/05/04/bash-smart-extract-utility/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>BASH &#8211; Router&#8217;s Public IP Address For Mac</title>
		<link>http://sgowtham.net/blog/2010/01/19/bash-routers-public-ip-address-for-mac/</link>
		<comments>http://sgowtham.net/blog/2010/01/19/bash-routers-public-ip-address-for-mac/#comments</comments>
		<pubDate>Tue, 19 Jan 2010 16:47:09 +0000</pubDate>
		<dc:creator>Gowtham</dc:creator>
				<category><![CDATA[AWK]]></category>
		<category><![CDATA[BASH]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[SED]]></category>

		<guid isPermaLink="false">http://sgowtham.net/blog/?p=2601</guid>
		<description><![CDATA[Why This Script? While in its simplest form of usage, this script will only print out the public (&#038; private) IP address along with the SSID to which the machine is connected to, the results therefrom can be used for a variety of other purposes &#8211; I will let your imagination fly you to your [...]]]></description>
			<content:encoded><![CDATA[<h3 class="blog">Why This Script?</h3>
<p>While in its simplest form of usage, this script will only print out the public (&#038; private) IP address along with the SSID to which the machine is connected to, the results therefrom can be used for a variety of other purposes &#8211; I will let your imagination fly you to your dream destination!</p>
<p><br clear="all"></p>
<h3 class="blog">The Script</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#! /bin/bash</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># BASH script to display the IP Address - one that the machine has, </span>
<span style="color: #666666; font-style: italic;"># as well as router's public IP Address, if any.</span>
<span style="color: #666666; font-style: italic;"># Tested on Apple Mac Snow Leopard 10.6.2</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># First written : Gowtham, Thu Dec 31 12:05:35 EST 2005</span>
<span style="color: #666666; font-style: italic;"># Last modified : Gowtham, Thu Dec 31 12:05:35 EST 2005</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># en1 is the wireless interface. </span>
<span style="color: #666666; font-style: italic;"># Change appropriately, if different</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">WIFI_INTERFACE</span>=<span style="color: #ff0000;">&quot;en1&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Details about the ${WIFI_INTERFACE}</span>
<span style="color: #c20cb9; font-weight: bold;">ifconfig</span> <span style="color: #800000;">${WIFI_INTERFACE}</span> <span style="color: #000000; font-weight: bold;">&gt;</span> public_ip.txt
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">STATUS</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">cat</span> public_ip.txt <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;status&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $4}'</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Analyze the details and display appropriate information</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$STATUS</span>&quot;</span> = <span style="color: #ff0000;">&quot;active&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>;
<span style="color: #000000; font-weight: bold;">then</span>
  <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">IPADDRESS</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">cat</span> public_ip.txt <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> broadcast <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $2}'</span><span style="color: #000000; font-weight: bold;">`</span>
  <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">SSID</span>=<span style="color: #000000; font-weight: bold;">`</span>system_profiler SPAirPortDataType <span style="color: #000000; font-weight: bold;">|</span> \
               <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-A1</span> <span style="color: #ff0000;">&quot;Current Network Information:&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> \
               <span style="color: #c20cb9; font-weight: bold;">tail</span> <span style="color: #660033;">-1</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span> <span style="color: #ff0000;">':'</span> <span style="color: #ff0000;">'{print $1}'</span> <span style="color: #000000; font-weight: bold;">|</span> \
               <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/^[ \t]*//;s/[ \t]*$//'</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #000000; font-weight: bold;">else</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot; <span style="color: #780078;">`date`</span>&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot; You are not connected to the internet&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span>
  <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Get the public IP address, $NSIP</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">NSIP</span>=<span style="color: #000000; font-weight: bold;">`</span>curl <span style="color: #660033;">-s</span> http:<span style="color: #000000; font-weight: bold;">//</span>checkip.dyndns.org <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $6}'</span> <span style="color: #000000; font-weight: bold;">|</span> \
             <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span> <span style="color: #ff0000;">'&lt;'</span> <span style="color: #ff0000;">'{print $1}'</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Compare $IPADDRESS &amp; $NSIP</span>
<span style="color: #666666; font-style: italic;"># Display appropriate information along with SSID</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$IPADDRESS</span>&quot;</span> = <span style="color: #ff0000;">&quot;<span style="color: #007800;">$NSIP</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>;
<span style="color: #000000; font-weight: bold;">then</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  <span style="color: #780078;">`date`</span>&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  SSID       : <span style="color: #007800;">$SSID</span>&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  IP Address : <span style="color: #007800;">$IPADDRESS</span>&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span>
<span style="color: #000000; font-weight: bold;">else</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  <span style="color: #780078;">`date`</span>&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  SSID                        : <span style="color: #007800;">$SSID</span>&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  Machine's static IP Address : <span style="color: #007800;">$IPADDRESS</span>&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  Router's  public IP Address : <span style="color: #007800;">$NSIP</span>&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Delete the scratch file</span>
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-f</span> public_ip.txt</pre></td></tr></table></div>

<p><br clear="all"></p>
<h3 class="blog">Screenshots</h3>
<p><br clear="all"><br />
<img src="http://sgowtham.net/blog/files/20100119/WithoutRouter.png" alt="Direct connection to the internet" title="Direct connection to the internet" class="framed"></p>
<p class="bpcaption">Directly connected to the internet</p>
<p><br clear="all"></p>
<p><img src="http://sgowtham.net/blog/files/20100119/WithRouter.png" alt="Configured behind a router" title="Configured behind a router" class="framed"></p>
<p class="bpcaption">Configured behind a router</p>
<p><br clear="all"><br />
I must thank <a href="http://glasstheplanet.org/" target="_blank">Jon DeVree</a> [<a href="http://twitter.com/nuxi/" target="_blank">@nuxi</a>] for help with a <a href="http://sgowtham.net/blog/2006/01/04/bash-routers-public-ip-address/" target="_blank">previous version</a> of this script [for linux] as well as <a href="http://www.facebook.com/profile.php?id=6601332" target="_blank">Sarah</a> for graciously letting me use her WiFi network.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fsgowtham.net%2Fblog%2F2010%2F01%2F19%2Fbash-routers-public-ip-address-for-mac%2F&amp;title=BASH%20%26%238211%3B%20Router%26%238217%3Bs%20Public%20IP%20Address%20For%20Mac" id="wpa2a_8"><img src="http://sgowtham.net/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://sgowtham.net/blog/2010/01/19/bash-routers-public-ip-address-for-mac/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>BASH &#8211; Wrappers For qstat In NPACI ROCKS 5.2.2</title>
		<link>http://sgowtham.net/blog/2009/12/10/bash-wrappers-for-qstat-in-npaci-rocks-5-2-2/</link>
		<comments>http://sgowtham.net/blog/2009/12/10/bash-wrappers-for-qstat-in-npaci-rocks-5-2-2/#comments</comments>
		<pubDate>Thu, 10 Dec 2009 20:51:33 +0000</pubDate>
		<dc:creator>Gowtham</dc:creator>
				<category><![CDATA[AWK]]></category>
		<category><![CDATA[BASH]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Rocks]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://sgowtham.net/blog/?p=2536</guid>
		<description><![CDATA[What is ROCKS? Rocks Cluster Distribution (originally called NPACI Rocks) is a Linux distribution intended for high-performance computing clusters. It was started by NPACI and the SDSC in 2000, and was initially funded in part by an NSF grant (2000-2007) but is currently funded by the followup NSF grant. Rocks was initially based on the [...]]]></description>
			<content:encoded><![CDATA[<h3 class="blog">What is ROCKS?</h3>
<p>Rocks Cluster Distribution (originally called NPACI Rocks) is a Linux distribution intended for high-performance computing clusters. It was started by NPACI and the SDSC in 2000, and was initially funded in part by an NSF grant (2000-2007)  but is currently funded by the followup NSF grant. Rocks was initially based on the Red Hat Linux distribution, however modern versions of Rocks are now based on CentOS, with a modified Anaconda installer that simplifies mass installation onto many computers. Rocks includes many tools (such as MPI) which are not part of CentOS but are integral components that make a group of computers into a cluster. Installations can be customized with additional software packages at install-time by using special user-supplied CDs (called <em>Roll CDs</em>). The Rolls extend the system by integrating seamlessly and automatically into the management and packaging mechanisms used by base software, greatly simplifying installation and configuration of large numbers of computers. Over a dozen Rolls have been created, including the SGE roll, the Condor roll, the Lustre roll, the Java roll, and the ganglia roll.</p>
<p><br clear="all"></p>
<h3 class="blog">Why wrappers?</h3>
<p>Functionality of <code>qstat</code> [part of the <strong>SGE Roll</strong>] changed in ROCKS 5.2.2 [it might have changed earlier than that, but that's when I first noticed]. To keep cluster users, supervisors and systems-administrators happy, I ended up writing these two wrappers:</p>
<p><br clear="all"></p>
<h3 class="blog">General Wrapper for <strong>qstat</strong></h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#! /bin/bash</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># A wrapper for 'qstat' command to show </span>
<span style="color: #666666; font-style: italic;"># the total number processors used/in use.</span>
<span style="color: #666666; font-style: italic;"># ROCKS 5.2.2</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Thu, 10 Dec 2009 12:27:59 -0500</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PROC_TOTAL</span>=<span style="color: #ff0000;">&quot;142&quot;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">USERS_LIST</span>=<span style="color: #ff0000;">&quot;
  user0
  user1
  user2
  user3
  user4&quot;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PROC_INUSE</span>=<span style="color: #000000; font-weight: bold;">`/</span>opt<span style="color: #000000; font-weight: bold;">/</span>gridengine<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>lx26-amd64<span style="color: #000000; font-weight: bold;">/</span>qstat <span style="color: #660033;">-u</span> <span style="color: #007800;">$USERS_LIST</span> <span style="color: #000000; font-weight: bold;">|</span> \
                  <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print} (NR&gt;2) {used_procs+=\$9} END {print used_procs}'</span> <span style="color: #000000; font-weight: bold;">|</span> \
                  <span style="color: #c20cb9; font-weight: bold;">tail</span> <span style="color: #660033;">-1</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $NF}'</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PROC_AVAIL</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">expr</span> <span style="color: #007800;">$PROC_TOTAL</span> - <span style="color: #007800;">$PROC_INUSE</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'-----------------------------------------------------------------------------------------------------------------'</span> 
<span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>gridengine<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>lx26-amd64<span style="color: #000000; font-weight: bold;">/</span>qstat <span style="color: #660033;">-u</span> <span style="color: #007800;">$USERS_LIST</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'-----------------------------------------------------------------------------------------------------------------'</span> 
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;   <span style="color: #007800;">$PROC_TOTAL</span> total processors :: <span style="color: #007800;">$PROC_INUSE</span> is/are in use :: <span style="color: #007800;">$PROC_AVAIL</span> is/are available&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'-----------------------------------------------------------------------------------------------------------------'</span>
<span style="color: #7a0874; font-weight: bold;">echo</span></pre></td></tr></table></div>

<p><br clear="all"></p>
<h3 class="blog">User Specific Wrapper for <strong>qstat</strong></h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#! /bin/bash</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># A wrapper for 'qstat' command to show only the jobs</span>
<span style="color: #666666; font-style: italic;"># submitted by a given user but show the total number</span>
<span style="color: #666666; font-style: italic;"># processors used/in use.</span>
<span style="color: #666666; font-style: italic;"># ROCKS 5.2.2</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Usage:</span>
<span style="color: #666666; font-style: italic;"># qu [USERNAME]</span>
<span style="color: #666666; font-style: italic;"># In the absence of any jobs submitted by USERNAME, or if</span>
<span style="color: #666666; font-style: italic;"># USERNAME is not specified at all, it just displays the jobs, </span>
<span style="color: #666666; font-style: italic;"># if any, by the currently logged in user.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Thu, 10 Dec 2009 12:27:59 -0500</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">EXPECTED_ARGS</span>=<span style="color: #ff0000;">&quot;1&quot;</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PROC_TOTAL</span>=<span style="color: #ff0000;">&quot;142&quot;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">USERS_LIST</span>=<span style="color: #ff0000;">&quot;
  user0
  user1
  user2
  user3
  user4&quot;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$#</span> <span style="color: #660033;">-ne</span> <span style="color: #007800;">$EXPECTED_ARGS</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>;
<span style="color: #000000; font-weight: bold;">then</span> 
  <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">MYUSER</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$USER</span>&quot;</span>
<span style="color: #000000; font-weight: bold;">else</span>
  <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">MYUSER</span>=<span style="color: #ff0000;">&quot;$1&quot;</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PROC_USER</span>=<span style="color: #000000; font-weight: bold;">`/</span>opt<span style="color: #000000; font-weight: bold;">/</span>gridengine<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>lx26-amd64<span style="color: #000000; font-weight: bold;">/</span>qstat <span style="color: #660033;">-u</span> <span style="color: #007800;">$MYUSER</span> <span style="color: #000000; font-weight: bold;">|</span> \
                 <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print} (NR&gt;2) {used_procs+=\$9} END {print used_procs}'</span> <span style="color: #000000; font-weight: bold;">|</span> \
                 <span style="color: #c20cb9; font-weight: bold;">tail</span> <span style="color: #660033;">-1</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $NF}'</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PROC_INUSE</span>=<span style="color: #000000; font-weight: bold;">`/</span>opt<span style="color: #000000; font-weight: bold;">/</span>gridengine<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>lx26-amd64<span style="color: #000000; font-weight: bold;">/</span>qstat <span style="color: #660033;">-u</span> <span style="color: #007800;">$USERS_LIST</span> <span style="color: #000000; font-weight: bold;">|</span> \
                  <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print} (NR&gt;2) {used_procs+=\$9} END {print used_procs}'</span> <span style="color: #000000; font-weight: bold;">|</span> \
                  <span style="color: #c20cb9; font-weight: bold;">tail</span> <span style="color: #660033;">-1</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $NF}'</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PROC_AVAIL</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">expr</span> <span style="color: #007800;">$PROC_TOTAL</span> - <span style="color: #007800;">$PROC_INUSE</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$PROC_USER</span> <span style="color: #660033;">-gt</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> ;
<span style="color: #000000; font-weight: bold;">then</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'-----------------------------------------------------------------------------------------------------------------'</span> 
  <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>gridengine<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>lx26-amd64<span style="color: #000000; font-weight: bold;">/</span>qstat <span style="color: #660033;">-u</span> <span style="color: #007800;">$MYUSER</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'-----------------------------------------------------------------------------------------------------------------'</span> 
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot; <span style="color: #007800;">$PROC_TOTAL</span> total processors :: <span style="color: #007800;">$PROC_INUSE</span> is/are in use :: <span style="color: #007800;">$PROC_USER</span> is/are use by <span style="color: #007800;">$MYUSER</span> :: <span style="color: #007800;">$PROC_AVAIL</span> is/are available &quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'-----------------------------------------------------------------------------------------------------------------'</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span>
<span style="color: #000000; font-weight: bold;">else</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  <span style="color: #780078;">`hostname`</span> @ <span style="color: #780078;">`date -R`</span>&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  <span style="color: #007800;">$PROC_TOTAL</span> total processors&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  <span style="color: #007800;">$PROC_INUSE</span> is/are in use &quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  0 is/are use by <span style="color: #007800;">$MYUSER</span>&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  <span style="color: #007800;">$PROC_AVAIL</span> is/are available &quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></td></tr></table></div>

<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fsgowtham.net%2Fblog%2F2009%2F12%2F10%2Fbash-wrappers-for-qstat-in-npaci-rocks-5-2-2%2F&amp;title=BASH%20%26%238211%3B%20Wrappers%20For%20qstat%20In%20NPACI%20ROCKS%205.2.2" id="wpa2a_10"><img src="http://sgowtham.net/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://sgowtham.net/blog/2009/12/10/bash-wrappers-for-qstat-in-npaci-rocks-5-2-2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PERL &#8211; Retrieving Data From MySQL Databases In Different Servers</title>
		<link>http://sgowtham.net/blog/2009/03/04/perl-retrieving-data-from-mysql-databases-in-different-servers/</link>
		<comments>http://sgowtham.net/blog/2009/03/04/perl-retrieving-data-from-mysql-databases-in-different-servers/#comments</comments>
		<pubDate>Wed, 04 Mar 2009 08:07:04 +0000</pubDate>
		<dc:creator>Gowtham</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PERL]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Twitter]]></category>

		<guid isPermaLink="false">http://sgowtham.net/blog/?p=1846</guid>
		<description><![CDATA[Let us consider the following (hypothetical/real) case: we have a fruit basket with an assortment of fruits in it. Over a period of time, let us suppose we accumulate so much fruit [will they not stink? may be - but that's a problem beyond the scope of PERL &#038; MySQL] that one basket can no [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://sgowtham.net/blog/files/20090304/fruit_basket.png" alt="Fruit Basket" title="Fruit Basket" align="left" width="175" vspace="10" hspace="10"> Let us consider the following (hypothetical/real) case: we have a fruit basket with an assortment of fruits in it. Over a period of time, let us suppose we accumulate so much fruit [<em>will they not stink?</em> may be - but that's a problem beyond the scope of PERL &#038; MySQL] that one basket can no longer hold all the fruits. One possible [and meaningful] way to solve this problem is to introduce another basket and segregate fruits into either one of the two baskets. To make it bit more elegant, we should probably make sure that a given kind of fruit is stored in only one of the baskets. Then, when someone asks us for a fruit &#8211; say an Apple &#8211; we know which basket contains apples and we can readily pick them out; when someone else asks for an Orange, we can repeat the process; and so on.</p>
<p><br clear="all"></p>
<h3 class="blog">What does fruit basket have anything to do with PERL/MySQL?</h3>
<p>Analogically speaking, we can consider fruits as some form of data/information while baskets can be considered as different servers/MySQL databases. Also, our thought/action process &#8211; of deciding whether to choose from one or both baskets &#8211; can be formulated as a PERL script. While some parts of transforming this problem into a script were relatively <em>easy</em>, the task of merging the information acquired from different servers/databases and presenting them as one unit [consider this as packaging fruits] bugged me for a really long time. </p>
<p><br clear="all"></p>
<h3 class="blog">Tweet [and Email] to find answers!</h3>
<p><img align="right" src="http://sgowtham.net/blog/files/20090304/twitter.png" alt="Twitter" title="Twitter" vspace="10" hspace="10"> After many sleepless nights &#038; weekends, several trips to Princeton, long discussions with myself and friends, I decided to seek help through couple of very trusted sources: <a href="http://www.lug.mtu.edu/" target="_blank" class="underline">Linux Users Group @ Michigan Tech</a> and <a href="http://www.twitter.com/sgowtham/" target="_blank" class="underline">Twitter</a>. And needless to say, the answer wasn&#8217;t too far along &#8211; thanks mainly to Derek LaHousse (<a href="http://www.twitter.com/ManoftheSea/" target="_blank" class="underline">@ManoftheSea</a>), <a href="http://glasstheplanet.org/" target="_blank" class="underline">Jon DeVree</a> (<a href="http://www.twitter.com/nuxi/" target="_blank" class="underline">@nuxi</a>) and <a href="http://adamjaskie.livejournal.com/" target="_blank" class="underline">Adam Jaskiewicz</a> (<a href="http://www.twitter.com/ajjaskie/" target="_blank" class="underline">@ajjaskie</a>) took time out of their busy schedules to help out with blocks of code. Owing to the kind of problem at hand, Jaskie&#8217;s code block fit the requirements perfectly. </p>
<p><br clear="all"></p>
<h3 class="blog">PERL script to query MySQL databases in different servers</h3>
<p>For completeness sake, let us suppose that the two servers are named <em>server1.domain.com</em> and <em>server2.domain.com</em>; the two databases are named <em>database1</em> and <em>database2</em>; these two databases have the exact same table names/structure but data pertaining to uniquely different sets of fruits. MySQL userid and password could be same or different, but for sake of generalization, let us assume <em>username1/password1</em> applies to <em>database1</em> while <em>username2/password2</em> applies to <em>database2</em>. Needless to say, this set up can be generalized to N servers.</p>
<p><br clear="all"></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
</pre></td><td class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#! /usr/bin/perl -wT</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">use</span> DBI<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> CGI<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> CGI<span style="color: #339933;">::</span><span style="color: #006600;">Carp</span> <span style="color: #000066;">qw</span> <span style="color: #009900;">&#40;</span> fatalsToBrowser <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> File<span style="color: #339933;">::</span><span style="color: #006600;">Basename</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Server Name, Database, UserID and Password</span>
<span style="color: #0000ff;">$hostname1</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;server1.domain.com&quot;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$database1</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;database1&quot;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$userid1</span>   <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;userid1&quot;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$password1</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;password1&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">$hostname2</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;server2.domain.com&quot;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$database2</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;database2&quot;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$userid2</span>   <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;userid2&quot;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$password2</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;password2&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Sample Query Statements</span>
<span style="color: #666666; font-style: italic;"># $stmt=&quot;SELECT * FROM FruitBasket&quot;;</span>
<span style="color: #666666; font-style: italic;"># $stmt = &quot;SELECT * FROM FruitBasket WHERE FruitName='Apple'&quot;;</span>
<span style="color: #666666; font-style: italic;"># $stmt = &quot;SELECT * FROM FruitBasket WHERE FruitName='Orange'&quot;;</span>
<span style="color: #0000ff;">$stmt</span><span style="color: #339933;">=</span><span style="color: #ff0000;">&quot;SELECT * FROM FruitBasket WHERE FruitName='Apple' OR FruitName='Orange'&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Uncomment for debugging purposes only</span>
<span style="color: #666666; font-style: italic;"># print &quot;$stmt\n&quot;;</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$stmt</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">m/(FruitName)/</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;"># Uncomment for debugging purposes only</span>
  <span style="color: #666666; font-style: italic;"># print &quot;FruitName found.\n&quot;;</span>
&nbsp;
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$stmt</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">m/(Apple|Banana|Pineapple)/</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># Uncomment for debugging purposes only</span>
    <span style="color: #666666; font-style: italic;"># print &quot;Apple|Banana|Pineapple :: Query server1.domain.com\n&quot;;</span>
&nbsp;
    <span style="color: #0000ff;">$dbh</span> <span style="color: #339933;">=</span> DBI<span style="color: #339933;">-&gt;</span><span style="color: #006600;">connect</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;dbi:mysql:$database1:$hostname1&quot;</span><span style="color: #339933;">,</span><span style="color: #ff0000;">&quot;$userid1&quot;</span><span style="color: #339933;">,</span><span style="color: #ff0000;">&quot;$password1&quot;</span><span style="color: #009900;">&#41;</span>
           <span style="color: #b1b100;">or</span> <span style="color: #000066;">die</span> <span style="color: #ff0000;">&quot;Error!&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$h1</span>  <span style="color: #339933;">=</span> <span style="color: #0000ff;">$dbh</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$stmt</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$h1</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">execute</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$r1</span>  <span style="color: #339933;">=</span> <span style="color: #0000ff;">$h1</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">fetchall_arrayref</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #0000ff;">@final_result</span><span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@$r1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$stmt</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">m/(Grape|Orange|Peach|Tomato)/</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># Uncomment for debugging purposes only</span>
    <span style="color: #666666; font-style: italic;"># print &quot;Grape|Orange|Peach|Tomato :: Query server2.domain.com\n&quot;;</span>
&nbsp;
    <span style="color: #0000ff;">$dbh</span> <span style="color: #339933;">=</span> DBI<span style="color: #339933;">-&gt;</span><span style="color: #006600;">connect</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;dbi:mysql:$database2:$hostname2&quot;</span><span style="color: #339933;">,</span><span style="color: #ff0000;">&quot;$userid2&quot;</span><span style="color: #339933;">,</span><span style="color: #ff0000;">&quot;$password2&quot;</span><span style="color: #009900;">&#41;</span>
           <span style="color: #b1b100;">or</span> <span style="color: #000066;">die</span> <span style="color: #ff0000;">&quot;Error!&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$h2</span>  <span style="color: #339933;">=</span> <span style="color: #0000ff;">$dbh</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$stmt</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$h2</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">execute</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$r2</span>  <span style="color: #339933;">=</span> <span style="color: #0000ff;">$h2</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">fetchall_arrayref</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #0000ff;">@final_result</span><span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@$r2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;"># FruitType not present in the query statement.</span>
<span style="color: #666666; font-style: italic;"># Case where someone asks 'bring me some fruits'</span>
&nbsp;
  <span style="color: #666666; font-style: italic;"># Uncomment for debugging purposes only</span>
  <span style="color: #666666; font-style: italic;"># print &quot;Query server1.domain.com and server2.domain.com\n&quot;;</span>
&nbsp;
  <span style="color: #0000ff;">$dbh</span> <span style="color: #339933;">=</span> DBI<span style="color: #339933;">-&gt;</span><span style="color: #006600;">connect</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;dbi:mysql:$database1:$hostname1&quot;</span><span style="color: #339933;">,</span><span style="color: #ff0000;">&quot;$userid1&quot;</span><span style="color: #339933;">,</span><span style="color: #ff0000;">&quot;$password1&quot;</span><span style="color: #009900;">&#41;</span>
         <span style="color: #b1b100;">or</span> <span style="color: #000066;">die</span> <span style="color: #ff0000;">&quot;Error!&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #0000ff;">$h1</span>  <span style="color: #339933;">=</span> <span style="color: #0000ff;">$dbh</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$stmt</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #0000ff;">$h1</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">execute</span><span style="color: #339933;">;</span>
  <span style="color: #0000ff;">$r1</span>  <span style="color: #339933;">=</span> <span style="color: #0000ff;">$h1</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">fetchall_arrayref</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #0000ff;">$dbh</span> <span style="color: #339933;">=</span> DBI<span style="color: #339933;">-&gt;</span><span style="color: #006600;">connect</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;dbi:mysql:$database2:$hostname2&quot;</span><span style="color: #339933;">,</span><span style="color: #ff0000;">&quot;$userid2&quot;</span><span style="color: #339933;">,</span><span style="color: #ff0000;">&quot;$password2&quot;</span><span style="color: #009900;">&#41;</span>
         <span style="color: #b1b100;">or</span> <span style="color: #000066;">die</span> <span style="color: #ff0000;">&quot;Error!&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #0000ff;">$h2</span>  <span style="color: #339933;">=</span> <span style="color: #0000ff;">$dbh</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$stmt</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #0000ff;">$h2</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">execute</span><span style="color: #339933;">;</span>
  <span style="color: #0000ff;">$r2</span>  <span style="color: #339933;">=</span> <span style="color: #0000ff;">$h2</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">fetchall_arrayref</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #0000ff;">@final_result</span><span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@$r1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">@$r2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Loop through the @final_result array and print the results</span>
<span style="color: #b1b100;">for</span> <span style="color: #0000ff;">$array_ref</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">@final_result</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;@$array_ref <span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><br clear="all"></p>
<h3 class="blog">Is there a better way of doing the same thing?</h3>
<p>There probably is one &#8211; one could keep the information about fruits &#038; server/database names in a flat text file (as a mapping file), read that in and compare it with <em>$stmt</em>. For now, this seems to be doing the job and as I find more time, I will look into it. If you find this useful and/or find bugs/mistakes and/or have other elegant methods of accomplishing the same thing, please do share them &#8211; readers, including me, will greatly appreciate it.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fsgowtham.net%2Fblog%2F2009%2F03%2F04%2Fperl-retrieving-data-from-mysql-databases-in-different-servers%2F&amp;title=PERL%20%26%238211%3B%20Retrieving%20Data%20From%20MySQL%20Databases%20In%20Different%20Servers" id="wpa2a_12"><img src="http://sgowtham.net/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://sgowtham.net/blog/2009/03/04/perl-retrieving-data-from-mysql-databases-in-different-servers/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>BASH &#8211; GZIP or BZIP2?</title>
		<link>http://sgowtham.net/blog/2008/10/19/bash-gzip-or-bzip2/</link>
		<comments>http://sgowtham.net/blog/2008/10/19/bash-gzip-or-bzip2/#comments</comments>
		<pubDate>Sun, 19 Oct 2008 16:27:39 +0000</pubDate>
		<dc:creator>Gowtham</dc:creator>
				<category><![CDATA[AWK]]></category>
		<category><![CDATA[BASH]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://sgowtham.net/blog/?p=1081</guid>
		<description><![CDATA[BASH is a free software Unix shell written for the GNU Project. Its name is an acronym which stands for Bourne-again shell. The name is a pun on the name of the Bourne shell (sh), an early and important UNIX shell written by Stephen Bourne and distributed with Version 7 Unix circa 1978, and the [...]]]></description>
			<content:encoded><![CDATA[<p>BASH is a free software Unix shell written for the GNU Project. Its name is an acronym which stands for <em>Bourne-again shell</em>. The name is a pun on the name of the Bourne shell (<strong>sh</strong>), an early and important UNIX shell written by Stephen Bourne and distributed with Version 7 Unix circa 1978, and the concept of being <em>born again</em>. BASH was created in 1987 by Brian Fox. In 1990 Chet Ramey became the primary maintainer. BASH is the default shell on most GNU/Linux systems as well as on Mac OS X and it can be run on most UNIX-like operating systems. It has also been ported to Microsoft Windows using the POSIX emulation provided by Cygwin, to MS-DOS by the DJGPP project and to Novell NetWare.</p>
<p>AWK is a general purpose programming language that is designed for processing text-based data, either in files or data streams, and was created at Bell Labs in the 1970s. The name AWK is derived from the family names of its authors — Alfred <strong>A</strong>ho, Peter <strong>W</strong>einberger, and Brian <strong>K</strong>ernighan; however, it is not commonly pronounced as a string of separate letters but rather to sound the same as the name of the bird, <strong>auk</strong>. <em>awk</em>, when written in all lowercase letters, refers to the UNIX or Plan 9 program that runs other programs written in the AWK programming language. AWK is an example of a programming language that extensively uses the string data type, associative arrays (that is, arrays indexed by key strings), and regular expressions. The power, terseness, and limitations of AWK programs and <strong>sed</strong> scripts inspired Larry Wall to write PERL. Because of their dense notation, all these languages are often used for writing one-liner programs. AWK is one of the early tools to appear in Version 7 UNIX and gained popularity as a way to add computational features to a UNIX pipeline. A version of the AWK language is a standard feature of nearly every modern UNIX-like operating system.</p>
<p><br clear="all"></p>
<h3 class="blog">The Script</h3>
<p>Often times, it becomes necessary to compress files to save (or make) space (for more files??). With the availability of <strong>gzip</strong> and <strong>bzip2</strong> on most Linux distributions, often times one is left to ponder &#8211; <em>which mechanism is better for a given file?</em> Although it&#8217;s a common understanding that <em>bigger the file size, bzip2 performs better</em>, the following script is expected to help one in that matter. It compresses a given file with both options, compares the resulting filesize with the original (uncompressed) file and then makes a decision to retain one of the three (uncompressed, gzipped or bzipped).</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#! /bin/bash</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># BASH script that takes ONE filename as a (mandatory) argument</span>
<span style="color: #666666; font-style: italic;"># and compresses them using both 'GZIP' and 'BZIP2'. Then, compares</span>
<span style="color: #666666; font-style: italic;"># the filesizes and retains the one with the smallest value.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;"># Usage: ./optimal_compression.sh [FILENAME]</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># 01 September, 2006</span>
<span style="color: #666666; font-style: italic;"># Tue, 14 Oct 2008 12:53:11 -0400</span>
<span style="color: #666666; font-style: italic;"># Sun, 19 Oct 2008 12:08:36 -0400</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$#</span> <span style="color: #660033;">-ne</span> <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>;
<span style="color: #000000; font-weight: bold;">then</span>
  <span style="color: #666666; font-style: italic;"># Display error message when no (or more than one) files are specified as arguments</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot; You must specify a filename&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span>
  <span style="color: #7a0874; font-weight: bold;">exit</span>
<span style="color: #000000; font-weight: bold;">else</span>
&nbsp;
  <span style="color: #666666; font-style: italic;"># Assign the supplied filename to a variable</span>
  <span style="color: #007800;">FILENAME</span>=<span style="color: #007800;">$1</span>
&nbsp;
  <span style="color: #666666; font-style: italic;"># Other useful variables</span>
  <span style="color: #007800;">TODAY</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #ff0000;">&quot;%Y%m%d_%H%M%S&quot;</span><span style="color: #000000; font-weight: bold;">`</span>
  <span style="color: #007800;">BZIP</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">which</span> <span style="color: #c20cb9; font-weight: bold;">bzip2</span><span style="color: #000000; font-weight: bold;">`</span>
  <span style="color: #007800;">GZIP</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">which</span> <span style="color: #c20cb9; font-weight: bold;">gzip</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
  <span style="color: #666666; font-style: italic;"># Temporary files that contain compressed data</span>
  <span style="color: #007800;">BZIP_FILE</span>=<span style="color: #ff0000;">&quot;/tmp/tmp_<span style="color: #007800;">$TODAY</span>.bz2&quot;</span>
  <span style="color: #007800;">GZIP_FILE</span>=<span style="color: #ff0000;">&quot;/tmp/tmp_<span style="color: #007800;">$TODAY</span>.gz&quot;</span>
&nbsp;
&nbsp;
  <span style="color: #666666; font-style: italic;"># Compress the files with gzip and bzip2</span>
  <span style="color: #666666; font-style: italic;"># One may add '&amp;' at the end of the lines below and</span>
  <span style="color: #666666; font-style: italic;"># uncomment 'wait' line, if really big files are being</span>
  <span style="color: #666666; font-style: italic;"># compressed. It may save time. However, the definition</span>
  <span style="color: #666666; font-style: italic;"># OPTIMUM might need some modification if done so.</span>
  <span style="color: #007800;">$BZIP</span> <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #007800;">$FILENAME</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #007800;">$BZIP_FILE</span>
  <span style="color: #007800;">$GZIP</span> <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #007800;">$FILENAME</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #007800;">$GZIP_FILE</span>
  <span style="color: #666666; font-style: italic;"># wait</span>
&nbsp;
  <span style="color: #666666; font-style: italic;"># Compare file size - of normal, gzipped and bzipped files</span>
  <span style="color: #666666; font-style: italic;"># and determine which one has the smallest (optimal) value.</span>
  <span style="color: #666666; font-style: italic;"># Remember, 'ls -l' sorts filenames alphabetically</span>
  <span style="color: #007800;">OPTIMUM</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-ltr</span> <span style="color: #007800;">$FILENAME</span> <span style="color: #007800;">$BZIP_FILE</span> <span style="color: #007800;">$GZIP_FILE</span> <span style="color: #000000; font-weight: bold;">|</span> \
           <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $5&quot;:&quot;NR}'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sort</span> <span style="color: #660033;">-n</span> <span style="color: #000000; font-weight: bold;">|</span> \
           <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span> <span style="color: #ff0000;">':'</span> <span style="color: #ff0000;">'{if ($1 != &quot;&quot;) { print $2 }}'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">head</span> -<span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$OPTIMUM</span>&quot;</span> <span style="color: #000000; font-weight: bold;">in</span>
    <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">echo</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot; <span style="color: #007800;">$FILENAME</span> not compressed.&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span>
        <span style="color: #000000; font-weight: bold;">;;</span>
    <span style="color: #000000;">2</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">echo</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot; <span style="color: #007800;">$FILENAME</span> compressed with <span style="color: #007800;">$BZIP</span> =&gt; <span style="color: #007800;">$FILENAME</span>.bz2&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span>
        <span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #007800;">$BZIP_FILE</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$FILENAME</span>.bz2&quot;</span> 
        <span style="color: #000000; font-weight: bold;">;;</span>
    <span style="color: #000000;">3</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">echo</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot; <span style="color: #007800;">$FILENAME</span> compressed with <span style="color: #007800;">$GZIP</span> =&gt; <span style="color: #007800;">$FILENAME</span>.gz&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span>
        <span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #007800;">$GZIP_FILE</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$FILENAME</span>.gz&quot;</span> 
        <span style="color: #000000; font-weight: bold;">;;</span>
  <span style="color: #000000; font-weight: bold;">esac</span>
&nbsp;
  <span style="color: #666666; font-style: italic;"># Remove temporary files </span>
  <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-f</span> <span style="color: #007800;">$FILENAME</span> <span style="color: #007800;">$BZIP_FILE</span> <span style="color: #007800;">$GZIP_FILE</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></td></tr></table></div>

<p><br clear="all"><br />
<img class="framed" src="http://sgowtham.net/blog/files/20081019/optimal_compression.png" alt="Optimal Compression" title="Optimal Compression"></p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fsgowtham.net%2Fblog%2F2008%2F10%2F19%2Fbash-gzip-or-bzip2%2F&amp;title=BASH%20%26%238211%3B%20GZIP%20or%20BZIP2%3F" id="wpa2a_14"><img src="http://sgowtham.net/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://sgowtham.net/blog/2008/10/19/bash-gzip-or-bzip2/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>PERL &#8211; Mapping Elements To Their Respective Arrays</title>
		<link>http://sgowtham.net/blog/2008/10/15/perl-mapping-elements-to-their-respective-arrays/</link>
		<comments>http://sgowtham.net/blog/2008/10/15/perl-mapping-elements-to-their-respective-arrays/#comments</comments>
		<pubDate>Wed, 15 Oct 2008 16:19:25 +0000</pubDate>
		<dc:creator>Gowtham</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[PERL]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://sgowtham.net/blog/?p=1052</guid>
		<description><![CDATA[Often times, a need arises where one has to search a bunch of arrays to find out to which one of them a given set of elements belong. Of course, life becomes a lot simpler if those arrays are unique (meaning any given element appears only in one of the arrays) and life may not [...]]]></description>
			<content:encoded><![CDATA[<p>Often times, a need arises where one has to search a bunch of arrays to find out to which one of them a given set of elements belong. Of course, life becomes a lot simpler if those arrays are unique (meaning any given element appears only in one of the arrays) and life may not always be that simple. Some common examples of such simple case include, but not limited to, the following:</p>
<ol>
<li>Decide which fruit belongs to which basket</li>
<li>Decide which database to query based on a set criterion. Certainly helps if the array names are the same as respective database names. There are potentially very many such database driven applications</li>
<li>And so on.</li>
</ol>
<p>If you are looking for methods to map just one element (in question) to its array, you may refer to my <a href="http://sgowtham.net/blog/2008/10/11/perl-mapping-an-element-to-its-array/" target="_blank">previous write up</a>.</p>
<p><br clear="all"></p>
<h3 class="blog">The Script/Module</h3>
<p>Save the following into a file and call it, <strong>elements_arrays_map.pl</strong> (or <strong>elements_arrays_map.pm</strong>, as the need may be). It provides a function/sub routine that takes the <strong>element names</strong> as the input and returns the <strong>array names</strong> to which the requested elements belong as an array. The sub-routine makes a hash of all  the arrays and uses <strong>foreach</strong> loop to sift through them. The array name (depending on the application), can subsequently used appropriately. (Re)naming the variables and functions to describe the specific application may also be useful.</p>
<p><br clear="all"></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
</pre></td><td class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#! /usr/bin/perl -wT</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># PERL module/script to decide to which array an element belongs to</span>
<span style="color: #666666; font-style: italic;"># when there are multiple arrays.</span>
<span style="color: #666666; font-style: italic;"># Assumes that the arrays contain UNIQUE element names</span>
<span style="color: #666666; font-style: italic;"># Element_Array_Map() takes in elementNames as input and returns the </span>
<span style="color: #666666; font-style: italic;"># name of arrays they are in.</span>
<span style="color: #666666; font-style: italic;"># </span>
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># sub Elements_Arrays_Map() BEGINS</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> Elements_Arrays_Map <span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Requested elementNames</span>
&nbsp;
  <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@elements</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">@_</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Uncomment the following lines for debugging purposes</span>
<span style="color: #666666; font-style: italic;"># foreach my $element (@{elements}) {</span>
<span style="color: #666666; font-style: italic;">#   print &quot;Requested element is $element\n&quot;;</span>
<span style="color: #666666; font-style: italic;"># }</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># A hash of arrays</span>
<span style="color: #666666; font-style: italic;"># Each array contains several element names</span>
<span style="color: #666666; font-style: italic;"># Each array can have different number of elements </span>
<span style="color: #666666; font-style: italic;"># Elements of each array are UNIQUE</span>
<span style="color: #666666; font-style: italic;"># Hash definition can be modified to include 'N' arrays</span>
&nbsp;
  <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">%HASH_OF_ARRAYS</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>
      ARRAY1 <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#91;</span><span style="color: #ff0000;">'Element1'</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'Element2'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> 
      ARRAY2 <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#91;</span><span style="color: #ff0000;">'Element3'</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'Element4'</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'Element5'</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'Element6'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
      ARRAY3 <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#91;</span><span style="color: #ff0000;">'Element7'</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'Element8'</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'Element9'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
      ARRAY4 <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#91;</span><span style="color: #ff0000;">'Element0'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
      <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Search the hash of arrays to find out to which arrays do the </span>
<span style="color: #666666; font-style: italic;"># requested elements belong</span>
&nbsp;
  <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">foreach</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$element</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><span style="color: #009900;">&#123;</span>elements<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">foreach</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$element_array</span> <span style="color: #009900;">&#40;</span><span style="color: #000066;">keys</span> <span style="color: #0000ff;">%HASH_OF_ARRAYS</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$HASH_OF_ARRAYS</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$element_array</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$element</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">m/$_/</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>  
          <span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;$element is in $element_array<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
          <span style="color: #0000ff;">$output_array</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$element_array</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #0000ff;">$i</span><span style="color: #339933;">++;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000066;">return</span> <span style="color: #0000ff;">@output_array</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> 
<span style="color: #666666; font-style: italic;"># sub Elements_Arrays_Map() ENDS</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Call it after the function to avoid the following error</span>
<span style="color: #666666; font-style: italic;"># 'main::Elements_Arrays_Map() called too early to check prototype'</span>
<span style="color: #666666; font-style: italic;"># If not using '-wT' flags, this function can be called before its </span>
<span style="color: #666666; font-style: italic;"># definition. The value '@output_array' can be passed on to other </span>
<span style="color: #666666; font-style: italic;"># modules/scripts, if necessary.</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@elementNames</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Element1&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Element0&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Element4&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@output_array</span> <span style="color: #339933;">=</span> Elements_Arrays_Map<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@elementNames</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Uncomment the following line for debugging purposes</span>
<span style="color: #666666; font-style: italic;"># print &quot;$element_array\n&quot;;</span></pre></td></tr></table></div>

<p><br clear="all"><br />
<img class="framed" src="http://sgowtham.net/blog/files/20081015/elements_arrays_map.png" alt="Mapping Elements To Their Respective Arrays" title="Mapping Elements To Their Respective Arrays"></p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fsgowtham.net%2Fblog%2F2008%2F10%2F15%2Fperl-mapping-elements-to-their-respective-arrays%2F&amp;title=PERL%20%26%238211%3B%20Mapping%20Elements%20To%20Their%20Respective%20Arrays" id="wpa2a_16"><img src="http://sgowtham.net/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://sgowtham.net/blog/2008/10/15/perl-mapping-elements-to-their-respective-arrays/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>BASH &#8211; Wrappers For qstat In NPACI ROCKS</title>
		<link>http://sgowtham.net/blog/2008/10/13/bash-wrappers-for-qstat-in-npaci-rocks/</link>
		<comments>http://sgowtham.net/blog/2008/10/13/bash-wrappers-for-qstat-in-npaci-rocks/#comments</comments>
		<pubDate>Mon, 13 Oct 2008 22:34:07 +0000</pubDate>
		<dc:creator>Gowtham</dc:creator>
				<category><![CDATA[AWK]]></category>
		<category><![CDATA[BASH]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Rocks]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://sgowtham.net/blog/?p=975</guid>
		<description><![CDATA[BASH is a free software UNIX shell written for the GNU Project. Its name is an acronym which stands for Bourne-again shell. The name is a pun on the name of the Bourne shell (sh), an early and important UNIX shell written by Stephen Bourne and distributed with Version 7 UNIX circa 1978, and the [...]]]></description>
			<content:encoded><![CDATA[<p>BASH is a free software UNIX shell written for the GNU Project. Its name is an acronym which stands for <em>Bourne-again shell</em>. The name is a pun on the name of the Bourne shell (<strong>sh</strong>), an early and important UNIX shell written by Stephen Bourne and distributed with Version 7 UNIX circa 1978, and the concept of being <em>born again</em>. BASH was created in 1987 by Brian Fox. In 1990 Chet Ramey became the primary maintainer. BASH is the default shell on most GNU/Linux systems as well as on Mac OS X and it can be run on most UNIX-like operating systems. It has also been ported to Microsoft Windows using the POSIX emulation provided by Cygwin, to MS-DOS by the DJGPP project and to Novell NetWare.</p>
<p>AWK is a general purpose programming language that is designed for processing text-based data, either in files or data streams, and was created at Bell Labs in the 1970s. The name AWK is derived from the family names of its authors — Alfred <strong>A</strong>ho, Peter <strong>W</strong>einberger, and Brian <strong>K</strong>ernighan; however, it is not commonly pronounced as a string of separate letters but rather to sound the same as the name of the bird, <strong>auk</strong>. <em>awk</em>, when written in all lowercase letters, refers to the UNIX or Plan 9 program that runs other programs written in the AWK programming language. AWK is an example of a programming language that extensively uses the string data type, associative arrays (that is, arrays indexed by key strings), and regular expressions. The power, terseness, and limitations of AWK programs and <strong>sed</strong> scripts inspired Larry Wall to write PERL. Because of their dense notation, all these languages are often used for writing one-liner programs. AWK is one of the early tools to appear in Version 7 UNIX and gained popularity as a way to add computational features to a UNIX pipeline. A version of the AWK language is a standard feature of nearly every modern UNIX-like operating system.</p>
<p><br clear="all"></p>
<h3 class="blog">What is ROCKS?</h3>
<p>Rocks Cluster Distribution (originally called NPACI Rocks) is a Linux distribution intended for high-performance computing clusters. It was started by NPACI and the SDSC in 2000, and was initially funded in part by an NSF grant (2000-2007)  but is currently funded by the followup NSF grant. Rocks was initially based on the Red Hat Linux distribution, however modern versions of Rocks are now based on CentOS, with a modified Anaconda installer that simplifies mass installation onto many computers. Rocks includes many tools (such as MPI) which are not part of CentOS but are integral components that make a group of computers into a cluster. Installations can be customized with additional software packages at install-time by using special user-supplied CDs (called <em>Roll CDs</em>). The Rolls extend the system by integrating seamlessly and automatically into the management and packaging mechanisms used by base software, greatly simplifying installation and configuration of large numbers of computers. Over a dozen Rolls have been created, including the SGE roll, the Condor roll, the Lustre roll, the Java roll, and the ganglia roll.</p>
<p><br clear="all"></p>
<h3 class="blog">General Wrapper for <strong>qstat</strong></h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#! /bin/bash</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Save this as /home/local/bin/qstat</span>
<span style="color: #666666; font-style: italic;"># A wrapper for 'qstat' command to show all currently submitted jobs along</span>
<span style="color: #666666; font-style: italic;"># with the total number processors used/in use</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Check the path to 'qstat'</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Thu, 02 Oct 2008 21:06:05 -0400</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Modify this variable to meet the cluster's requirements</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PROC_TOTAL</span>=<span style="color: #ff0000;">&quot;128&quot;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PROC_INUSE</span>=<span style="color: #000000; font-weight: bold;">`/</span>opt<span style="color: #000000; font-weight: bold;">/</span>gridengine<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>lx26-amd64<span style="color: #000000; font-weight: bold;">/</span>qstat <span style="color: #000000; font-weight: bold;">|</span> \
       <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print} (NR&gt;2) {used_procs+=\$9} END {print used_procs}'</span> <span style="color: #000000; font-weight: bold;">|</span> \
       <span style="color: #c20cb9; font-weight: bold;">tail</span> <span style="color: #660033;">-1</span> <span style="color: #000000; font-weight: bold;">|</span> \
       <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $NF}'</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PROC_AVAIL</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">expr</span> <span style="color: #007800;">$PROC_TOTAL</span> - <span style="color: #007800;">$PROC_INUSE</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">JOBS_LIST</span>=<span style="color: #000000; font-weight: bold;">`/</span>opt<span style="color: #000000; font-weight: bold;">/</span>gridengine<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>lx26-amd64<span style="color: #000000; font-weight: bold;">/</span>qstat<span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'-----------------------------------------------------------------------------------------------------------------'</span> 
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$JOBS_LIST</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'-----------------------------------------------------------------------------------------------------------------'</span> 
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;   <span style="color: #007800;">$PROC_TOTAL</span> total processors :: <span style="color: #007800;">$PROC_INUSE</span> are in use :: <span style="color: #007800;">$PROC_AVAIL</span> are available&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'-----------------------------------------------------------------------------------------------------------------'</span>
<span style="color: #7a0874; font-weight: bold;">echo</span></pre></td></tr></table></div>

<p><br clear="all"><br />
<img class="framed" src="http://sgowtham.net/blog/files/20081013/qstat.png" alt="qstat General Wrapper" title="qstat General Wrapper"></p>
<p><br clear="all"></p>
<h3 class="blog">User Specific Wrapper for <strong>qstat</strong></h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#! /bin/bash</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Save this as /home/local/bin/qu</span>
<span style="color: #666666; font-style: italic;"># A wrapper for 'qstat' command to show all currently submitted jobs by a given </span>
<span style="color: #666666; font-style: italic;"># user ($USER) along with the total number processors used/in use</span>
<span style="color: #666666; font-style: italic;"># If the $USER has no jobs, displays all currently submitted jobs.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Check the path to 'qstat'</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Thu, 02 Oct 2008 21:35:04 -0400</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;"># Modify this variable to meet the cluster's requirements</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PROC_TOTAL</span>=<span style="color: #ff0000;">&quot;128&quot;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PROC_INUSE</span>=<span style="color: #000000; font-weight: bold;">`/</span>opt<span style="color: #000000; font-weight: bold;">/</span>gridengine<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>lx26-amd64<span style="color: #000000; font-weight: bold;">/</span>qstat <span style="color: #000000; font-weight: bold;">|</span> \
       <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print} (NR&gt;2) {used_procs+=\$9} END {print used_procs}'</span> <span style="color: #000000; font-weight: bold;">|</span> \
       <span style="color: #c20cb9; font-weight: bold;">tail</span> <span style="color: #660033;">-1</span> <span style="color: #000000; font-weight: bold;">|</span> \
       <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $NF}'</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PROC_AVAIL</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">expr</span> <span style="color: #007800;">$PROC_TOTAL</span> - <span style="color: #007800;">$PROC_INUSE</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">JOBS_LIST</span>=<span style="color: #000000; font-weight: bold;">`/</span>opt<span style="color: #000000; font-weight: bold;">/</span>gridengine<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>lx26-amd64<span style="color: #000000; font-weight: bold;">/</span>qstat <span style="color: #660033;">-u</span> <span style="color: #007800;">$USER</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$JOBS_LIST</span>&quot;</span> == <span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>;
<span style="color: #000000; font-weight: bold;">then</span>
  <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">JOBS_LIST</span>=<span style="color: #000000; font-weight: bold;">`/</span>opt<span style="color: #000000; font-weight: bold;">/</span>gridengine<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>lx26-amd64<span style="color: #000000; font-weight: bold;">/</span>qstat<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'-----------------------------------------------------------------------------------------------------------------'</span> 
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$JOBS_LIST</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'-----------------------------------------------------------------------------------------------------------------'</span> 
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;   <span style="color: #007800;">$PROC_TOTAL</span> total processors :: <span style="color: #007800;">$PROC_INUSE</span> are in use :: <span style="color: #007800;">$PROC_AVAIL</span> are available&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'-----------------------------------------------------------------------------------------------------------------'</span>
<span style="color: #7a0874; font-weight: bold;">echo</span></pre></td></tr></table></div>

<p><br clear="all"><br />
<img class="framed" src="http://sgowtham.net/blog/files/20081013/qu.png" alt="qstat User Specific Wrapper" title="qstat User Specific Wrapper"></p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fsgowtham.net%2Fblog%2F2008%2F10%2F13%2Fbash-wrappers-for-qstat-in-npaci-rocks%2F&amp;title=BASH%20%26%238211%3B%20Wrappers%20For%20qstat%20In%20NPACI%20ROCKS" id="wpa2a_18"><img src="http://sgowtham.net/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://sgowtham.net/blog/2008/10/13/bash-wrappers-for-qstat-in-npaci-rocks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PERL &#8211; Mapping An Element To Its Array</title>
		<link>http://sgowtham.net/blog/2008/10/11/perl-mapping-an-element-to-its-array/</link>
		<comments>http://sgowtham.net/blog/2008/10/11/perl-mapping-an-element-to-its-array/#comments</comments>
		<pubDate>Sat, 11 Oct 2008 17:28:50 +0000</pubDate>
		<dc:creator>Gowtham</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[PERL]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://sgowtham.net/blog/?p=806</guid>
		<description><![CDATA[Disclaimer Often times, a need arises where one has to search a bunch of arrays to find out to which one of them a given element belongs. Of course, life becomes a lot simpler if those arrays are unique (meaning any given element appears only in one of the arrays) and life may not always [...]]]></description>
			<content:encoded><![CDATA[<h3 class="blog">Disclaimer</h3>
<p>Often times, a need arises where one has to search a bunch of arrays to find out to which one of them a given element belongs. Of course, life becomes a lot simpler if those arrays are unique (meaning any given element appears only in one of the arrays) and life may not always be that simple. Some common examples of such simple case include, but not limited to, the following:</p>
<ol>
<li>Decide which fruit belongs to which basket</li>
<li>Decide which database to query based on a set criterion. Certainly helps if the array names are the same as respective database names. There are potentially very many such database driven applications</li>
<li>And so on.</li>
</ol>
<p><br clear="all"></p>
<h3 class="blog">The Script/Module</h3>
<p>Save the following into a file and call it, <strong>element_array_map.pl</strong> (or <strong>element_array_map.pm</strong>, as the need may be). It provides a function/sub routine that takes the <strong>element name</strong> as the input and returns the <strong>array name</strong> to which the requested element belongs as output. The sub-routine makes a hash of all  the arrays and uses <strong>foreach</strong> loop to sift through them. The array name (depending on the application), can subsequently used appropriately. (Re)naming the variables and functions to describe the specific application may also be useful.</p>
<p><br clear="all"></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
</pre></td><td class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#! /usr/bin/perl -wT</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># PERL module/script to decide to which array an element belongs to</span>
<span style="color: #666666; font-style: italic;"># when there are multiple arrays.</span>
<span style="color: #666666; font-style: italic;"># Assumes that the arrays contain UNIQUE element names</span>
<span style="color: #666666; font-style: italic;"># Element_Array_Map() takes in elementName as input and returns the name of array it's in.</span>
<span style="color: #666666; font-style: italic;"># </span>
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># sub Element_Array_Map() BEGINS</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> Element_Array_Map<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$)</span> <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Requested elementName</span>
&nbsp;
  <span style="color: #000066;">local</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$element</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$_</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Uncomment the following line for debugging purposes</span>
<span style="color: #666666; font-style: italic;"># print(&quot;Requested element is $element\n&quot;);</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># A hash of arrays</span>
<span style="color: #666666; font-style: italic;"># Each array contains several element names</span>
<span style="color: #666666; font-style: italic;"># Each array can have different number of elements </span>
<span style="color: #666666; font-style: italic;"># Elements of each array are UNIQUE</span>
<span style="color: #666666; font-style: italic;"># Hash definition can be modified to include 'N' arrays</span>
&nbsp;
  <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">%HASH_OF_ARRAYS</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>
      ARRAY1 <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#91;</span><span style="color: #ff0000;">'Element1'</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'Element2'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> 
      ARRAY2 <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#91;</span><span style="color: #ff0000;">'Element3'</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'Element4'</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'Element5'</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'Element6'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
      ARRAY3 <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#91;</span><span style="color: #ff0000;">'Element7'</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'Element8'</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'Element9'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
      ARRAY4 <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#91;</span><span style="color: #ff0000;">'Element0'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
      <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Search the hash of arrays to find out to which array does the </span>
<span style="color: #666666; font-style: italic;"># requested element belong</span>
&nbsp;
  <span style="color: #b1b100;">foreach</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$element_array</span> <span style="color: #009900;">&#40;</span><span style="color: #000066;">keys</span> <span style="color: #0000ff;">%HASH_OF_ARRAYS</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$HASH_OF_ARRAYS</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$element_array</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$element</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">m/$_/</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>  
        <span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;$element is in $element_array<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">return</span> <span style="color: #0000ff;">$element_array</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span> 
<span style="color: #666666; font-style: italic;"># sub Element_Array_Map() ENDS</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Call it after the function to avoid the following error</span>
<span style="color: #666666; font-style: italic;"># 'main::Element_Array_Map() called too early to check prototype'</span>
<span style="color: #666666; font-style: italic;"># If not using '-wT' flags, this function can be called before its </span>
<span style="color: #666666; font-style: italic;"># definition. The value '$element_array' can be passed on to other </span>
<span style="color: #666666; font-style: italic;"># modules/scripts, if necessary.</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$elementName</span>   <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;Element1&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$element_array</span> <span style="color: #339933;">=</span> Element_Array_Map<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$elementName</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Uncomment the following line for debugging purposes</span>
<span style="color: #666666; font-style: italic;"># print &quot;$element_array\n&quot;;</span></pre></td></tr></table></div>

<p><br clear="all"><br />
<img class="framed" src="http://sgowtham.net/blog/files/20081011/element_array_map.png" alt="Mapping An Element To Its Array" title="Mapping An Element To Its Array"></p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fsgowtham.net%2Fblog%2F2008%2F10%2F11%2Fperl-mapping-an-element-to-its-array%2F&amp;title=PERL%20%26%238211%3B%20Mapping%20An%20Element%20To%20Its%20Array" id="wpa2a_20"><img src="http://sgowtham.net/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://sgowtham.net/blog/2008/10/11/perl-mapping-an-element-to-its-array/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Expect &#8211; Remote SSH Login</title>
		<link>http://sgowtham.net/blog/2008/09/12/expect-remote-ssh-login/</link>
		<comments>http://sgowtham.net/blog/2008/09/12/expect-remote-ssh-login/#comments</comments>
		<pubDate>Fri, 12 Sep 2008 21:03:04 +0000</pubDate>
		<dc:creator>Gowtham</dc:creator>
				<category><![CDATA[Expect]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://sgowtham.net/blog/?p=825</guid>
		<description><![CDATA[Expect is a UNIX automation and testing tool, written by Don Libes as an extension to the Tcl scripting language, for interactive applications such as telnet, ftp, passwd, fsck, rlogin, tip, ssh, and others. It uses UNIX pseudo terminals to wrap up sub-processes transparently, allowing the automation of arbitrary applications that are accessed over a [...]]]></description>
			<content:encoded><![CDATA[<p>Expect is a UNIX automation and testing tool, written by Don Libes as an extension to the <strong>Tcl</strong> scripting language, for interactive applications such as <strong>telnet</strong>, <strong>ftp</strong>, <strong>passwd</strong>, <strong>fsck</strong>, <strong>rlogin</strong>, <strong>tip</strong>, <strong>ssh</strong>, and others. It uses UNIX pseudo terminals to wrap up sub-processes transparently, allowing the automation of arbitrary applications that are accessed over a terminal. With <strong>Tk</strong>, interactive applications can be wrapped in X11 GUIs. Expect has regular expression pattern matching and general program capabilities, allowing simple scripts to intelligently control programs such as <strong>telnet</strong>, <strong>ftp</strong>, and <strong>ssh</strong>, all of which lack a programming language, macros, or any other program mechanism. The result is that Expect scripts provide old tools with significant new power and flexibility.</p>
<p><br clear="all"></p>
<h3 class="blog">The Script</h3>
<p>When a server keeps prompting for password at SSH attempts in spite of setting up RSA/DSA keys, this script can be used to overcome that issue. Make sure that the script has <strong>700</strong> permission as it will contain your password in plain text.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#! /usr/bin/expect</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Fri, 12 Sep 2008 12:58:10 -0400</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Edit the following line - $USER@$SERVER</span>
spawn <span style="color: #c20cb9; font-weight: bold;">ssh</span> your-useid<span style="color: #000000; font-weight: bold;">@</span>your-server-name
&nbsp;
<span style="color: #666666; font-style: italic;"># First time connection will print out some text for</span>
<span style="color: #666666; font-style: italic;"># which one needs to type 'yes' to continue</span>
<span style="color: #666666; font-style: italic;"># Comment these two lines after the first attempt</span>
expect <span style="color: #ff0000;">&quot;*Are you sure you want to continue connecting*&quot;</span>
send   <span style="color: #ff0000;">&quot;yes<span style="color: #000099; font-weight: bold;">\r</span>&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Put the password here</span>
expect <span style="color: #ff0000;">&quot;*assword*&quot;</span>
send   <span style="color: #ff0000;">&quot;YOUR-PASSWORD<span style="color: #000099; font-weight: bold;">\r</span>&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Start interacting</span>
interact</pre></div></div>

<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fsgowtham.net%2Fblog%2F2008%2F09%2F12%2Fexpect-remote-ssh-login%2F&amp;title=Expect%20%26%238211%3B%20Remote%20SSH%20Login" id="wpa2a_22"><img src="http://sgowtham.net/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://sgowtham.net/blog/2008/09/12/expect-remote-ssh-login/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>BASH &#8211; Sum of All File/Folder Sizes</title>
		<link>http://sgowtham.net/blog/2008/04/09/bashsum-of-all-filefolder-sizes/</link>
		<comments>http://sgowtham.net/blog/2008/04/09/bashsum-of-all-filefolder-sizes/#comments</comments>
		<pubDate>Wed, 09 Apr 2008 21:14:08 +0000</pubDate>
		<dc:creator>Gowtham</dc:creator>
				<category><![CDATA[AWK]]></category>
		<category><![CDATA[BASH]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://sgowtham.net/blog/?p=829</guid>
		<description><![CDATA[Disclaimer The instructions/steps/scripts/methods given below worked for me running CentOS. It may very well work for you on other linux distributions, Red Hat-like or otherwise. Please note that if you decide to use these instructions on your machine, you are doing so entirely at your very own discretion and that neither this site, sgowtham.net, nor [...]]]></description>
			<content:encoded><![CDATA[<h3 class="blog">Disclaimer</h3>
<p>The instructions/steps/scripts/methods given below worked for me running CentOS. It may very well work for you on other linux distributions, Red Hat-like or otherwise. Please note that if you decide to use these instructions on your machine, you are doing so entirely at your very own discretion and that neither this site, <a href="http://sgowtham.net/" target="_blank">sgowtham.net</a>, nor its author is responsible for any/all damage &#8211; intellectual or otherwise.</p>
<p><br clear="all"></p>
<h3 class="blog">What is BASH and AWK?</h3>
<p>BASH is a free software Unix shell written for the GNU Project. Its name is an acronym which stands for <em>Bourne-again shell</em>. The name is a pun on the name of the Bourne shell (<strong>sh</strong>), an early and important UNIX shell written by Stephen Bourne and distributed with Version 7 Unix circa 1978, and the concept of being <em>born again</em>. BASH was created in 1987 by Brian Fox. In 1990 Chet Ramey became the primary maintainer. BASH is the default shell on most GNU/Linux systems as well as on Mac OS X and it can be run on most UNIX-like operating systems. It has also been ported to Microsoft Windows using the POSIX emulation provided by Cygwin, to MS-DOS by the DJGPP project and to Novell NetWare.</p>
<p>AWK is a general purpose programming language that is designed for processing text-based data, either in files or data streams, and was created at Bell Labs in the 1970s. The name AWK is derived from the family names of its authors — Alfred <strong>A</strong>ho, Peter <strong>W</strong>einberger, and Brian <strong>K</strong>ernighan; however, it is not commonly pronounced as a string of separate letters but rather to sound the same as the name of the bird, <strong>auk</strong>. <em>awk</em>, when written in all lowercase letters, refers to the UNIX or Plan 9 program that runs other programs written in the AWK programming language. AWK is an example of a programming language that extensively uses the string data type, associative arrays (that is, arrays indexed by key strings), and regular expressions. The power, terseness, and limitations of AWK programs and <strong>sed</strong> scripts inspired Larry Wall to write PERL. Because of their dense notation, all these languages are often used for writing one-liner programs. AWK is one of the early tools to appear in Version 7 UNIX and gained popularity as a way to add computational features to a UNIX pipeline. A version of the AWK language is a standard feature of nearly every modern UNIX-like operating system.</p>
<p><br clear="all"></p>
<h3 class="blog">The Script</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#! /bin/bash</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Calculates the sum of all files/folders (in bytes) </span>
<span style="color: #666666; font-style: italic;"># Wed, 09 Apr 2008 10:44:02 -0400</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Sum of all requested files/folders&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-al</span> <span style="color: #007800;">$1</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{sum = sum + $5} END {print sum}'</span>
<span style="color: #7a0874; font-weight: bold;">echo</span></pre></td></tr></table></div>

<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fsgowtham.net%2Fblog%2F2008%2F04%2F09%2Fbashsum-of-all-filefolder-sizes%2F&amp;title=BASH%20%26%238211%3B%20Sum%20of%20All%20File%2FFolder%20Sizes" id="wpa2a_24"><img src="http://sgowtham.net/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://sgowtham.net/blog/2008/04/09/bashsum-of-all-filefolder-sizes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>BASH &#8211; Read A File, One Line At A Time</title>
		<link>http://sgowtham.net/blog/2008/01/23/bash-read-a-file-one-line-at-a-time/</link>
		<comments>http://sgowtham.net/blog/2008/01/23/bash-read-a-file-one-line-at-a-time/#comments</comments>
		<pubDate>Wed, 23 Jan 2008 23:15:24 +0000</pubDate>
		<dc:creator>Gowtham</dc:creator>
				<category><![CDATA[BASH]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://sgowtham.net/blog/?p=890</guid>
		<description><![CDATA[Disclaimer The instructions/steps given below worked for me running CentOS. It may very well work for you on other linux distributions, Red Hat-like or otherwise. Please note that if you decide to use these instructions on your machine, you are doing so entirely at your very own discretion and that neither this site, sgowtham.net, nor [...]]]></description>
			<content:encoded><![CDATA[<h3 class="blog">Disclaimer</h3>
<p>The instructions/steps given below worked for me running CentOS. It may very well work for you on other linux distributions, Red Hat-like or otherwise. Please note that if you decide to use these instructions on your machine, you are doing so entirely at your very own discretion and that neither this site, <a href="http://sgowtham.net/" target="_blank">sgowtham.net</a>, nor its author is responsible for any/all damage &#8211; intellectual or otherwise.</p>
<p><br clear="all"></p>
<h3 class="blog">What is BASH?</h3>
<p>BASH is a free software Unix shell written for the GNU Project. Its name is an acronym which stands  for <em>Bourne-again shell</em>. The name is a pun on the name of the Bourne shell (<strong>sh</strong>), an early and important UNIX shell written by Stephen Bourne and distributed with Version 7 UNIX circa 1978, and the concept of being <em>born again</em>. BASH was created in 1987 by Brian Fox. In 1990 Chet Ramey became the primary maintainer. BASH is the default shell on most GNU/Linux systems as well as on Mac OS X and it can be run on most UNIX-like operating systems. It has also been ported to Microsoft Windows using the POSIX emulation provided by Cygwin, to MS-DOS by the DJGPP project and to Novell NetWare.</p>
<p><br clear="all"></p>
<h3 class="blog">The Script</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#! /bin/bash</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Read one line at a time from a specified file. </span>
<span style="color: #666666; font-style: italic;"># Can be used to extract required information from those lines.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Usage: ./read-lines.sh FILENAME </span>
<span style="color: #666666; font-style: italic;"># Mon, 23 Jun 2008 22:24:24 -0400</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span>
<span style="color: #7a0874; font-weight: bold;">exec</span><span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #007800;">$1</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #c20cb9; font-weight: bold;">read</span> line
<span style="color: #000000; font-weight: bold;">do</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$line</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span></pre></td></tr></table></div>

<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fsgowtham.net%2Fblog%2F2008%2F01%2F23%2Fbash-read-a-file-one-line-at-a-time%2F&amp;title=BASH%20%26%238211%3B%20Read%20A%20File%2C%20One%20Line%20At%20A%20Time" id="wpa2a_26"><img src="http://sgowtham.net/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://sgowtham.net/blog/2008/01/23/bash-read-a-file-one-line-at-a-time/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>BASH &#8211; Replace Space In Filenames With Underscore</title>
		<link>http://sgowtham.net/blog/2007/10/18/bash-replace-space-in-filenames-with-underscore/</link>
		<comments>http://sgowtham.net/blog/2007/10/18/bash-replace-space-in-filenames-with-underscore/#comments</comments>
		<pubDate>Fri, 19 Oct 2007 02:20:51 +0000</pubDate>
		<dc:creator>Gowtham</dc:creator>
				<category><![CDATA[BASH]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://sgowtham.net/blog/?p=896</guid>
		<description><![CDATA[Disclaimer The instructions/steps given below worked for me running CentOS. It may very well work for you on other linux distributions, Red Hat-like or otherwise. Please note that if you decide to use these instructions on your machine, you are doing so entirely at your very own discretion and that neither this site, sgowtham.net, nor [...]]]></description>
			<content:encoded><![CDATA[<h3 class="blog">Disclaimer</h3>
<p>The instructions/steps given below worked for me running CentOS. It may very well work for you on other linux distributions, Red Hat-like or otherwise. Please note that if you decide to use these instructions on your machine, you are doing so entirely at your very own discretion and that neither this site, <a href="http://sgowtham.net/" target="_blank">sgowtham.net</a>, nor its author is responsible for any/all damage &#8211; intellectual or otherwise.</p>
<p><br clear="all"></p>
<h3 class="blog">What is BASH?</h3>
<p>BASH is a free software Unix shell written for the GNU Project. Its name is an acronym which stands for <em>Bourne-again shell</em>. The name is a pun on the name of the Bourne shell (<strong>sh</strong>), an early and important UNIX shell written by Stephen Bourne and distributed with Version 7 UNIX circa 1978, and the concept of being <em>born again</em>. BASH was created in 1987 by Brian Fox. In 1990 Chet Ramey became the primary maintainer. BASH is the default shell on most GNU/Linux systems as well as on Mac OS X and it can be run on most UNIX-like operating systems. It has also been ported to Microsoft Windows using the POSIX emulation provided by Cygwin, to MS-DOS by the DJGPP project and to Novell NetWare.</p>
<p><br clear="all"></p>
<h3 class="blog">The Script</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#! /bin/bash</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Removes spaces in filenames (replaces them with underscore)</span>
<span style="color: #666666; font-style: italic;"># Thu, 18 Oct 2007 21:34:45 -0400</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #c20cb9; font-weight: bold;">file</span> <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">*</span>;
<span style="color: #000000; font-weight: bold;">do</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> Converting <span style="color: #ff0000;">&quot;<span style="color: #007800;">$file</span>&quot;</span> to <span style="color: #ff0000;">&quot;<span style="color: #007800;">${file// /_}</span>&quot;</span>
  <span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$file</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${file// /_}</span>&quot;</span>
<span style="color: #000000; font-weight: bold;">done</span></pre></td></tr></table></div>

<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fsgowtham.net%2Fblog%2F2007%2F10%2F18%2Fbash-replace-space-in-filenames-with-underscore%2F&amp;title=BASH%20%26%238211%3B%20Replace%20Space%20In%20Filenames%20With%20Underscore" id="wpa2a_28"><img src="http://sgowtham.net/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://sgowtham.net/blog/2007/10/18/bash-replace-space-in-filenames-with-underscore/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PERL &#8211; Password Encryption</title>
		<link>http://sgowtham.net/blog/2007/07/13/perl-password-encryption/</link>
		<comments>http://sgowtham.net/blog/2007/07/13/perl-password-encryption/#comments</comments>
		<pubDate>Sat, 14 Jul 2007 00:16:24 +0000</pubDate>
		<dc:creator>Gowtham</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[PERL]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://sgowtham.net/blog/?p=929</guid>
		<description><![CDATA[Disclaimer The instructions/steps/scripts/methods given below worked for me running CentOS. It may very well work for you on other linux distributions, Red Hat-like or otherwise. Please note that if you decide to use these instructions on your machine, you are doing so entirely at your very own discretion and that neither this site, sgowtham.net, nor [...]]]></description>
			<content:encoded><![CDATA[<h3 class="blog">Disclaimer</h3>
<p>The instructions/steps/scripts/methods given below worked for me running CentOS. It may very well work for you on other linux distributions, Red Hat-like or otherwise. Please note that if you decide to use these instructions on your machine, you are doing so entirely at your very own discretion and that neither this site, <a href="http://sgowtham.net/" target="_blank">sgowtham.net</a>, nor its author is responsible for any/all damage &#8211; intellectual or otherwise.</p>
<p><br clear="all"></p>
<h3 class="blog">What is PERL?</h3>
<p>In computer programming, PERL is a high-level, general-purpose, interpreted, dynamic programming language. PERL was originally developed by Larry Wall, a linguist working as a systems administrator for NASA, in 1987, as a general purpose UNIX scripting language to make report processing easier. Since then, it has undergone many changes and revisions and became widely popular among programmers. Larry Wall continues to oversee development of the core language. PERL borrows features from other programming languages including C, shell scripting (sh), AWK, sed and Lisp. The language provides powerful text processing facilities without the arbitrary data length limits of many contemporary UNIX tools, making it the ideal language for manipulating text files. It is also used for graphics programming, system administration, network programming, applications that require database access and CGI programming on the Web. PERL is nicknamed <em>the Swiss Army knife of programming languages</em> due to its flexibility and adaptability.</p>
<p><br clear="all"></p>
<h3 class="blog">The Script</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#! /usr/bin/perl</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># PERL script to quickly generate a password (one could use mkpasswd as well). </span>
<span style="color: #666666; font-style: italic;"># The password generated with this script has its first two characters as the 'salt' </span>
<span style="color: #666666; font-style: italic;"># defined below, easily indicating whether the user has changed the temporary </span>
<span style="color: #666666; font-style: italic;"># password or not.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Patrick Krogel, Michigan Technological University</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Salt - common practice is to choose System Administrator's initials</span>
<span style="color: #007800;">$salt</span> = <span style="color: #ff0000;">&quot;ab&quot;</span>;
&nbsp;
sub encrypt<span style="color: #7a0874; font-weight: bold;">&#40;</span>$<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
   my <span style="color: #007800;">$pass</span>  = <span style="color: #7a0874; font-weight: bold;">shift</span>;
   my <span style="color: #007800;">$epass</span> = crypt<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$pass</span>,<span style="color: #007800;">$salt</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>;
   <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #007800;">$epass</span>;
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Step 1: Get Password (twice)</span>
system<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">&quot;stty -echo&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>;
print <span style="color: #ff0000;">&quot;Enter password: &quot;</span>;
<span style="color: #007800;">$pass1</span> = <span style="color: #000000; font-weight: bold;">&lt;</span>STDIN<span style="color: #000000; font-weight: bold;">&gt;</span>;
chomp <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$pass1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>;
&nbsp;
print <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>Confirm password: &quot;</span>;
<span style="color: #007800;">$pass2</span> = <span style="color: #000000; font-weight: bold;">&lt;</span>STDIN<span style="color: #000000; font-weight: bold;">&gt;</span>;
chomp <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$pass2</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>;
&nbsp;
system<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">&quot;stty echo&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>;
&nbsp;
<span style="color: #666666; font-style: italic;"># Compare the user entry and process it</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-z</span> <span style="color: #007800;">$pass1</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #007800;">$pass1</span> eq <span style="color: #007800;">$pass2</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
   <span style="color: #007800;">$epass</span> = encrypt<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$pass1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>;
   print <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>Password: <span style="color: #007800;">$epass</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
<span style="color: #7a0874; font-weight: bold;">&#125;</span> elsif <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$pass1</span> ne <span style="color: #007800;">$pass2</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
   print <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>Passwords do not match.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
<span style="color: #7a0874; font-weight: bold;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
   print <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>Password is blank.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></td></tr></table></div>

<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fsgowtham.net%2Fblog%2F2007%2F07%2F13%2Fperl-password-encryption%2F&amp;title=PERL%20%26%238211%3B%20Password%20Encryption" id="wpa2a_30"><img src="http://sgowtham.net/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://sgowtham.net/blog/2007/07/13/perl-password-encryption/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>BASH &#8211; Sum Of All Integers Between Given Two Integers</title>
		<link>http://sgowtham.net/blog/2007/07/06/bash-sum-of-all-integers-between-given-two-integers/</link>
		<comments>http://sgowtham.net/blog/2007/07/06/bash-sum-of-all-integers-between-given-two-integers/#comments</comments>
		<pubDate>Sat, 07 Jul 2007 01:23:57 +0000</pubDate>
		<dc:creator>Gowtham</dc:creator>
				<category><![CDATA[AWK]]></category>
		<category><![CDATA[BASH]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://sgowtham.net/blog/?p=900</guid>
		<description><![CDATA[Disclaimer The instructions/steps/scripts/methods given below worked for me running CentOS. It may very well work for you on other linux distributions, Red Hat-like or otherwise. Please note that if you decide to use these instructions on your machine, you are doing so entirely at your very own discretion and that neither this site, sgowtham.net, nor [...]]]></description>
			<content:encoded><![CDATA[<h3 class="blog">Disclaimer</h3>
<p>The instructions/steps/scripts/methods given below worked for me running CentOS. It may very well work for you on other linux distributions, Red Hat-like or otherwise. Please note that if you decide to use these instructions on your machine, you are doing so entirely at your very own discretion and that neither this site, <a href="http://sgowtham.net/" target="_blank">sgowtham.net</a>, nor its author is responsible for any/all damage &#8211; intellectual or otherwise.</p>
<p><br clear="all"></p>
<h3 class="blog">What is BASH and AWK?</h3>
<p>BASH is a free software Unix shell written for the GNU Project. Its name is an acronym which stands for <em>Bourne-again shell</em>. The name is a pun on the name of the Bourne shell (<strong>sh</strong>), an early and important UNIX shell written by Stephen Bourne and distributed with Version 7 Unix circa 1978, and the concept of being <em>born again</em>. BASH was created in 1987 by Brian Fox. In 1990 Chet Ramey became the primary maintainer. BASH is the default shell on most GNU/Linux systems as well as on Mac OS X and it can be run on most UNIX-like operating systems. It has also been ported to Microsoft Windows using the POSIX emulation provided by Cygwin, to MS-DOS by the DJGPP project and to Novell NetWare.</p>
<p>AWK is a general purpose programming language that is designed for processing text-based data, either in files or data streams, and was created at Bell Labs in the 1970s. The name AWK is derived from the family names of its authors — Alfred <strong>A</strong>ho, Peter <strong>W</strong>einberger, and Brian <strong>K</strong>ernighan; however, it is not commonly pronounced as a string of separate letters but rather to sound the same as the name of the bird, <strong>auk</strong>. <em>awk</em>, when written in all lowercase letters, refers to the UNIX or Plan 9 program that runs other programs written in the AWK programming language. AWK is an example of a programming language that extensively uses the string data type, associative arrays (that is, arrays indexed by key strings), and regular expressions. The power, terseness, and limitations of AWK programs and <strong>sed</strong> scripts inspired Larry Wall to write PERL. Because of their dense notation, all these languages are often used for writing one-liner programs. AWK is one of the early tools to appear in Version 7 UNIX and gained popularity as a way to add computational features to a UNIX pipeline. A version of the AWK language is a standard feature of nearly every modern UNIX-like operating system.</p>
<p><br clear="all"></p>
<h3 class="blog">The Script</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#! /bin/bash</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># BASH/AWK utility to find the sum of all integers between any two given integers.</span>
<span style="color: #666666; font-style: italic;"># In the absence of second integer, it calculates the sum of all integers, starting from zero,</span>
<span style="color: #666666; font-style: italic;"># till the given number</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;"># Usage: sum.sh INTEGER1 INTEGER2</span>
<span style="color: #666666; font-style: italic;"># Fri, 06 Jul 2007 20:46:42 -0400</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">seq</span> <span style="color: #007800;">$1</span> <span style="color: #007800;">$2</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{x+=$1} END {print x}'</span></pre></td></tr></table></div>

<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fsgowtham.net%2Fblog%2F2007%2F07%2F06%2Fbash-sum-of-all-integers-between-given-two-integers%2F&amp;title=BASH%20%26%238211%3B%20Sum%20Of%20All%20Integers%20Between%20Given%20Two%20Integers" id="wpa2a_32"><img src="http://sgowtham.net/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://sgowtham.net/blog/2007/07/06/bash-sum-of-all-integers-between-given-two-integers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>BASH &#8211; Filename Toggle Case</title>
		<link>http://sgowtham.net/blog/2006/05/17/bash-filename-toggle-case/</link>
		<comments>http://sgowtham.net/blog/2006/05/17/bash-filename-toggle-case/#comments</comments>
		<pubDate>Thu, 18 May 2006 03:34:08 +0000</pubDate>
		<dc:creator>Gowtham</dc:creator>
				<category><![CDATA[BASH]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://sgowtham.net/blog/?p=905</guid>
		<description><![CDATA[Disclaimer The instructions/steps/scripts/methods given below worked for me running CentOS. It may very well work for you on other linux distributions, Red Hat-like or otherwise. Please note that if you decide to use these instructions on your machine, you are doing so entirely at your very own discretion and that neither this site, sgowtham.net, nor [...]]]></description>
			<content:encoded><![CDATA[<h3 class="blog">Disclaimer</h3>
<p>The instructions/steps/scripts/methods given below worked for me running CentOS. It may very well work for you on other linux distributions, Red Hat-like or otherwise. Please note that if you decide to use these instructions on your machine, you are doing so entirely at your very own discretion and that neither this site, <a href="http://sgowtham.net/" target="_blank">sgowtham.net</a>, nor its author is responsible for any/all damage &#8211; intellectual or otherwise.</p>
<p><br clear="all"></p>
<h3 class="blog">What is BASH?</h3>
<p>BASH is a free software Unix shell written for the GNU Project. Its name is an acronym which stands  for <em>Bourne-again shell</em>. The name is a pun on the name of the Bourne shell (<strong>sh</strong>), an early and important UNIX shell written by Stephen Bourne and distributed with Version 7 UNIX circa 1978, and the concept of being <em>born again</em>. BASH was created in 1987 by Brian Fox. In 1990 Chet Ramey became the primary maintainer. BASH is the default shell on most GNU/Linux systems as well as on Mac OS X and it can be run on most UNIX-like operating systems. It has also been ported to Microsoft Windows using the POSIX emulation provided by Cygwin, to MS-DOS by the DJGPP project and to Novell NetWare.</p>
<p><br clear="all"></p>
<h3 class="blog">The Script</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#! /bin/bash</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># BASH script to convert upper (lower) case filenames to lower (upper) case.</span>
<span style="color: #666666; font-style: italic;"># Converts all files in a given directory, including any directory.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Wed, 17 May 2006 22:09:15 -0400</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Uppercase to lowercase</span>
<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #c20cb9; font-weight: bold;">file</span> <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #000000; font-weight: bold;">*</span>.<span style="color: #000000; font-weight: bold;">*`</span>;
<span style="color: #000000; font-weight: bold;">do</span>
  <span style="color: #007800;">lfile</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$file</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">tr</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>A-Z<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>a-z<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  Converting <span style="color: #007800;">${file}</span> to <span style="color: #007800;">${lfile}</span> &quot;</span>
  <span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #800000;">${file}</span> <span style="color: #800000;">${lfile}</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Lowercase to Uppercase</span>
<span style="color: #666666; font-style: italic;"># for file in `ls *.*`; </span>
<span style="color: #666666; font-style: italic;"># do</span>
<span style="color: #666666; font-style: italic;">#   ufile=$(echo $file | tr [a-z] [A-Z])</span>
<span style="color: #666666; font-style: italic;">#   echo &quot;  Converting ${file} to ${ufile} &quot;</span>
<span style="color: #666666; font-style: italic;">#   mv ${file} ${ufile}</span>
<span style="color: #666666; font-style: italic;"># done</span></pre></td></tr></table></div>

<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fsgowtham.net%2Fblog%2F2006%2F05%2F17%2Fbash-filename-toggle-case%2F&amp;title=BASH%20%26%238211%3B%20Filename%20Toggle%20Case" id="wpa2a_34"><img src="http://sgowtham.net/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://sgowtham.net/blog/2006/05/17/bash-filename-toggle-case/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>BASH &#8211; Center Align A File</title>
		<link>http://sgowtham.net/blog/2006/04/09/bash-center-align-a-file/</link>
		<comments>http://sgowtham.net/blog/2006/04/09/bash-center-align-a-file/#comments</comments>
		<pubDate>Sun, 09 Apr 2006 23:39:48 +0000</pubDate>
		<dc:creator>Gowtham</dc:creator>
				<category><![CDATA[BASH]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[SED]]></category>

		<guid isPermaLink="false">http://sgowtham.net/blog/?p=910</guid>
		<description><![CDATA[Disclaimer The instructions/steps/scripts/methods given below worked for me running CentOS. It may very well work for you on other linux distributions, Red Hat-like or otherwise. Please note that if you decide to use these instructions on your machine, you are doing so entirely at your very own discretion and that neither this site, sgowtham.net, nor [...]]]></description>
			<content:encoded><![CDATA[<h3 class="blog">Disclaimer</h3>
<p>The instructions/steps/scripts/methods given below worked for me running CentOS. It may very well work for you on other linux distributions, Red Hat-like or otherwise. Please note that if you decide to use these instructions on your machine, you are doing so entirely at your very own discretion and that neither this site, <a href="http://sgowtham.net/" target="_blank">sgowtham.net</a>, nor its author is responsible for any/all damage &#8211; intellectual or otherwise.</p>
<p><br clear="all"></p>
<h3 class="blog">What is BASH and SED?</h3>
<p>BASH is a free software Unix shell written for the GNU Project. Its name is an acronym which stands  for <em>Bourne-again shell</em>. The name is a pun on the name of the Bourne shell (<strong>sh</strong>), an early and important UNIX shell written by Stephen Bourne and distributed with Version 7 UNIX circa 1978, and the concept of being <em>born again</em>. BASH was created in 1987 by Brian Fox. In 1990 Chet Ramey became the primary maintainer. BASH is the default shell on most GNU/Linux systems as well as on Mac OS X and it can be run on most UNIX-like operating systems. It has also been ported to Microsoft Windows using the POSIX emulation provided by Cygwin, to MS-DOS by the DJGPP project and to Novell NetWare.</p>
<p>sed (<strong>S</strong>tream <strong>ED</strong>itor) refers to a UNIX utility which parses text files and implements a programming language which can apply textual transformations to such files. It reads input files line by line (sequentially), applying the operation which has been specified via the command line (or a sed script), and then outputs the line. It was developed from 1973 to 1974 as a UNIX utility by Lee E. McMahon of Bell Labs, and is available for most operating systems.</p>
<p><br clear="all"></p>
<h3 class="blog">The Script</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#! /bin/bash</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># BASH script to center all text in the middle of 79-column width.</span>
<span style="color: #666666; font-style: italic;"># Leading white spaces are insignificant and no trailing spaces appear at the end.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Sun, 09 Apr 2006 08:47:20 -0400</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>;
<span style="color: #000000; font-weight: bold;">then</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Center aligning the text in $1&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">FILENAME</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$1</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span> <span style="color: #ff0000;">'.'</span> <span style="color: #ff0000;">'{print $1}'</span><span style="color: #000000; font-weight: bold;">`</span>
  <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">EXTN</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$1</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span> <span style="color: #ff0000;">'.'</span> <span style="color: #ff0000;">'{print $2}'</span><span style="color: #000000; font-weight: bold;">`</span>
  <span style="color: #c20cb9; font-weight: bold;">sed</span>  <span style="color: #660033;">-e</span> :a <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/^.\{1,77\}$/ &amp;/;ta'</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/\( *\)\1/\1/'</span> <span style="color: #007800;">$1</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #007800;">$FILENAME_calign</span>.<span style="color: #007800;">$EXTN</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Open <span style="color: #007800;">$FILENAME_calign</span>.<span style="color: #007800;">$EXTN</span>&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></td></tr></table></div>

<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fsgowtham.net%2Fblog%2F2006%2F04%2F09%2Fbash-center-align-a-file%2F&amp;title=BASH%20%26%238211%3B%20Center%20Align%20A%20File" id="wpa2a_36"><img src="http://sgowtham.net/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://sgowtham.net/blog/2006/04/09/bash-center-align-a-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PERL &#8211; Disk Usage Reminder</title>
		<link>http://sgowtham.net/blog/2006/02/24/perl-disk-usage-reminder/</link>
		<comments>http://sgowtham.net/blog/2006/02/24/perl-disk-usage-reminder/#comments</comments>
		<pubDate>Fri, 24 Feb 2006 23:46:55 +0000</pubDate>
		<dc:creator>Gowtham</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[PERL]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://sgowtham.net/blog/?p=913</guid>
		<description><![CDATA[Disclaimer The instructions/steps/scripts/methods given below worked for me running CentOS. It may very well work for you on other linux distributions, Red Hat-like or otherwise. Please note that if you decide to use these instructions on your machine, you are doing so entirely at your very own discretion and that neither this site, sgowtham.net, nor [...]]]></description>
			<content:encoded><![CDATA[<h3 class="blog">Disclaimer</h3>
<p>The instructions/steps/scripts/methods given below worked for me running CentOS. It may very well work for you on other linux distributions, Red Hat-like or otherwise. Please note that if you decide to use these instructions on your machine, you are doing so entirely at your very own discretion and that neither this site, <a href="http://sgowtham.net/" target="_blank">sgowtham.net</a>, nor its author is responsible for any/all damage &#8211; intellectual or otherwise.</p>
<p><br clear="all"></p>
<h3 class="blog">What is PERL?</h3>
<p>In computer programming, PERL is a high-level, general-purpose, interpreted, dynamic programming language. PERL was originally developed by Larry Wall, a linguist working as a systems administrator for NASA, in 1987, as a general purpose UNIX scripting language to make report processing easier. Since then, it has undergone many changes and revisions and became widely popular among programmers. Larry Wall continues to oversee development of the core language. PERL borrows features from other programming languages including C, shell scripting (sh), AWK, sed and Lisp. The language provides powerful text processing facilities without the arbitrary data length limits of many contemporary UNIX tools, making it the ideal language for manipulating text files. It is also used for graphics programming, system administration, network programming, applications that require database access and CGI programming on the Web. PERL is nicknamed <em>the Swiss Army knife of programming languages</em> due to its flexibility and adaptability.</p>
<p><br clear="all"></p>
<h3 class="blog">The Script</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
</pre></td><td class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#! /usr/bin/perl -wT</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Perl script to check disk usage and send emails to users hogging more than a specified limit. </span>
<span style="color: #666666; font-style: italic;"># Needs to be run as root and a good way to do it is via a cron job.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;"># First written : Pat Krogel, Fri Feb 24 11:51:35 EST 2006</span>
<span style="color: #666666; font-style: italic;"># Last modified : Gowtham, Fri Feb 24 15:37:40 EST 2006</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Variable initializations</span>
<span style="color: #0000ff;">$date</span>    <span style="color: #339933;">=</span> <span style="color: #000066;">localtime</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$dulimit</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">20</span><span style="color: #339933;">;</span>   <span style="color: #666666; font-style: italic;"># Disk Usage Limit, in GB</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Get the disk usage, in GB, and separate out space and uids </span>
<span style="color: #000066;">open</span> PIPE<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;du -s -B 1024M /home/* |&quot;</span> <span style="color: #b1b100;">or</span> <span style="color: #000066;">die</span> <span style="color: #ff0000;">&quot;Can't get disk usage.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009999;">&lt;PIPE&gt;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
   <span style="color: #000066;">chomp</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$space</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$user</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #000066;">split</span> <span style="color: #009966; font-style: italic;">/\s+/</span><span style="color: #339933;">;</span>
   <span style="color: #0000ff;">$user</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">s/^.*\/(\w+)$/\1/</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$space</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000ff;">$dulimit</span><span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;"># Debugging purposes only! </span>
      <span style="color: #666666; font-style: italic;"># print &quot;$user is taking up $space GB\n&quot;;</span>
      <span style="color: #000066;">open</span> MAIL<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;| mail -s 'Disk Usage Notification' $user<span style="color: #000099; font-weight: bold;">\@</span>domain.name&quot;</span>
        <span style="color: #b1b100;">or</span> <span style="color: #000066;">die</span> <span style="color: #ff0000;">&quot;Can't send email.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
      <span style="color: #000066;">print</span> MAIL <span style="color: #ff0000;">&quot;$user,<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
      <span style="color: #000066;">print</span> MAIL <span style="color: #ff0000;">&quot;Your home folder,<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
      <span style="color: #000066;">print</span> MAIL <span style="color: #ff0000;">&quot;/home/$user ($space GB)<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
      <span style="color: #000066;">print</span> MAIL <span style="color: #ff0000;">&quot;in 'host.domain.name' has exceeded the present limit.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
      <span style="color: #000066;">print</span> MAIL <span style="color: #ff0000;">&quot;Please back it up elsewhere (some other machine or<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
      <span style="color: #000066;">print</span> MAIL <span style="color: #ff0000;">&quot;external hard drives) and clean up the home folder.<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
      <span style="color: #000066;">print</span> MAIL <span style="color: #ff0000;">&quot;root<span style="color: #000099; font-weight: bold;">\@</span>host.domain.name<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
      <span style="color: #000066;">print</span> MAIL <span style="color: #ff0000;">&quot;$date<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
      <span style="color: #000066;">close</span> MAIL<span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000066;">close</span> PIPE<span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fsgowtham.net%2Fblog%2F2006%2F02%2F24%2Fperl-disk-usage-reminder%2F&amp;title=PERL%20%26%238211%3B%20Disk%20Usage%20Reminder" id="wpa2a_38"><img src="http://sgowtham.net/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://sgowtham.net/blog/2006/02/24/perl-disk-usage-reminder/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>BASH &#8211; Router&#8217;s Public IP Address</title>
		<link>http://sgowtham.net/blog/2006/01/04/bash-routers-public-ip-address/</link>
		<comments>http://sgowtham.net/blog/2006/01/04/bash-routers-public-ip-address/#comments</comments>
		<pubDate>Wed, 04 Jan 2006 23:58:01 +0000</pubDate>
		<dc:creator>Gowtham</dc:creator>
				<category><![CDATA[AWK]]></category>
		<category><![CDATA[BASH]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://sgowtham.net/blog/?p=919</guid>
		<description><![CDATA[BASH, AWK and SED BASH is a free software Unix shell written for the GNU Project. Its name is an acronym which stands for Bourne-again shell. The name is a pun on the name of the Bourne shell (sh), an early and important UNIX shell written by Stephen Bourne and distributed with Version 7 UNIX [...]]]></description>
			<content:encoded><![CDATA[<h3 class="blog">BASH, AWK and SED</h3>
<p>BASH is a free software Unix shell written for the GNU Project. Its name is an acronym which stands  for <em>Bourne-again shell</em>. The name is a pun on the name of the Bourne shell (<strong>sh</strong>), an early and important UNIX shell written by Stephen Bourne and distributed with Version 7 UNIX circa 1978, and the concept of being <em>born again</em>. BASH was created in 1987 by Brian Fox. In 1990 Chet Ramey became the primary maintainer. BASH is the default shell on most GNU/Linux systems as well as on Mac OS X and it can be run on most UNIX-like operating systems. It has also been ported to Microsoft Windows using the POSIX emulation provided by Cygwin, to MS-DOS by the DJGPP project and to Novell NetWare.</p>
<p>AWK is a general purpose programming language that is designed for processing text-based data, either in files or data streams, and was created at Bell Labs in the 1970s. The name AWK is derived from the family names of its authors — Alfred <strong>A</strong>ho, Peter <strong>W</strong>einberger, and Brian <strong>K</strong>ernighan; however, it is not commonly pronounced as a string of separate letters but rather to sound the same as the name of the bird, <strong>auk</strong>. <em>awk</em>, when written in all lowercase letters, refers to the UNIX or Plan 9 program that runs other programs written in the AWK programming language. AWK is an example of a programming language that extensively uses the string data type, associative arrays (that is, arrays indexed by key strings), and regular expressions. The power, terseness, and limitations of AWK programs and <strong>sed</strong> scripts inspired Larry Wall to write PERL. Because of their dense notation, all these languages are often used for writing one-liner programs. AWK is one of the early tools to appear in Version 7 UNIX and gained popularity as a way to add computational features to a UNIX pipeline. A version of the AWK language is a standard feature of nearly every modern UNIX-like operating system.</p>
<p>sed (<em>s</em>tream <em>ed</em>itor) is a Unix utility that parses text files and implements a programming language which can apply textual transformations to such files. It reads input files line by line, applying the operation which has been specified via the command line (or a sed script), and then outputs the line. It was developed in 1973-74 as a Unix utility by Lee McMahon of Bell Labs, and is available for UNIX and most flavors of Linux operating system.</p>
<p><br clear="all"></p>
<h3 class="blog">The Script</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#! /bin/bash</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># POSIX SH shell script to display the IP Address - one that the machine has, </span>
<span style="color: #666666; font-style: italic;"># as well as router's public IP Address, if any.</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># First written : Gowtham,  Wed Dec 28 22:05:35 EST 2005</span>
<span style="color: #666666; font-style: italic;"># Last modified : Gowtham,  Fri Dec 30 06:57:50 EST 2005</span>
<span style="color: #666666; font-style: italic;">#                 Gowtham,  Tue Jan  3 09:52:47 EST 2006</span>
<span style="color: #666666; font-style: italic;">#                 Jon DeVree, Tue Jan  3 22:28:15 EST 2006 </span>
&nbsp;
<span style="color: #007800;">IFACE</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">netstat</span> <span style="color: #660033;">-rn</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> ^0.0.0.0 <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $8}'</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$IFACE</span>&quot;</span> = <span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>;
<span style="color: #000000; font-weight: bold;">then</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot; You are not connected to the internet&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span>
  <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #007800;">IP</span>=<span style="color: #000000; font-weight: bold;">`/</span>sbin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">ifconfig</span> <span style="color: #007800;">$IFACE</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> Bcast <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $2}'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span> <span style="color: #ff0000;">':'</span> <span style="color: #ff0000;">'{print $2}'</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">NSIP</span>=<span style="color: #000000; font-weight: bold;">`</span>curl <span style="color: #660033;">-s</span> http:<span style="color: #000000; font-weight: bold;">//</span>checkip.dyndns.org <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $6}'</span> <span style="color: #000000; font-weight: bold;">|</span> \
            <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span> <span style="color: #ff0000;">'&lt;'</span> <span style="color: #ff0000;">'{print $1}'</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$IP</span>&quot;</span> = <span style="color: #ff0000;">&quot;<span style="color: #007800;">$NSIP</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>;
<span style="color: #000000; font-weight: bold;">then</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot; Your machine is directly connected to the internet&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot; IP Address : <span style="color: #007800;">$IP</span>&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span>
<span style="color: #000000; font-weight: bold;">else</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot; Your machine is configured behind a router&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot; Machine's static IP Address : <span style="color: #007800;">$IP</span>&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot; Router's  public IP Address : <span style="color: #007800;">$NSIP</span>&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></td></tr></table></div>

<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fsgowtham.net%2Fblog%2F2006%2F01%2F04%2Fbash-routers-public-ip-address%2F&amp;title=BASH%20%26%238211%3B%20Router%26%238217%3Bs%20Public%20IP%20Address" id="wpa2a_40"><img src="http://sgowtham.net/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://sgowtham.net/blog/2006/01/04/bash-routers-public-ip-address/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>BASH &#8211; Login Counter</title>
		<link>http://sgowtham.net/blog/2005/09/23/bash-login-counter/</link>
		<comments>http://sgowtham.net/blog/2005/09/23/bash-login-counter/#comments</comments>
		<pubDate>Sat, 24 Sep 2005 00:20:34 +0000</pubDate>
		<dc:creator>Gowtham</dc:creator>
				<category><![CDATA[AWK]]></category>
		<category><![CDATA[BASH]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://sgowtham.net/blog/?p=933</guid>
		<description><![CDATA[Disclaimer The instructions/steps/scripts/methods given below worked for me running CentOS. It may very well work for you on other linux distributions, Red Hat-like or otherwise. Please note that if you decide to use these instructions on your machine, you are doing so entirely at your very own discretion and that neither this site, sgowtham.net, nor [...]]]></description>
			<content:encoded><![CDATA[<h3 class="blog">Disclaimer</h3>
<p>The instructions/steps/scripts/methods given below worked for me running CentOS. It may very well work for you on other linux distributions, Red Hat-like or otherwise. Please note that if you decide to use these instructions on your machine, you are doing so entirely at your very own discretion and that neither this site, <a href="http://sgowtham.net/" target="_blank">sgowtham.net</a>, nor its author is responsible for any/all damage &#8211; intellectual or otherwise.</p>
<p><br clear="all"></p>
<h3 class="blog">What is BASH and AWK?</h3>
<p>BASH is a free software Unix shell written for the GNU Project. Its name is an acronym which stands  for <em>Bourne-again shell</em>. The name is a pun on the name of the Bourne shell (<strong>sh</strong>), an early and important UNIX shell written by Stephen Bourne and distributed with Version 7 UNIX circa 1978, and the concept of being <em>born again</em>. BASH was created in 1987 by Brian Fox. In 1990 Chet Ramey became the primary maintainer. BASH is the default shell on most GNU/Linux systems as well as on Mac OS X and it can be run on most UNIX-like operating systems. It has also been ported to Microsoft Windows using the POSIX emulation provided by Cygwin, to MS-DOS by the DJGPP project and to Novell NetWare.</p>
<p>AWK is a general purpose programming language that is designed for processing text-based data, either in files or data streams, and was created at Bell Labs in the 1970s. The name AWK is derived from the family names of its authors — Alfred <strong>A</strong>ho, Peter <strong>W</strong>einberger, and Brian <strong>K</strong>ernighan; however, it is not commonly pronounced as a string of separate letters but rather to sound the same as the name of the bird, <strong>auk</strong>. <em>awk</em>, when written in all lowercase letters, refers to the UNIX or Plan 9 program that runs other programs written in the AWK programming language. AWK is an example of a programming language that extensively uses the string data type, associative arrays (that is, arrays indexed by key strings), and regular expressions. The power, terseness, and limitations of AWK programs and <strong>sed</strong> scripts inspired Larry Wall to write PERL. Because of their dense notation, all these languages are often used for writing one-liner programs. AWK is one of the early tools to appear in Version 7 UNIX and gained popularity as a way to add computational features to a UNIX pipeline. A version of the AWK language is a standard feature of nearly every modern UNIX-like operating system.</p>
<p><br clear="all"></p>
<h3 class="blog">The Script</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#! /bin/bash</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;"># Displays the number of login attempts by users</span>
<span style="color: #666666; font-style: italic;"># Gowtham, 2005.09.23</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot; <span style="color: #780078;">`hostname`</span> login attempts by users in this month&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span>
<span style="color: #c20cb9; font-weight: bold;">last</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $1}'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sort</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">uniq</span> <span style="color: #660033;">-c</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sort</span> <span style="color: #660033;">-nr</span></pre></td></tr></table></div>

<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fsgowtham.net%2Fblog%2F2005%2F09%2F23%2Fbash-login-counter%2F&amp;title=BASH%20%26%238211%3B%20Login%20Counter" id="wpa2a_42"><img src="http://sgowtham.net/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://sgowtham.net/blog/2005/09/23/bash-login-counter/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

