<?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>Matt [Danger] &#187; Unix</title>
	<atom:link href="http://mattdanger.net/category/unix/feed/" rel="self" type="application/rss+xml" />
	<link>http://mattdanger.net</link>
	<description>One step closer to world domination</description>
	<lastBuildDate>Fri, 02 Dec 2011 18:20:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>perl-Net-SSLeay dependency error when installing Memcached with yum</title>
		<link>http://mattdanger.net/2010/12/perl-net-ssleay-dependency-error-when-installing-memcached-with-yum/</link>
		<comments>http://mattdanger.net/2010/12/perl-net-ssleay-dependency-error-when-installing-memcached-with-yum/#comments</comments>
		<pubDate>Fri, 03 Dec 2010 23:39:19 +0000</pubDate>
		<dc:creator>Matt Danger</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[Unix]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[memcached]]></category>
		<category><![CDATA[perl-IO-Socket-SSL]]></category>
		<category><![CDATA[perl-Net-SSLeay]]></category>
		<category><![CDATA[yum]]></category>

		<guid isPermaLink="false">http://mattdanger.net/?p=297</guid>
		<description><![CDATA[Today while configuring another production CentOS 5.5 machine I ran into a problem where memcached refused to install. [root@localhost ~]# yum install memcached Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * rpmforge: apt.sw.be rpmforge &#124; 1.1 kB 00:00 rpmforge/primary &#124; 2.2 MB 00:01 rpmforge 10361/10361 Setting up Install Process Resolving Dependencies --> Running&#8230;]]></description>
			<content:encoded><![CDATA[<p>Today while configuring another production CentOS 5.5 machine I ran into a problem where memcached refused to install.</p>
<p><code>[root@localhost ~]# yum install memcached<br />
Loaded plugins: fastestmirror<br />
Loading mirror speeds from cached hostfile<br />
 * rpmforge: apt.sw.be<br />
rpmforge                                                                                                        | 1.1 kB     00:00<br />
rpmforge/primary                                                                                                | 2.2 MB     00:01<br />
rpmforge                                                                                                                   10361/10361<br />
Setting up Install Process<br />
Resolving Dependencies<br />
--> Running transaction check<br />
---> Package memcached.i386 0:1.4.5-1.el5.rf set to be updated<br />
--> Processing Dependency: perl(AnyEvent) for package: memcached<br />
--> Processing Dependency: perl(AnyEvent::Socket) for package: memcached<br />
--> Processing Dependency: perl(AnyEvent::Handle) for package: memcached<br />
--> Processing Dependency: libevent-1.1a.so.1 for package: memcached<br />
--> Processing Dependency: perl(YAML) for package: memcached<br />
--> Processing Dependency: perl(Term::ReadKey) for package: memcached<br />
--> Running transaction check<br />
---> Package compat-libevent-11a.i386 0:3.2.1-1.el5.rf set to be updated<br />
---> Package perl-AnyEvent.noarch 0:5.240-1.el5.rf set to be updated<br />
--> Processing Dependency: perl(JSON::XS) >= 2.2 for package: perl-AnyEvent<br />
--> Processing Dependency: perl(JSON) >= 2.09 for package: perl-AnyEvent<br />
--> Processing Dependency: perl(EV) >= 3.05 for package: perl-AnyEvent<br />
--> Processing Dependency: perl(Guard) >= 1.02 for package: perl-AnyEvent<br />
--> Processing Dependency: perl(Net::SSLeay) >= 1.33 for package: perl-AnyEvent<br />
---> Package perl-TermReadKey.i386 0:2.30-3.el5.rf set to be updated<br />
---> Package perl-YAML.noarch 0:0.71-1.el5.rf set to be updated<br />
--> Running transaction check<br />
---> Package perl-AnyEvent.noarch 0:5.240-1.el5.rf set to be updated<br />
--> Processing Dependency: perl(Net::SSLeay) >= 1.33 for package: perl-AnyEvent<br />
---> Package perl-EV.i386 0:3.9-1.el5.rf set to be updated<br />
--> Processing Dependency: perl(common::sense) for package: perl-EV<br />
---> Package perl-Guard.i386 0:1.021-1.el5.rf set to be updated<br />
---> Package perl-JSON.noarch 0:2.17-1.el5.rf set to be updated<br />
---> Package perl-JSON-XS.i386 0:2.27-1.el5.rf set to be updated<br />
--> Running transaction check<br />
---> Package perl-AnyEvent.noarch 0:5.240-1.el5.rf set to be updated<br />
--> Processing Dependency: perl(Net::SSLeay) >= 1.33 for package: perl-AnyEvent<br />
---> Package perl-common-sense.i386 0:3.0-1.el5.rf set to be updated<br />
--> Finished Dependency Resolution<br />
perl-AnyEvent-5.240-1.el5.rf.noarch from rpmforge has depsolving problems<br />
  --> Missing Dependency: perl(Net::SSLeay) >= 1.33 is needed by package perl-AnyEvent-5.240-1.el5.rf.noarch (rpmforge)<br />
Error: Missing Dependency: perl(Net::SSLeay) >= 1.33 is needed by package perl-AnyEvent-5.240-1.el5.rf.noarch (rpmforge)<br />
 You could try using --skip-broken to work around the problem<br />
 You could try running: package-cleanup --problems<br />
                        package-cleanup --dupes<br />
                        rpm -Va --nofiles --nodigest<br />
The program package-cleanup is found in the yum-utils package.<br />
</code></p>
<p>CentOS&#8217;s yum repository doesn&#8217;t have the latest perl-Net-SSLeay and perl-IO-Socket-SSL packages that are required by memcached. I did some Googling to find that <a href="http://www.linuxquestions.org/questions/linux-software-2/memcached-844721/">others</a> were experiencing a similar problem without resolution. Here&#8217;s the simple fix:</p>
<p>First, remove the old perl modules. Then download and install the newer versions that memcached requires.</p>
<p><code>rpm-e perl-Net-SSLeay-1.30-4.fc6<br />
rpm -e perl-IO-Socket-SSL-1.01-1.fc6<br />
wget http://packages.sw.be/perl-Net-SSLeay/perl-Net-SSLeay-1.36-1.el5.rfx.i386.rpm<br />
wget http://packages.sw.be/perl-Net-SSLeay/perl-Net-SSLeay-1.36-1.el5.rfx.x86_64.rpm<br />
wget http://packages.sw.be/perl-IO-Socket-SSL/perl-IO-Socket-SSL-1.34-1.el5.rfx.noarch.rpm<br />
rpm -i perl-Net-SSLeay-1.36-1.el5.rfx.x86_64.rpm<br />
rpm -i perl-Net-SSLeay-1.36-1.el5.rfx.i386.rpm<br />
rpm -i perl-IO-Socket-SSL-1.34-1.el5.rfx.noarch.rpm</code></p>
<p>Now you should be able to install memcached without error.</p>
<p><code>yum -y install memcached</code></p>
<p>If you experience an error removing either of the packages then you can try greping to see if you have other versions installed.</p>
<p><code>rpm -qa | grep perl-Net-SSLeay</code></p>
<p>and </p>
<p><code>rpm -qa | grep perl-IO-Socket-SSL</code></p>
]]></content:encoded>
			<wfw:commentRss>http://mattdanger.net/2010/12/perl-net-ssleay-dependency-error-when-installing-memcached-with-yum/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Facebook-Status-2.0 announced!</title>
		<link>http://mattdanger.net/2009/02/facebook-status-20-announced/</link>
		<comments>http://mattdanger.net/2009/02/facebook-status-20-announced/#comments</comments>
		<pubDate>Tue, 10 Feb 2009 18:33:01 +0000</pubDate>
		<dc:creator>Matt Danger</dc:creator>
				<category><![CDATA[Announcements]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[terminal]]></category>
		<category><![CDATA[Unix]]></category>
		<category><![CDATA[Facebook]]></category>
		<category><![CDATA[shell script]]></category>
		<category><![CDATA[status]]></category>

		<guid isPermaLink="false">http://mattdanger.net/?p=155</guid>
		<description><![CDATA[I have updated my original Facebook status script to work with Facebook 2.0. Why is this interesting? Until recently the Facebook Developer Platform didn&#8217;t allow the changing of user status messages. This does and can be implemented in other utilities, which I may do in the future. Enjoy!]]></description>
			<content:encoded><![CDATA[<p>I have <a href="http://mattdanger.net/2008/11/update-your-facebook-status-from-the-command-line/">updated my original Facebook status script</a> to work with Facebook 2.0.</p>
<p>Why is this interesting? Until <a href="http://www.allfacebook.com/2009/02/facebook-opens-status-api-say-goodbye-to-twitter/">recently</a> the Facebook Developer Platform didn&#8217;t allow the changing of user status messages. This does and can be implemented in other utilities, which I may do in the future. Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://mattdanger.net/2009/02/facebook-status-20-announced/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bash Examples</title>
		<link>http://mattdanger.net/2008/11/bash-examples/</link>
		<comments>http://mattdanger.net/2008/11/bash-examples/#comments</comments>
		<pubDate>Sun, 23 Nov 2008 23:35:14 +0000</pubDate>
		<dc:creator>Matt Danger</dc:creator>
				<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[Unix]]></category>
		<category><![CDATA[Bash]]></category>

		<guid isPermaLink="false">http://mattdanger.net/?p=8</guid>
		<description><![CDATA[A while ago a friend was taking an entry level Unix programming class and asked me to help him study. I came up with some sample problems for him. Here are my solutions: The first is a program that will allow a user to input as many numbers as the user wants (999 as the&#8230;]]></description>
			<content:encoded><![CDATA[<p>A while ago a friend was taking an entry level Unix programming class and asked me to help him study. I came up with some sample problems for him. Here are my solutions:</p>
<p>The first is a program that will allow a user to input as many numbers as the user wants (999 as the choice that ends the user input). The program will then output the highest number, the lowest number, the sum of all the numbers, and the average number.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #007800;">COUNT</span>=<span style="color: #000000;">0</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Enter a number (999 to quit): &quot;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #c20cb9; font-weight: bold;">read</span> NUM; <span style="color: #000000; font-weight: bold;">do</span>
  <span style="color: #666666; font-style: italic;"># Set initials</span>
  <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$COUNT</span> <span style="color: #660033;">-eq</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: #007800;">HIGHEST</span>=<span style="color: #007800;">$NUM</span>
    <span style="color: #007800;">LOWEST</span>=<span style="color: #007800;">$NUM</span>
    <span style="color: #007800;">SUM</span>=<span style="color: #007800;">$NUM</span>
  <span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
  <span style="color: #666666; font-style: italic;"># If 999 is entered, break out</span>
  <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$NUM</span> <span style="color: #660033;">-eq</span> <span style="color: #000000;">999</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;">break</span>
  <span style="color: #000000; font-weight: bold;">else</span>
    <span style="color: #666666; font-style: italic;"># See if inputted number is the highest number</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$NUM</span> <span style="color: #660033;">-gt</span> <span style="color: #007800;">$HIGHEST</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
      <span style="color: #007800;">HIGHEST</span>=<span style="color: #007800;">$NUM</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># See if inputted number is the lowest number</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$NUM</span> <span style="color: #660033;">-lt</span> <span style="color: #007800;">$LOWEST</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
      <span style="color: #007800;">LOWEST</span>=<span style="color: #007800;">$NUM</span>;
    <span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># Calculate sum</span>
    <span style="color: #007800;">SUM</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$SUM</span>+<span style="color: #007800;">$NUM</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Enter another number (999 to quit): &quot;</span>
  <span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
  <span style="color: #007800;">COUNT</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$COUNT</span>+<span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #007800;">AVERAGE</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$SUM</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$COUNT</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Highest number: <span style="color: #007800;">$HIGHEST</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Lowest number: <span style="color: #007800;">$LOWEST</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Sum of the numbers: <span style="color: #007800;">$SUM</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Average of the numbers: <span style="color: #007800;">$AVERAGE</span>&quot;</span></pre></div></div>

<p>The second program is a number guessing game. The computer picks a number from 0-60 then allows the user to guess at the number until the user gets it right. The program gives the user a hint on whether they should guess a higher or lower number.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash </span>
<span style="color: #007800;">RAN</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>RANDOM<span style="color: #000000; font-weight: bold;">%</span>60<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">COUNTER</span>=<span style="color: #000000;">1</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;I've guessed a number between 0-60, what is it? &quot;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #c20cb9; font-weight: bold;">read</span> GUESS; <span style="color: #000000; font-weight: bold;">do</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$GUESS</span> <span style="color: #660033;">-eq</span> <span style="color: #007800;">$RAN</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;">break</span>;
  <span style="color: #000000; font-weight: bold;">else</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$GUESS</span> <span style="color: #660033;">-lt</span> <span style="color: #007800;">$RAN</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: #660033;">-n</span> <span style="color: #ff0000;">&quot;Nope, try a higher number: &quot;</span>
    <span style="color: #000000; font-weight: bold;">else</span>
      <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Nope, try a lower number: &quot;</span>
    <span style="color: #000000; font-weight: bold;">fi</span>	
  <span style="color: #000000; font-weight: bold;">fi</span>
  <span style="color: #007800;">COUNTER</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>COUNTER+<span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">done</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;Yep, good job! It took you <span style="color: #007800;">$COUNTER</span> tries to guess correctly.&quot;</span></pre></div></div>

<p>The third program allows a user to type in a number, then the program will either count up to the number provided by the user or count down from that number. In addition, a menu lets the user choose which counter they wish to use. In both cases that counter will either count down to 0, or start counting from 0.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash </span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Enter a number: &quot;</span>; <span style="color: #c20cb9; font-weight: bold;">read</span> NUM
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Enter U to count up to <span style="color: #007800;">$NUM</span> and D to count down to 0: &quot;</span>; <span style="color: #c20cb9; font-weight: bold;">read</span> CHOICE
&nbsp;
<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #007800;">$CHOICE</span> <span style="color: #000000; font-weight: bold;">in</span>
  <span style="color: #ff0000;">'u'</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #ff0000;">'U'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> 
    <span style="color: #007800;">COUNTER</span>=<span style="color: #000000;">0</span>
    <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$COUNTER</span> <span style="color: #660033;">-le</span> <span style="color: #007800;">$NUM</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">do</span>
      <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$COUNTER</span>
      <span style="color: #007800;">COUNTER</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$COUNTER</span>+<span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
    <span style="color: #000000; font-weight: bold;">done</span> <span style="color: #000000; font-weight: bold;">;;</span>
  <span style="color: #ff0000;">'d'</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #ff0000;">'D'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
    <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$NUM</span> <span style="color: #660033;">-ge</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">do</span>
      <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$NUM</span>;
      <span style="color: #007800;">NUM</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$NUM</span>-<span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
    <span style="color: #000000; font-weight: bold;">done</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;Error: You entered an invalid argument.&quot;</span>
<span style="color: #000000; font-weight: bold;">esac</span></pre></div></div>

<p>The last program asks the user if they want to add, subtract, multiply or divide two user inputted numbers. Then the program outputs the sum of number 1 and number 2, the difference of number 1 and number 2, the product of number 1 and number 2, and the quotient of number 1 and number 2</p>
<p>This program will run until the user wants to quit. Also, if the user puts in a 0 as the second number, we let the user know that if they choose divide that a division by zero error will occur.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #c20cb9; font-weight: bold;">true</span>; <span style="color: #000000; font-weight: bold;">do</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Please enter two numbers (type 'q' to quit): &quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Number 1: &quot;</span>
  <span style="color: #c20cb9; font-weight: bold;">read</span> NUM1
  <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$NUM1</span> == <span style="color: #ff0000;">&quot;q&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;">exit</span>; <span style="color: #000000; font-weight: bold;">fi</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Number 2: &quot;</span>
  <span style="color: #c20cb9; font-weight: bold;">read</span> NUM2
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Enter (a) to add, (s) to subtract, (m) to multiply, or (d) to divide these numbers: &quot;</span>
  <span style="color: #c20cb9; font-weight: bold;">read</span> OPERATION
&nbsp;
  <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #007800;">$OPERATION</span> <span style="color: #000000; font-weight: bold;">in</span>
    a<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;The sum of <span style="color: #007800;">$NUM1</span> and <span style="color: #007800;">$NUM2</span> is: <span style="color: #007800;">$(($NUM1+$NUM2)</span>)&quot;</span> <span style="color: #000000; font-weight: bold;">;;</span>
    s<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;The difference of <span style="color: #007800;">$NUM1</span> and <span style="color: #007800;">$NUM2</span> is: <span style="color: #007800;">$(($NUM1-$NUM2)</span>)&quot;</span><span style="color: #000000; font-weight: bold;">;;</span>
    m<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;The product of <span style="color: #007800;">$NUM1</span> and <span style="color: #007800;">$NUM2</span> is: <span style="color: #007800;">$(($NUM1*$NUM2)</span>)&quot;</span> <span style="color: #000000; font-weight: bold;">;;</span>
    d<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$NUM2</span> <span style="color: #660033;">-eq</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: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;You can't divide by 0, a division by zero error will occur.&quot;</span>
      <span style="color: #000000; font-weight: bold;">else</span> 			
	    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;The quotient of <span style="color: #007800;">$NUM1</span> and <span style="color: #007800;">$NUM2</span> is: <span style="color: #007800;">$(($NUM1/$NUM2)</span>)&quot;</span>
      <span style="color: #000000; font-weight: bold;">fi</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;">done</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://mattdanger.net/2008/11/bash-examples/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Newest LiveJournal Images</title>
		<link>http://mattdanger.net/2004/11/newest-livejournal-images/</link>
		<comments>http://mattdanger.net/2004/11/newest-livejournal-images/#comments</comments>
		<pubDate>Wed, 24 Nov 2004 17:54:07 +0000</pubDate>
		<dc:creator>Matt Danger</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Unix]]></category>
		<category><![CDATA[LiveJournal]]></category>

		<guid isPermaLink="false">http://mattdanger.net/?p=16</guid>
		<description><![CDATA[This script displays the newest images posted by LiveJournal users. The script is pretty basic and simply parses a feed from LiveJournal. You can view it in action here: http://mattdanger.net/lj/ (Warning: Some images may be NSFW!) The code: &#60;?php &#160; $n = 5; // Maximum is 250 $referrer = 'http://example.com'; // Your site $email = 'user@example.com';&#8230;]]></description>
			<content:encoded><![CDATA[<p>This script displays the newest images posted by LiveJournal users. The script is pretty basic and simply parses a feed from LiveJournal.</p>
<p>You can view it in action here: <a href="http://mattdanger.net/lj/">http://mattdanger.net/lj/</a> (Warning: Some images may be NSFW!)</p>
<p>The code:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000088;">$n</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Maximum is 250</span>
<span style="color: #000088;">$referrer</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://example.com'</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Your site</span>
<span style="color: #000088;">$email</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'user@example.com'</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Your email</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fsockopen</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'livejournal.com'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">80</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #990000;">fputs</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;GET /stats/latest-img.bml HTTP/1.0rn&quot;</span> <span style="color: #339933;">.</span>
      <span style="color: #0000ff;">&quot;Host: www.livejournal.comrn&quot;</span> <span style="color: #339933;">.</span>
      <span style="color: #0000ff;">&quot;User-Agent: &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$referrer</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;; &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$email</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;rnrn&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">feof</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000088;">$data</span> <span style="color: #339933;">.=</span> <span style="color: #990000;">fgets</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">preg_match_all</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;recent-image img='([^']+)' url='([^']+)' /&gt;&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #339933;">,</span> <span style="color: #000088;">$out</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$n</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;a href=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$out</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$out</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;n&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <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>
&nbsp;
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Connecting to LiveJournal failed.&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>As an aside, if you&#8217;re a LiveJournal user and don&#8217;t want your images posted to the public feed you can go to your <a href="http://www.livejournal.com/admin/console/">command console</a> and type &#8220;set latest_optout yes&#8221;.</p>
]]></content:encoded>
			<wfw:commentRss>http://mattdanger.net/2004/11/newest-livejournal-images/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

