<?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>Shell Tips ! &#187; Common CLI</title>
	<atom:link href="http://www.shell-tips.com/category/common-cli/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.shell-tips.com</link>
	<description>Some useful tips about CLI tools, Shell scripts and batch files... GNU Bash, Windows XP, SQL, Help Sheets / Cheat Sheets, etc.</description>
	<lastBuildDate>Mon, 14 Jun 2010 08:56:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Performing Math calculation in Bash</title>
		<link>http://www.shell-tips.com/2010/06/14/performing-math-calculation-in-bash/</link>
		<comments>http://www.shell-tips.com/2010/06/14/performing-math-calculation-in-bash/#comments</comments>
		<pubDate>Mon, 14 Jun 2010 08:56:44 +0000</pubDate>
		<dc:creator>Nicolas Brousse</dc:creator>
				<category><![CDATA[Bash - GNU Shell]]></category>
		<category><![CDATA[Common CLI]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[bc]]></category>
		<category><![CDATA[cli]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[tip]]></category>

		<guid isPermaLink="false">http://www.shell-tips.com/?p=184</guid>
		<description><![CDATA[I use math in bash scripts a lot, from simple crontab reports to Nagios monitoring plugins&#8230; Here is few small examples on how to do some maths in Bash with integers or float. Integer Math First way to do math with integer (and only integer) is to use the command &#8220;expr &#8212; evaluate expression&#8220;. Mac-n-Cheese:~ [...]]]></description>
			<content:encoded><![CDATA[<p>I use math in bash scripts a lot, from simple crontab reports to Nagios monitoring plugins&#8230; Here is few small examples on how to do some maths in Bash with integers or float.</p>
<p><span id="more-184"></span><strong>Integer Math<br />
</strong></p>
<p>First way to do math with integer (and only integer) is to use the command &#8220;<em>expr &#8212; evaluate expression</em>&#8220;.</p>
<pre class="brush:shell">Mac-n-Cheese:~ nicolas$ expr 1 + 1
2
Mac-n-Cheese:~ nicolas$ myvar=$(expr 1 + 1)
Mac-n-Cheese:~ nicolas$ echo $myvar
2
Mac-n-Cheese:~ nicolas$ expr $myvar + 1
3
Mac-n-Cheese:~ nicolas$ expr $myvar / 3
1
Mac-n-Cheese:~ nicolas$ expr $myvar \* 3
9
</pre>
<p>When doing a &#8220;multiply by&#8221; make sure to backslash the &#8220;asterisk&#8221;  as it&#8217;s a wildcard in Bash used for expansion.</p>
<p>Another alternative to <em>expr</em>, is to use the bash builtin command <em>let</em>.</p>
<pre class="brush:shell">Mac-n-Cheese:~ nicolas$ echo $myvar
6
Mac-n-Cheese:~ nicolas$ let myvar+=1
Mac-n-Cheese:~ nicolas$ echo $myvar
7
Mac-n-Cheese:~ nicolas$ let myvar+1
Mac-n-Cheese:~ nicolas$ echo $myvar
7
Mac-n-Cheese:~ nicolas$ let myvar2=myvar+1
Mac-n-Cheese:~ nicolas$ echo $myvar2
8
</pre>
<p>Also, you can simply use the parentheses or square brackets :</p>
<pre class="brush:shell">Mac-n-Cheese:~ nicolas$ echo $myvar
3
Mac-n-Cheese:~ nicolas$ echo $((myvar+2))
5
Mac-n-Cheese:~ nicolas$ echo $[myvar+2]
5
Mac-n-Cheese:~ nicolas$ myvar=$((myvar+3))
</pre>
<p>This allow you to use C-style programming :</p>
<pre class="brush:shell">Mac-n-Cheese:~ nicolas$ echo $myvar
3
Mac-n-Cheese:~ nicolas$ echo $((myvar++))
3
Mac-n-Cheese:~ nicolas$ echo $myvar
4
Mac-n-Cheese:~ nicolas$ echo $((++myvar))
5
Mac-n-Cheese:~ nicolas$ echo $myvar
5
</pre>
<p><strong>Floating point arithmetic</strong></p>
<p>If you need to do floating point arithmetic, you will have to use a command line tool, the most common one is &#8220;<em>bc &#8211; An arbitrary precision calculator language</em>&#8220;.</p>
<pre class="brush:shell">Mac-n-Cheese:~ nicolas$ bc
bc 1.06
Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
3*5.2+7/8
15.6
15.6+299.33*2.3/7.4
108.6
</pre>
<p>Of course you can use the STDIN to send your formula to &#8220;<em>bc</em>&#8221; then get the output on STDOUT.</p>
<pre class="brush:shell">Mac-n-Cheese:~ nicolas$ echo "3.4+7/8-(5.94*3.14)" | bc
-15.25
</pre>
<p>I encourage you too take a look at the man pages to get more detail on how it works (<em>man bc</em>).</p>
<blockquote><p>There are four special variables, scale, ibase, obase, and last.  scale defines how some operations use digits after the decimal point.  The default value of scale is 0. ibase and obase define the conver-<br />
sion base for input and output numbers.  The default for both input and output is base 10.  last (an extension) is a variable that has the value of the last printed number.</p></blockquote>
<p>The &#8220;scale&#8221; variable is really important for the precision of your results, especially when using integers only (Note: you can also use &#8220;bc -l&#8221; to use mathlib and see the result at max scale) .</p>
<pre class="brush:shell">Mac-n-Cheese:~ nicolas$ echo "2/3" | bc
0
Mac-n-Cheese:~ nicolas$ echo "scale=2; 2/3" | bc
.66
Mac-n-Cheese:~ nicolas$ echo "(2/3)+(7/8)" | bc
0
Mac-n-Cheese:~ nicolas$ echo "scale=2;(2/3)+(7/8)" | bc
1.53
Mac-n-Cheese:~ nicolas$ echo "scale=4;(2/3)+(7/8)" | bc
1.5416
Mac-n-Cheese:~ nicolas$ echo "scale=6;(2/3)+(7/8)" | bc
1.541666
Mac-n-Cheese:~ nicolas$ echo "(2/3)+(7/8)" | bc -l
1.54166666666666666666
</pre>
<p>You can also use the here-doc notation to pass your formula to bc :</p>
<pre class="brush:shell">Mac-n-Cheese:~ nicolas$ bc -l &lt;&lt;&lt; "(2/3)+(7/8)"
1.54166666666666666666
</pre>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fwww.shell-tips.com%2F2010%2F06%2F14%2Fperforming-math-calculation-in-bash%2F&amp;title=Performing+Math+calculation+in+Bash" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fwww.shell-tips.com%2F2010%2F06%2F14%2Fperforming-math-calculation-in-bash%2F&amp;title=Performing+Math+calculation+in+Bash" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.shell-tips.com%2F2010%2F06%2F14%2Fperforming-math-calculation-in-bash%2F&amp;title=Performing+Math+calculation+in+Bash" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fwww.shell-tips.com%2F2010%2F06%2F14%2Fperforming-math-calculation-in-bash%2F&amp;headline=Performing+Math+calculation+in+Bash" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=Performing+Math+calculation+in+Bash&amp;url=http%3A%2F%2Fwww.shell-tips.com%2F2010%2F06%2F14%2Fperforming-math-calculation-in-bash%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=Performing+Math+calculation+in+Bash&amp;u=http%3A%2F%2Fwww.shell-tips.com%2F2010%2F06%2F14%2Fperforming-math-calculation-in-bash%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=Performing+Math+calculation+in+Bash&amp;url=http%3A%2F%2Fwww.shell-tips.com%2F2010%2F06%2F14%2Fperforming-math-calculation-in-bash%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=Performing+Math+calculation+in+Bash&amp;url=http%3A%2F%2Fwww.shell-tips.com%2F2010%2F06%2F14%2Fperforming-math-calculation-in-bash%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=Performing+Math+calculation+in+Bash&amp;url=http%3A%2F%2Fwww.shell-tips.com%2F2010%2F06%2F14%2Fperforming-math-calculation-in-bash%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.shell-tips.com%2F2010%2F06%2F14%2Fperforming-math-calculation-in-bash%2F&amp;title=Performing+Math+calculation+in+Bash&amp;summary=&amp;source=" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fwww.shell-tips.com%2F2010%2F06%2F14%2Fperforming-math-calculation-in-bash%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fwww.shell-tips.com%2F2010%2F06%2F14%2Fperforming-math-calculation-in-bash%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fwww.shell-tips.com%2F2010%2F06%2F14%2Fperforming-math-calculation-in-bash%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.shell-tips.com/2010/06/14/performing-math-calculation-in-bash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Common errors while starting Apache server on linux</title>
		<link>http://www.shell-tips.com/2007/02/14/common-errors-while-starting-apache-server-on-linux/</link>
		<comments>http://www.shell-tips.com/2007/02/14/common-errors-while-starting-apache-server-on-linux/#comments</comments>
		<pubDate>Wed, 14 Feb 2007 00:15:55 +0000</pubDate>
		<dc:creator>Nicolas Brousse</dc:creator>
				<category><![CDATA[Bash - GNU Shell]]></category>
		<category><![CDATA[Common CLI]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[apachectl]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[ipcrm]]></category>
		<category><![CDATA[ipcs]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[semaphore]]></category>

		<guid isPermaLink="false">http://www.shell-tips.com/2007/02/14/common-errors-while-starting-apache-server-on-linux/</guid>
		<description><![CDATA[The correct way to start the apache server is to use the apachectl command. apachectl stop apachectl start apachectl graceful You can also check your configuration files. apachectl configtest A common error is probably this one : (98)Address already in use: make_sock: could not bind to address 0.0.0.0:443 no listening sockets available, shutting down This [...]]]></description>
			<content:encoded><![CDATA[<p>The correct way to start the apache server is to use the <strong>apachectl</strong> command.</p>
<blockquote><p>apachectl stop</p>
<p>apachectl start</p>
<p>apachectl graceful</p></blockquote>
<p>You can also check your configuration files.</p>
<blockquote><p>apachectl configtest</p></blockquote>
<p>A common error is probably this one :</p>
<blockquote><p>(98)Address already in use: make_sock: could not bind to address 0.0.0.0:443</p></blockquote>
<blockquote><p>no listening sockets available, shutting down</p></blockquote>
<p>This is caused by one or more processes running on the 443 (secure socket) port. You can get all the process ID&#8217;s that are running on this port with the command <strong>fuser</strong> or a more classical &#8220;<strong>ps auxww</strong>&#8221; with a less readable format.</p>
<blockquote><p>nicolas@grimm:~$ fuser 443/tcp</p>
<p>443/tcp:        7977    6815    9819    35217</p></blockquote>
<blockquote><p>Now you just have to do a <strong>kill</strong> on those process.</p></blockquote>
<blockquote><p>nicolas@grimm:~$ kill -9 7977 6815 9819 35217</p>
<p>Or in a more sys admin useful way :</p>
<p>nicolas@grimm:~$ kill -9 $(fuse 443/tcp 2&gt;/dev/null)</p></blockquote>
<p>Other typical error would be those following :</p>
<blockquote><p>(28)No space left on device: Couldn&#8217;t create accept lock</p></blockquote>
<blockquote><p>or</p></blockquote>
<blockquote><p>(28)No space left on device: mod_rewrite: could not create rewrite_log_lock Configuration Failed</p></blockquote>
<p><span id="more-31"></span></p>
<p>Brain dead things is that you have plenty of space on your disk. Problem comes from apache that was not shutdown properly and lets lot of semaphore-arrays left. So, here comes <strong>ipcs</strong> command. ipcs provides information on the ipc facilities for which the calling process has read acccess.</p>
<blockquote><p>nicolas@grimm:~$ ipcs -s | grep www-data</p></blockquote>
<blockquote><p>0&#215;00000000 163840     www-data  600        1<br />
0&#215;00000000 196609     www-data  600        1<br />
0&#215;00000000 229378     www-data  600        1</p></blockquote>
<p>Before restart your apache you have to remove all this semaphore arrays by using <strong>ipcrm</strong>. ipcrm remove a message queue, semaphore set or shared memory id.</p>
<blockquote><p>nicolas@grimm:~$ ipcs -s | grep www-data | perl -e &#8216;while () { @a=split(/\s+/); print `ipcrm sem $a[1]`}&#8217;</p></blockquote>
<p>Now you should be able to start your apache. Lot of other error can happens. first thing to do is to take a look at your error log file then googleize ! ;-)</p>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fwww.shell-tips.com%2F2007%2F02%2F14%2Fcommon-errors-while-starting-apache-server-on-linux%2F&amp;title=Common+errors+while+starting+Apache+server+on+linux" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fwww.shell-tips.com%2F2007%2F02%2F14%2Fcommon-errors-while-starting-apache-server-on-linux%2F&amp;title=Common+errors+while+starting+Apache+server+on+linux" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.shell-tips.com%2F2007%2F02%2F14%2Fcommon-errors-while-starting-apache-server-on-linux%2F&amp;title=Common+errors+while+starting+Apache+server+on+linux" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fwww.shell-tips.com%2F2007%2F02%2F14%2Fcommon-errors-while-starting-apache-server-on-linux%2F&amp;headline=Common+errors+while+starting+Apache+server+on+linux" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=Common+errors+while+starting+Apache+server+on+linux&amp;url=http%3A%2F%2Fwww.shell-tips.com%2F2007%2F02%2F14%2Fcommon-errors-while-starting-apache-server-on-linux%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=Common+errors+while+starting+Apache+server+on+linux&amp;u=http%3A%2F%2Fwww.shell-tips.com%2F2007%2F02%2F14%2Fcommon-errors-while-starting-apache-server-on-linux%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=Common+errors+while+starting+Apache+server+on+linux&amp;url=http%3A%2F%2Fwww.shell-tips.com%2F2007%2F02%2F14%2Fcommon-errors-while-starting-apache-server-on-linux%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=Common+errors+while+starting+Apache+server+on+linux&amp;url=http%3A%2F%2Fwww.shell-tips.com%2F2007%2F02%2F14%2Fcommon-errors-while-starting-apache-server-on-linux%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=Common+errors+while+starting+Apache+server+on+linux&amp;url=http%3A%2F%2Fwww.shell-tips.com%2F2007%2F02%2F14%2Fcommon-errors-while-starting-apache-server-on-linux%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.shell-tips.com%2F2007%2F02%2F14%2Fcommon-errors-while-starting-apache-server-on-linux%2F&amp;title=Common+errors+while+starting+Apache+server+on+linux&amp;summary=&amp;source=" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fwww.shell-tips.com%2F2007%2F02%2F14%2Fcommon-errors-while-starting-apache-server-on-linux%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fwww.shell-tips.com%2F2007%2F02%2F14%2Fcommon-errors-while-starting-apache-server-on-linux%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fwww.shell-tips.com%2F2007%2F02%2F14%2Fcommon-errors-while-starting-apache-server-on-linux%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.shell-tips.com/2007/02/14/common-errors-while-starting-apache-server-on-linux/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
