<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss1full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns="http://purl.org/rss/1.0/" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">
<channel rdf:about="http://aplawrence.com/fullrss.rdf">
<title>Main Site News at A.P.Lawrence.com</title>
<link>http://aplawrence.com/</link>
<description>
Main feed at aplawrence.com: Thousands of articles, reviews, consultants listings, skills tests, opinion, how-to's for Unix, Linux and Mac OS X, networking, web site maintenance and more.. 
</description>
<sy:updatePeriod>hourly</sy:updatePeriod>
<sy:updateFrequency>6</sy:updateFrequency>
<sy:updateBase>2008-01-01T00:00+00:00</sy:updateBase>
<dc:language>en</dc:language>
<dc:publisher>A.P. Lawrence</dc:publisher>
<dc:rights>Copyright  A.P. Lawrence</dc:rights>
<dc:creator>A.P. Lawrence (mailto:rssfeeds@aplawrence.com)</dc:creator>
<dc:date>2009-11-15T19:27:42+00:00</dc:date>
<image rdf:resource="http://aplawrence.com/image21.gif">
</image>
<items>
<rdf:Seq>
<rdf:li rdf:resource="http://aplawrence.com/Unixart/sort-vs-uniq.html" />
<rdf:li rdf:resource="http://aplawrence.com/Girish/LiveUSB.html" />
<rdf:li rdf:resource="http://aplawrence.com/Unixart/google-go.html" />
<rdf:li rdf:resource="http://aplawrence.com/Unixart/network-fishing.html" />
<rdf:li rdf:resource="http://aplawrence.com/Unixart/awk-vs.perl.html" />
<rdf:li rdf:resource="http://aplawrence.com/Linux/setting-colors.html" />
<rdf:li rdf:resource="http://aplawrence.com/Linux/strange-hack.html" />
<rdf:li rdf:resource="http://aplawrence.com/Linux/samba-pigs.html" />
</rdf:Seq>
</items>
<geo:lat>41.889582</geo:lat><geo:long>-70.894066</geo:long><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/aplawrence/ZPYH" type="application/rss+xml" /><feedburner:emailServiceId>aplawrence/ZPYH</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /></channel>
<image rdf:about="http://aplawrence.com/image21.gif">
<title>A.P.Lawrence Logo</title>
<url>http://aplawrence.com/image21.gif</url>
<link>http://aplawrence.com</link>
</image>


<item rdf:about="http://aplawrence.com/Unixart/sort-vs-uniq.html">
<title>Sort -u vs. uniq  </title>
<description>Linux,MacOSX,Basics,Shell,Programming 

2009/11/15&lt;br /&gt;
&lt;!-- LEFTADOK --&gt;
&lt;!-- PCOUNT --&gt;
&lt;!-- PCOUNT --&gt;

&lt;p&gt;I have sometimes seen people use a pipeline that includes "sort | uniq".  The result of that is no different than just adding a -u flag to sort and absolutely requires more time and processing power - not that it usually matters; unless the input is humongously long, you'd need to run them through "time" to spot any difference.   So why use "uniq"?&lt;/p&gt;
&lt;p&gt;For cases like that, where there is no difference in the output, it's probably just habit - you may be accustomed to using "uniq" for other jobs and just reach for it automatically.  I'll argue that it's a good habit to have:  if you are in the habit of using "sort -u", you may tend to forget about "uniq" and that could cause you do do something much more difficult and clumsy when a job needs something that "uniq" does well.&lt;/p&gt;
&lt;p&gt;However, it's also true that "sort" has tricks that "uniq" lacks, so if you only know about "uniq", you again could make your life more difficult.&lt;/p&gt;
&lt;p&gt;One of the helpful abilities that "sort" has is the ability to specify the field separator.  Let's take a sample file:&lt;/p&gt;
&lt;pre&gt;
A:B:C:D
a:b:c:d
t:b:c:d
t:b:c:d
a:b:c:d
a:b:x:d
foo:b:x:d
f:a:x:d
&lt;/pre&gt;
&lt;p&gt;If all we cared about was removing duplicatelines, we could use "sort -u file" or "sort file | uniq".  But what if we want to sort by the second field?&lt;/p&gt;
&lt;p&gt;We can do that directly with "sort -t: -k 2 -u", but it's much harder to do with "uniq" because you can't tell it a separator character.  You can get around that partially with "tr" or "sed", translating ":"'s to spaces or tabs, but that's clumsy.   Even after translating, "uniq" only lets you skip fields, so you don't get quite the same output:&lt;/p&gt;
&lt;pre&gt;
$ sort -t: -k 2 -u file
A:B:C:D
f:a:x:d
a:b:c:d
a:b:x:d
$ cat file | tr ":" " " | sort | uniq -f1
A B C D
a b c d
a b x d
f a x d
foo b x d
t b c d
&lt;/pre&gt;
&lt;p&gt;We could argue about which output truly represents unique lines when sorted on field 2, but the point to understand is that skipping fields isn't the same as what "sort" does.&lt;/p&gt;
&lt;p&gt;You can also lock down fields with "sort" :&lt;/p&gt;
&lt;pre&gt;
$ sort -t: -u -k2,2   file
A:B:C:D
f:a:x:d
a:b:c:d
&lt;/pre&gt;
&lt;p&gt;As "uniq" can only skip fields and can't anchor to one field only, it's much harder to get these results.  However, "uniq" again has tricks that "sort" can't do: it can skip a specific number of characters in addition to   skipping fields.  It can also give you only the unique lines or only the lines that were repeated:&lt;/p&gt;

&lt;pre&gt;
$ sort file | uniq -u  # only the unique, non-repeated lines
A:B:C:D
a:b:x:d
f:a:x:d
foo:b:x:d
$ sort file | uniq -d  # repeated lines
a:b:c:d
t:b:c:d
&lt;/pre&gt;
&lt;p&gt;Either of those is extremely convoluted without "uniq", and the need for one or the other does come up surprisingly often.&lt;/p&gt;
&lt;p&gt;Somebody thought that we could use "sort" and "uniq" in one program: &lt;a href="http://256.com/sources/sortu/"&gt;Sortu&lt;/a&gt; is the result.&lt;/p&gt;

&lt;blockquote&gt;
The sortu program is a replacement for the sort and uniq programs. It is common for Unix script writers to want to count how many separate patterns are in a file. For example, if you have a list of addresses, you may want to see how many are from each state. So you cut out the state part, sort these, and then pass them through uniq -c. Sortu does all this for you in a fraction of the time. 
&lt;/blockquote&gt;
&lt;p&gt;I think by the time I figured out how to use "sortu" I could have already done the job another way, but you might find it interesting anyway.&lt;/p&gt;
&lt;p&gt;I think the important thing is to realize that "sort" and "uniq" have both conflicting and complementary abilities.  Don't tie yourself in pipeline knots with either of them; learn to use each of them appropriately and your scripts will be easier.&lt;/p&gt;


&lt;p&gt;Comments: &lt;a href="http://aplawrence.com/cgi-bin/newcomm.pl?commenting=/Unixart/sort-vs-uniq.html"&gt;Click Here.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;br /&gt;&lt;i&gt;&lt;b&gt;Many of the products and books I review are things I purchased for my own use.  Some were given to me specifically for the purpose of   reviewing them.&lt;/b&gt;&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;&lt;i&gt;&lt;b&gt;I resell or can earn commissions from the sale of some of these items.  Links within these pages may be affiliate links that pay me for referring you 
to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain.  If you have any question, please do feel free to contact me.&lt;/b&gt;&lt;/i&gt;&lt;/p&gt;
&lt;div style="font-size:80%"&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td&gt; - &lt;/td&gt;
&lt;td&gt;&lt;a href="http://aplawrence.com/Tests"&gt;Skills Tests&lt;/a&gt;&lt;/td&gt;
&lt;td&gt; - &lt;/td&gt;
&lt;td&gt;&lt;a href="http://aplawrence.com/psst.html"&gt;Psst - wanna work for yourself?&lt;/a&gt;&lt;/td&gt;
&lt;td&gt; - &lt;/td&gt;&lt;td&gt;&lt;a href="http://aplawrence.com/troubleshootingbook.html"&gt;Unix/Linux Troubleshooting e-book&lt;/a&gt;&lt;/td&gt;
&lt;td&gt; - &lt;/td&gt;
&lt;td&gt;&lt;a href="http://aplawrence.com/Kerio"&gt;Kerio Mail Server&lt;/a&gt;&lt;/td&gt;
&lt;td&gt; - &lt;/td&gt;
&lt;td&gt;&lt;a href="http://aplawrence.com/rates.html"&gt;Consulting&lt;/a&gt;&lt;/td&gt;
&lt;td&gt; - &lt;/td&gt;
&lt;td&gt;&lt;a href="http://aplawrence.com/advert.html"&gt;Advertise Here&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/_PKs2QMhuZN9-nMYpsdhS1mykyE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/_PKs2QMhuZN9-nMYpsdhS1mykyE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/_PKs2QMhuZN9-nMYpsdhS1mykyE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/_PKs2QMhuZN9-nMYpsdhS1mykyE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/aplawrence/ZPYH?a=fpBZ-CRml0o:Ff3fL5d021E:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/aplawrence/ZPYH?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/aplawrence/ZPYH/~4/fpBZ-CRml0o" height="1" width="1"/&gt;</description>
<link>http://feedproxy.google.com/~r/aplawrence/ZPYH/~3/fpBZ-CRml0o/sort-vs-uniq.html</link>
<feedburner:origLink>http://aplawrence.com/Unixart/sort-vs-uniq.html</feedburner:origLink></item>
<item rdf:about="http://aplawrence.com/Girish/LiveUSB.html">
<title>LiveUSB OpenBSD project at sourceforge  by Girish Venkatachalam</title>
<description>Programming,Girish 

2009/11/14 Girish Venkatachalam

&lt;!-- LEFTADOK --&gt;
&lt;!-- PCOUNT --&gt;
&lt;!-- PCOUNT --&gt;

&lt;br /&gt;&lt;br /&gt;
&lt;p&gt;&lt;i&gt;Girish Venkatachalam is a UNIX hacker with more than a decade of
networking and crypto programming experience.
His hobbies include yoga,cycling, cooking and he &lt;a href="http://gayatri-hitech.com/about.html"&gt;runs his own
business.&lt;/a&gt; Details here:&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;

&lt;a href="http://gayatri-hitech.com"&gt;http://gayatri-hitech.com&lt;/a&gt;
&lt;br /&gt;&lt;a href="http://spam-cheetah.com"&gt;http://spam-cheetah.com&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
It is really easy to create a USB bootable OpenBSD LiveUSB image. With
that you can do just about anything you want. Don&amp;#39;t believe me?
&lt;/p&gt;

&lt;p&gt;
Then head to &lt;a href="http://liveusb-openbsd.sf.net" target="_blank"&gt;http://liveusb-openbsd.sourceforge.net&lt;/a&gt;
and download the USB image. Boot it and find out!

&lt;/p&gt;

&lt;p&gt;
You can watch videos with mplayer in full screen, you can bask in the
glory of mplayer&amp;#39;s sexy OSD menu, you can read manual pages in color,
you can lookup English words using the dictionary client, you can chat
with pidgin, you can browse with Mozilla Firefox, you can use sox to
convert audio, you can play any video or audio file with mplayer, you
can stream audio from the Internet, you can do whatever you want!
&lt;/p&gt;

&lt;p&gt;
Moreover you can also use the rich repertoire of tiny but incredibly
powerful tools like netcat, socat, nmh, mutt, vim, randtype, figlet.
After all the man pages tell you how to use these tools and you have
examples too. You also have ready access to the perl, python and lua
interpreters, you have all the spam control daemons, the routing
protocols like BGP or OSP, you have FTP server, HTTP server or 
 you could do image processing with ImageMagick.
&lt;/p&gt;

&lt;p&gt;
There is one detail however.
&lt;/p&gt;

&lt;p&gt;
You have to use DHCP to connect to the Internet if your ADSL MODEM
dishes out dynamic IPs or you can configure the IP using the ifconfig
command. Usually this will do.

&lt;/p&gt;

&lt;pre&gt;
	# dhclient vr0
	(Your ethernet interface could be fxp0, rl0 or something else,
find out with ifconfig)
&lt;/pre&gt;

&lt;p&gt;
Give it a whirl and get in touch with me should you have any issues
using this. After all it is free and open source.
&lt;/p&gt;

&lt;p&gt;
And oh by the way the fixed write cycles of USB memory drives is largely
a myth.
&lt;/p&gt;


&lt;div style="text-align:center"&gt;&lt;a href="http://www.spam-cheetah.com/"&gt;&lt;img src="http://www.spam-cheetah.com/images/spam-cheetah.jpg" alt="running cheetah" /&gt;&lt;br /&gt; SpamCheetah&lt;br /&gt;Stop spam dead in its tracks!&lt;/a&gt;&lt;/div&gt;


&lt;p&gt;Comments: &lt;a href="http://aplawrence.com/cgi-bin/newcomm.pl?commenting=/Girish/LiveUSB.html"&gt;Click Here.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;br /&gt;&lt;i&gt;&lt;b&gt;Many of the products and books I review are things I purchased for my own use.  Some were given to me specifically for the purpose of   reviewing them.&lt;/b&gt;&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;&lt;i&gt;&lt;b&gt;I resell or can earn commissions from the sale of some of these items.  Links within these pages may be affiliate links that pay me for referring you 
to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain.  If you have any question, please do feel free to contact me.&lt;/b&gt;&lt;/i&gt;&lt;/p&gt;
&lt;div style="font-size:80%"&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td&gt; - &lt;/td&gt;
&lt;td&gt;&lt;a href="http://aplawrence.com/Tests"&gt;Skills Tests&lt;/a&gt;&lt;/td&gt;
&lt;td&gt; - &lt;/td&gt;
&lt;td&gt;&lt;a href="http://aplawrence.com/psst.html"&gt;Psst - wanna work for yourself?&lt;/a&gt;&lt;/td&gt;
&lt;td&gt; - &lt;/td&gt;&lt;td&gt;&lt;a href="http://aplawrence.com/troubleshootingbook.html"&gt;Unix/Linux Troubleshooting e-book&lt;/a&gt;&lt;/td&gt;
&lt;td&gt; - &lt;/td&gt;
&lt;td&gt;&lt;a href="http://aplawrence.com/Kerio"&gt;Kerio Mail Server&lt;/a&gt;&lt;/td&gt;
&lt;td&gt; - &lt;/td&gt;
&lt;td&gt;&lt;a href="http://aplawrence.com/rates.html"&gt;Consulting&lt;/a&gt;&lt;/td&gt;
&lt;td&gt; - &lt;/td&gt;
&lt;td&gt;&lt;a href="http://aplawrence.com/advert.html"&gt;Advertise Here&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Xjo1U-Hbut-hRB2puRTEN5ZfQvY/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Xjo1U-Hbut-hRB2puRTEN5ZfQvY/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Xjo1U-Hbut-hRB2puRTEN5ZfQvY/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Xjo1U-Hbut-hRB2puRTEN5ZfQvY/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/aplawrence/ZPYH?a=ZVp2mbQCoEY:JGbltO63obc:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/aplawrence/ZPYH?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/aplawrence/ZPYH/~4/ZVp2mbQCoEY" height="1" width="1"/&gt;</description>
<link>http://feedproxy.google.com/~r/aplawrence/ZPYH/~3/ZVp2mbQCoEY/LiveUSB.html</link>
<feedburner:origLink>http://aplawrence.com/Girish/LiveUSB.html</feedburner:origLink></item>
<item rdf:about="http://aplawrence.com/Unixart/google-go.html">
<title>Google's Go  </title>
<description>Linux,MacOSX,Programming 

2009/11/12&lt;br /&gt;
&lt;!-- LEFTADOK --&gt;
&lt;!-- PCOUNT --&gt;
&lt;!-- PCOUNT --&gt;

&lt;p&gt;Google has introduced &lt;a href="http://golang.org/doc/go_faq.html"&gt;Go&lt;/a&gt;.  Normally, the announcement of a new language isn't likely to get me to even click through to read about it - what do I need a new language for?  Can't I get myself screwed up enough with the languages I already know?&lt;/p&gt;
&lt;p&gt;Well, the names on the Go design team rung a few bells: Robert Griesemer, Rob Pike, Ken Thompson, Ian Taylor, Russ Cox, Jini Kim and Adam Langley.  Yes, THAT Rob Pike, THAT Ken Thompson.&lt;/p&gt;

&lt;p&gt;And, what the heck, Google does interesting stuff, so I thought I'd take a look and...  well, Go is interesting.  There's actually a lot to like.&lt;/p&gt;
&lt;p&gt;The first thing I noticed as I worked through the sample code was grouping.  In most languages you might do something like this to declare variables and constants:&lt;/p&gt;
&lt;pre&gt;

$counter=0;
$pi=3.1415926;
$Space = " ";
$Newline	= "\n";
&lt;/pre&gt;
&lt;p&gt;With Go, you can group related items:&lt;/p&gt;

&lt;pre&gt;

const (
	Space	= " ";
	Newline	= "\n";
)

var (
	countLock	sync.Mutex;
	inputCount	uint32;
	outputCount	uint32;
	errorCount	uint32;
)
&lt;/pre&gt;

&lt;p&gt;This isn't a big deal, but it helps make intentions clear, and it does save a little typing.&lt;/p&gt;
&lt;p&gt;Go has other tricks to save typing.  When you initialize a variable, the compiler works like Perl - it takes the clue from the value you provided.  So, while you could say&lt;/p&gt;
&lt;pre&gt;
var s string = "";
&lt;/pre&gt;
&lt;p&gt;, you can shorten that to&lt;/p&gt;
&lt;pre&gt;
var s  = "";
&lt;/pre&gt;
&lt;p&gt;I like that you can also do&lt;/p&gt;
&lt;pre&gt;
 s := "";
&lt;/pre&gt;
&lt;p&gt;because that's the same convention used in loops:&lt;/p&gt;
&lt;pre&gt;
 for i := 0;  &amp;lt; flag.NArg(); i++ {
&lt;/pre&gt;
&lt;p&gt;Not a big deal, but it makes sense, so it will be easy to remember, and it also stands out - you KNOW that := is initialization, wherever you see it.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Formatting&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;Formatting is something i always have trouble with.   I'm just not disciplined enough to be consistent. I'm hardly alone - there have been many "pretty print" programs for C and other languages.  Go introduces its own "gofmt" program.   Unlike general purpose code beautifiers, gofmt knows about Go and won't even touch something it doesn't see as legitimate.  Google says:&lt;/p&gt;
&lt;div style="margin-left:25px"&gt;
&lt;p&gt;
Formatting issues are the most contentious but the least consequential. People can adapt to different formatting styles but it's better if they don't have to, and less time is devoted to the topic if everyone adheres to the same style. The problem is how to approach this Utopia without a long prescriptive style guide.&lt;/p&gt;

&lt;p&gt;With Go we take an unusual approach and let the machine take care of most formatting issues. A program, gofmt, reads a Go program and emits the source in a standard style of indentation and vertical alignment, retaining and if necessary reformatting comments. If you want to know how to handle some new layout situation, run gofmt; if the answer doesn't seem right, fix the program (or file a bug), don't work around it.&lt;/p&gt;

&lt;p&gt;As an example, there's no need to spend time lining up the comments on the fields of a structure. Gofmt will do that for you. Given the declaration&lt;/p&gt;
&lt;pre&gt;
type T struct {
    name string; // name of the object
    value int; // its value
}
&lt;/pre&gt;

&lt;p&gt;gofmt will line up the columns:&lt;/p&gt;
&lt;pre&gt;
type T struct {
    name    string; // name of the object
    value   int;    // its value
}
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Ok, small details, but still, that is nice. Remember, the point isn't that 
a particular beautifier does this or that, it's that gofmt specifically 
understands Go code.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Function return values&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;Again, this is no big deal because no matter what the language there's a workaround, but Go directly supports multiple return values.  No arrays, no pointers to structures, just: &lt;/p&gt;
&lt;pre&gt;
return x, i;
&lt;/pre&gt;
&lt;p&gt;It's obvious, unhidden, far less confusing.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Slices, Maps, comma ok&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;Go doesn't do pointers.  Instead, you pull slices, much like array slices in Perl. So, buffer[10,50] is 50 bytes (or is it 40?)  from buffer, starting at its 10th byte.&lt;/p&gt;
&lt;p&gt;Maps are like associative arrays:&lt;/p&gt;
&lt;pre&gt;
var weekday = map[string] int {
	"Sun":  0,
	"Mon":  1,
	"Tue":  2,
	"Wed":  3,
	"Thu":  4,
	"Fri":  5,
	"Sat":  6,
}
&lt;/pre&gt;

&lt;p&gt;Ordinarily, you'd expect an uninitialized reference to cause some problem or return a null value, and that's true for Go - if you reference  weekday["FOO"], Go crashes.  But, not if you do it this way:&lt;/p&gt;
&lt;pre&gt;

day, ok = weekday[which]
&lt;/pre&gt;
&lt;p&gt;With that syntax, ok is set to boolean "true" if "which" is valid and false otherwise.  Easy, right?&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Much more&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;The designers really do seem to have thought things through well.  There's much, much more at the link I gave above.  I don't think I'll use Go for anything real, but it's fun to see the ideas.&lt;/p&gt;
&lt;p&gt;See &lt;a href="http://scienceblogs.com/goodmath/2009/11/googles_new_language_go.php?utm_source=nytwidget"&gt;Google's New Language: Go&lt;/a&gt; also.&lt;/p&gt;




&lt;p&gt;Comments: &lt;a href="http://aplawrence.com/cgi-bin/newcomm.pl?commenting=/Unixart/google-go.html"&gt;Click Here.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;br /&gt;&lt;i&gt;&lt;b&gt;Many of the products and books I review are things I purchased for my own use.  Some were given to me specifically for the purpose of   reviewing them.&lt;/b&gt;&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;&lt;i&gt;&lt;b&gt;I resell or can earn commissions from the sale of some of these items.  Links within these pages may be affiliate links that pay me for referring you 
to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain.  If you have any question, please do feel free to contact me.&lt;/b&gt;&lt;/i&gt;&lt;/p&gt;
&lt;div style="font-size:80%"&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td&gt; - &lt;/td&gt;
&lt;td&gt;&lt;a href="http://aplawrence.com/Tests"&gt;Skills Tests&lt;/a&gt;&lt;/td&gt;
&lt;td&gt; - &lt;/td&gt;
&lt;td&gt;&lt;a href="http://aplawrence.com/psst.html"&gt;Psst - wanna work for yourself?&lt;/a&gt;&lt;/td&gt;
&lt;td&gt; - &lt;/td&gt;&lt;td&gt;&lt;a href="http://aplawrence.com/troubleshootingbook.html"&gt;Unix/Linux Troubleshooting e-book&lt;/a&gt;&lt;/td&gt;
&lt;td&gt; - &lt;/td&gt;
&lt;td&gt;&lt;a href="http://aplawrence.com/Kerio"&gt;Kerio Mail Server&lt;/a&gt;&lt;/td&gt;
&lt;td&gt; - &lt;/td&gt;
&lt;td&gt;&lt;a href="http://aplawrence.com/rates.html"&gt;Consulting&lt;/a&gt;&lt;/td&gt;
&lt;td&gt; - &lt;/td&gt;
&lt;td&gt;&lt;a href="http://aplawrence.com/advert.html"&gt;Advertise Here&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/VScfSK83xFNtPjM6LG_0FeILuZA/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/VScfSK83xFNtPjM6LG_0FeILuZA/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/VScfSK83xFNtPjM6LG_0FeILuZA/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/VScfSK83xFNtPjM6LG_0FeILuZA/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/aplawrence/ZPYH?a=t4cKlllP4Bc:tkkVBm146QA:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/aplawrence/ZPYH?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/aplawrence/ZPYH/~4/t4cKlllP4Bc" height="1" width="1"/&gt;</description>
<link>http://feedproxy.google.com/~r/aplawrence/ZPYH/~3/t4cKlllP4Bc/google-go.html</link>
<feedburner:origLink>http://aplawrence.com/Unixart/google-go.html</feedburner:origLink></item>
<item rdf:about="http://aplawrence.com/Unixart/network-fishing.html">
<title>Fishing for an unknown device  </title>
<description>Linux,MacOSX,Networking,Perl 

2009/11/10&lt;br /&gt;
&lt;!-- LEFTADOK --&gt;
&lt;!-- PCOUNT --&gt;
&lt;!-- PCOUNT --&gt;

&lt;p&gt;A customer bought a Linksys print server.   It comes with a Windows CD that is supposed to allow you to configure the box, but with his Windows Vista machines, the print server couldn't be found.  Probably the software doesn't  work well with Vista. &lt;/p&gt;
&lt;p&gt; More aggravatingly, I couldn't find a MAC address printed anywhere on the device, so I couldn't set an IP with arp -s (which then would have let me finish configuring the device using a browser).&lt;/p&gt;
&lt;p&gt;&lt;i&gt;Yes, someone pointed out how to get it to spit out a configuration page.  This post really isn't about the Linksys, so read on.&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;What to do?   &lt;/p&gt;
&lt;p&gt;If you have a DHCP server anywhere in the network, the device will have obtained an IP address.  The DHCP server should be able to show you addresses it has passed out.  The only problem is recognizing it - if the server doesn't bother to show you when the DHCP lease was acquired, it may not be easy to spot the new addition.&lt;/p&gt;
&lt;p&gt;That was my problem - too many leases and without the MAC address (and too many Linksys devices scattered about to start with), I couldn't spot it.  Well, that's not entirely true:  I probably could have, but I was also pressed for time:  this was Boston job and it was getting later in the day and the last thing i want to do is be in Expressway traffic much after 2:00 PM.&lt;/p&gt;
&lt;p&gt;So.. . I threw the Linksys in my car and drove home, avoiding rush hour by a comfortable margin.&lt;/p&gt;
&lt;p&gt;Back home, I  hooked up the print server to my network and was able to quickly spot it in the router's DHCP list.  I typed that IP into a browser and now had access to the print server admin screens.   That's great, but the customer's network is 192.168.24.0 and mine is 192.168.113.0.    Simple enough to change that - I knew an available IP on their network, so I typed it in.   Of course, immediately after 
doing so, I no longer had access to the print server, right?&lt;/p&gt;
&lt;p&gt;Well, no.  All I need to do is temporarily change my machine to use something in that range.   The ethernet cables don't care if some of the devices are using one ip scheme and some are using others (a smart switch might care, but inexpensive little things like I use in my home do not). &lt;/p&gt;
&lt;p&gt;Or  could I use an alias.  On the Mac, I'd do &lt;/p&gt;
&lt;pre&gt;
sudo ifconfig en0 alias 192.168.24.12 netmask 255.255.255.0
&lt;/pre&gt;
&lt;p&gt;For Linux, I'd do:&lt;/p&gt;
&lt;pre&gt;
ifconfig eth0:0 192.168.24.12
&lt;/pre&gt;
&lt;p&gt;(See &lt;a href="http://aplawrence.com/Linux/adding_ip_aliases.html"&gt;Multiple IP addresses on one interface
&lt;/a&gt;)&lt;/p&gt;
&lt;p&gt;But what if I didn't have a DHCP server?   The Linksys probably comes configured with some IP address (even if it is 0.0.0.0).  If I don't know the MAC, and it isn't getting an IP from DHCP, how can I find it?&lt;/p&gt;
&lt;p&gt;Ahh, that's not so easy.  You could guess at the IP range:  many devices default to 192.168.1.x or 192.168.2.x addresses; setting your machine to something in that range (or use an alias) would let you then do a discover ping (ping 192.168.1.255) or use "nmap nmap -s 192.168.4.0/24", but you 
might not find it if it isn't responding to ICMP.  Yes, "nmap" can do a UDP scan, but again - who says this device will respond?&lt;/p&gt;
&lt;p&gt;Well, nmap can test against ports you know it will respond on.  For example, that print server is going to be listening on port 80.  I could do  nmap -p 80 192.168.11.0/24 - but again, I'm assuming the ip range and must be configured to be able to access that range.You can't use nmap to discover devices on networks your machine can't talk to.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Forget about the printserver - how can we find any unknown device?&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;I'm not aware of any generic layer 2 discovery software (just because I'm not aware of it doesn't mean it doesn't exist!), but you can use tcpdump.  The problem is filtering out all the unrelated traffic.  For example, I changed a spare Windows laptop to use 
172.16.48.9 - that's outside of my normal network.   In a few seconds, a "sudo tcpdump | grep 172.16" started showing activity:&lt;/p&gt;
&lt;pre&gt;
11:31:05.578203 IP 172.16.48.9 &gt; igmp.mcast.net: igmp v3 report, 1 group record(s)
11:31:05.579545 ARP, Request who-has 172.16.48.9 tell 172.16.48.9, length 46
11:31:05.883441 ARP, Request who-has 172.16.48.9 tell 172.16.48.9, length 46
11:31:06.517325 IP 172.16.48.9 &gt; igmp.mcast.net: igmp v3 report, 1 group record(s)
&lt;/pre&gt;
&lt;p&gt;But that was only easy to find because I knew I was looking for 172.16. &lt;/p&gt;
&lt;p&gt;I could do "sudo tcpdump -n  |grep -v 192.168" to cut down a lot of the noise - but if the device I want is in that range, I won't see it, so I have to be careful about what I exclude.  Also, this depends upon the device being noisy - though at a power cycle almost any network device has to make SOME network noise.&lt;/p&gt;
&lt;p&gt;A better way might be to use a Perl or Awk script that would sample tcpdump and extract unique IP addresses.  That's not hard:&lt;/p&gt;
&lt;pre&gt;
#!/usr/bin/perl
while (&amp;lt;&amp;gt;) {
 @stuff=split /\s+/;
 $ip=sprintf("%d.%d.%d.%d",split /\./,$stuff[2]) if $stuff[1] == "IP";
 $ip2=sprintf("%d.%d.%d.%d",split /\./,$stuff[4]) if $stuff[1] == "IP";

 if (not $stored{"$ip &gt; $ip2"}) {
   print "$ip &gt; $ip2 seen\n";
   $stored{"$ip &gt; $ip2"}=1;
 }
 
}
&lt;/pre&gt;
&lt;p&gt;I changed the Windows box to 172.16.13.98 and very quickly saw:&lt;/p&gt;
&lt;pre&gt;
192.168.113.2 &gt; 64.226.42.29 seen
64.226.42.29 &gt; 192.168.113.2 seen
192.168.113.2 &gt; 66.249.81.100 seen
66.249.81.100 &gt; 192.168.113.2 seen
192.168.113.2 &gt; 74.125.93.100 seen
&lt;b&gt;172.16.13.98 &gt; 224.0.0.251 seen&lt;/b&gt;
74.125.93.118 &gt; 192.168.113.2 seen
192.168.113.2 &gt; 74.125.93.118 seen
&lt;b&gt;172.16.3.98 &gt; 224.0.0.22 seen&lt;/b&gt;
&lt;b&gt;0.0.0.0 &gt; 172.16.3.98 seen&lt;/b&gt;
192.168.113.2 &gt; 66.249.80.83 seen
66.249.80.83 &gt; 192.168.113.2 seen
&lt;b&gt;172.16.3.98 &gt; 224.0.0.251 seen&lt;/b&gt;
&lt;b&gt;172.16.3.98 &gt; 239.255.255.250 seen&lt;/b&gt;
&lt;/pre&gt;
&lt;p&gt;(bolding added)&lt;/p&gt;

&lt;p&gt;Fairly easy to spot that (and eliminating 192.168 addresses would have made it even easier) - though for this, a simple &lt;b&gt; sudo tcpdump -n | grep "who-has"&lt;/b&gt; would have worked well, too.  The Perl script has the advantage of spotting any kind of activity (and just might show you activity you didn't expect!).&lt;/p&gt;
&lt;p&gt;Did I miss anything?  Do you have any tricks I forgot?  Please do comment if you do.&lt;/p&gt;

&lt;p&gt;Comments: &lt;a href="http://aplawrence.com/cgi-bin/newcomm.pl?commenting=/Unixart/network-fishing.html"&gt;Click Here.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;br /&gt;&lt;i&gt;&lt;b&gt;Many of the products and books I review are things I purchased for my own use.  Some were given to me specifically for the purpose of   reviewing them.&lt;/b&gt;&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;&lt;i&gt;&lt;b&gt;I resell or can earn commissions from the sale of some of these items.  Links within these pages may be affiliate links that pay me for referring you 
to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain.  If you have any question, please do feel free to contact me.&lt;/b&gt;&lt;/i&gt;&lt;/p&gt;
&lt;div style="font-size:80%"&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td&gt; - &lt;/td&gt;
&lt;td&gt;&lt;a href="http://aplawrence.com/Tests"&gt;Skills Tests&lt;/a&gt;&lt;/td&gt;
&lt;td&gt; - &lt;/td&gt;
&lt;td&gt;&lt;a href="http://aplawrence.com/psst.html"&gt;Psst - wanna work for yourself?&lt;/a&gt;&lt;/td&gt;
&lt;td&gt; - &lt;/td&gt;&lt;td&gt;&lt;a href="http://aplawrence.com/troubleshootingbook.html"&gt;Unix/Linux Troubleshooting e-book&lt;/a&gt;&lt;/td&gt;
&lt;td&gt; - &lt;/td&gt;
&lt;td&gt;&lt;a href="http://aplawrence.com/Kerio"&gt;Kerio Mail Server&lt;/a&gt;&lt;/td&gt;
&lt;td&gt; - &lt;/td&gt;
&lt;td&gt;&lt;a href="http://aplawrence.com/rates.html"&gt;Consulting&lt;/a&gt;&lt;/td&gt;
&lt;td&gt; - &lt;/td&gt;
&lt;td&gt;&lt;a href="http://aplawrence.com/advert.html"&gt;Advertise Here&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/08temNKbKKOZhPsg4Y_tiKeij3g/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/08temNKbKKOZhPsg4Y_tiKeij3g/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/08temNKbKKOZhPsg4Y_tiKeij3g/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/08temNKbKKOZhPsg4Y_tiKeij3g/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/aplawrence/ZPYH?a=DAZ7gxY8LD4:fiU5kw8qH_8:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/aplawrence/ZPYH?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/aplawrence/ZPYH/~4/DAZ7gxY8LD4" height="1" width="1"/&gt;</description>
<link>http://feedproxy.google.com/~r/aplawrence/ZPYH/~3/DAZ7gxY8LD4/network-fishing.html</link>
<feedburner:origLink>http://aplawrence.com/Unixart/network-fishing.html</feedburner:origLink></item>
<item rdf:about="http://aplawrence.com/Unixart/awk-vs.perl.html">
<title>Awk vs. Perl  </title>
<description>Linux,MacOSX,Shell,Perl 

2009/11/09&lt;br /&gt;
&lt;!-- LEFTADOK --&gt;
&lt;!-- PCOUNT --&gt;
&lt;!-- PCOUNT --&gt;

&lt;p&gt;At any Linux/Unix forum a large number of posts have to do with sed and awk - how do I do this, how do I do that?&lt;/p&gt;
&lt;p&gt;I can see using sed.   It's quick, it's simple  (unless we are doing something complicated) and easy to learn.   On the other hand, we have "awk", which is nasty and error prone even in its most basic invocations.&lt;/p&gt;
&lt;p&gt;&lt;i&gt;That's just my opinion, of course.&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;Sure, I used to use awk.   When I used it, you weren't likely to find Perl on 
most Unix systems, so for a lot of text mangling, awk was at least easier than writing in C or anything else.  It did the job, and you'd get used to its quirks.&lt;/p&gt;
&lt;p&gt;As Perl became ubiquitous, I thought of  awk like something sticky you'd find under your car seat.   Whatever use that thing may have had in the past, it's heading for the trash now.   Why on earth would I suffer with awk's limitations and difficult synatx when I have Perl?&lt;/p&gt;
&lt;p&gt;For me, awk synatx always seemed, well, awkward.  Perl immediately 
made sense to me.  In a way, that's scary, because it could mean that my mind works like Larry Wall's mind, and if that wouldn't cause you to check in with a psychiatrist, I don't know what would.  &lt;/p&gt;
&lt;p&gt;I'm hardly alone in that opinion. Many of those forum questions end up 
being answwered by a Perl script.  To me, the Perl solution always seems 
easier to read and understand (that may just be my screwy mind, again).&lt;/p&gt;
&lt;p&gt;Yet the forum questions persist.  Some of it is homework:  you can often tell when the petitioner includes such damning information as "I have to use awk.  Can't use Perl" or forgets to delete instructions like "Show your work" when cutting and pasting.  But it's not all homework: apparently a large number of people still use awk.&lt;/p&gt;
&lt;p&gt;I went looking for why and found this: &lt;a href="http://www.softpanorama.org/Tools/awk.shtml"&gt;AWK Programming
&lt;/a&gt;.  Some of the arguments made there in favor of awk include:&lt;/p&gt;
&lt;div style="font-style:italic"&gt;
&lt;ul&gt;
		&lt;li&gt;awk is simpler (especially important if deciding which to learn 
		first) &lt;/li&gt;

		&lt;li&gt;awk syntax is far more regular (another advantage for the beginner, 
		even without considering syntax-highlighting editors) &lt;/li&gt;
		&lt;li&gt;you may already know awk well enough for the task at hand
		&lt;/li&gt;
		&lt;li&gt;you may have only awk installed &lt;/li&gt;
		&lt;li&gt;awk can be smaller, thus much quicker to execute for small programs
		&lt;/li&gt;
		&lt;li&gt;awk variables don&amp;#39;t have `$&amp;#39; in front of them :-) &lt;/li&gt;

		&lt;li&gt;clear perl code is better than unclear awk code; but NOTHING 
		comes close to unclear perl code&lt;/li&gt;
	&lt;/ul&gt;
&lt;/div&gt;
&lt;p&gt;I'm not entirely in agreement - I don't think awk is "simpler" or has better syntax, but I can see that you could argue that.  But even that page admits that "Generally Perl might be better for really complex tasks".  I'd argue that awk is clumsy at complex tasks, but I definitely have to agree with that last comment about "unclear" code.&lt;/p&gt;
&lt;p&gt;Probably many of the readers here used awk before discovering Perl.  Did  Perl win you over or do you still find yourself typing "awk" frequently?  If you haven't used Perl, is it the learning curve?  Or just that you can do whatever you need with the tools you already have?&lt;/p&gt;





&lt;p&gt;Comments: &lt;a href="http://aplawrence.com/cgi-bin/newcomm.pl?commenting=/Unixart/awk-vs.perl.html"&gt;Click Here.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;br /&gt;&lt;i&gt;&lt;b&gt;Many of the products and books I review are things I purchased for my own use.  Some were given to me specifically for the purpose of   reviewing them.&lt;/b&gt;&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;&lt;i&gt;&lt;b&gt;I resell or can earn commissions from the sale of some of these items.  Links within these pages may be affiliate links that pay me for referring you 
to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain.  If you have any question, please do feel free to contact me.&lt;/b&gt;&lt;/i&gt;&lt;/p&gt;
&lt;div style="font-size:80%"&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td&gt; - &lt;/td&gt;
&lt;td&gt;&lt;a href="http://aplawrence.com/Tests"&gt;Skills Tests&lt;/a&gt;&lt;/td&gt;
&lt;td&gt; - &lt;/td&gt;
&lt;td&gt;&lt;a href="http://aplawrence.com/psst.html"&gt;Psst - wanna work for yourself?&lt;/a&gt;&lt;/td&gt;
&lt;td&gt; - &lt;/td&gt;&lt;td&gt;&lt;a href="http://aplawrence.com/troubleshootingbook.html"&gt;Unix/Linux Troubleshooting e-book&lt;/a&gt;&lt;/td&gt;
&lt;td&gt; - &lt;/td&gt;
&lt;td&gt;&lt;a href="http://aplawrence.com/Kerio"&gt;Kerio Mail Server&lt;/a&gt;&lt;/td&gt;
&lt;td&gt; - &lt;/td&gt;
&lt;td&gt;&lt;a href="http://aplawrence.com/rates.html"&gt;Consulting&lt;/a&gt;&lt;/td&gt;
&lt;td&gt; - &lt;/td&gt;
&lt;td&gt;&lt;a href="http://aplawrence.com/advert.html"&gt;Advertise Here&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Vbr_M138pO1CUQuKyvgjB4NB_VI/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Vbr_M138pO1CUQuKyvgjB4NB_VI/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Vbr_M138pO1CUQuKyvgjB4NB_VI/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Vbr_M138pO1CUQuKyvgjB4NB_VI/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/aplawrence/ZPYH?a=XE9yGKQqdzI:YbGBMGfK9NM:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/aplawrence/ZPYH?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/aplawrence/ZPYH/~4/XE9yGKQqdzI" height="1" width="1"/&gt;</description>
<link>http://feedproxy.google.com/~r/aplawrence/ZPYH/~3/XE9yGKQqdzI/awk-vs.perl.html</link>
<feedburner:origLink>http://aplawrence.com/Unixart/awk-vs.perl.html</feedburner:origLink></item>
<item rdf:about="http://aplawrence.com/Linux/setting-colors.html">
<title>Using color in shell scripts (Linux, Mac OS  X)  </title>
<description>Linux,MacOSX,Shell,Basics 

2009/11/08&lt;br /&gt;
&lt;!-- LEFTADOK --&gt;
&lt;!-- PCOUNT --&gt;
&lt;!-- PCOUNT --&gt;

&lt;p&gt;Let's jazz up some Bash scripts today, shall we?&lt;/p&gt;
&lt;p&gt;This post was prompted by a forum posting at another site where someone had a script that echoed "Pass' or "Fail"  and he wanted "Pass" in green and "Fail" in Red.&lt;/p&gt;
&lt;p&gt;By the way, I don't recommend this.&lt;/p&gt;
&lt;p&gt;Color is tricky. Displays can be bad at it, people can be color blind... using colors can make text hard to read - I don't like using color in scripts.  But, if you insist...&lt;/p&gt;
&lt;p&gt;The basic tool for terminal handling is "tput".     Put this in a shell script and run it:&lt;/p&gt;
&lt;p&gt;&lt;i&gt;For Linux, start up an Xterm or switch to a text console (CTRL-ALT-F1).  For Mac OS X, run the Terminal application.  You can put these commands in a shell script or just type them.&lt;/i&gt;&lt;/p&gt;

&lt;pre&gt;
tput setaf 0;tput setab 7;
echo "`tput setaf 1` FAIL `tput setaf 7`"
echo "`tput setaf 2` PASS `tput setaf 7`"
tput op
&lt;/pre&gt;
&lt;p&gt;Assuming your terminal session can do color,  that should have put "FAIL" in red on a white or gray background, "PASS" in green below it and then returned your terminal to its original settings - that is, if you began with a black background and white text, the "tput op" should return you to that, if you had a white background and blue text, you'll be back to that.   If for some reason you had a black background with red text, then this didn't change much, did it?&lt;/p&gt;
&lt;p&gt;On my screen, both the red and the green are a bit hard to read.  I can jazz that up a bit by adding the sequences to start and stop "bold":&lt;/p&gt;
&lt;pre&gt;
echo "`tput setaf 1;tput smso` FAIL `tput rmso;tput setaf 7`"
&lt;/pre&gt;
&lt;p&gt;But it's still not great.   If you are tempted to use color in your scripts, I'd suggest doing something like this:&lt;/p&gt;
&lt;pre&gt;
echo "`tput setaf 1` *** `tput op;tput smso`FAIL`tput rmso;
       tput setaf 1` *** `tput op`"
&lt;/pre&gt;
&lt;p&gt;And honestly I'd rather leave out the bolding.&lt;/p&gt;
&lt;p&gt;You can do much more with tput:&lt;/p&gt;
&lt;p&gt;&lt;i&gt;This one needs to be in a shell script.  If you don't know how to create a shell script, see &lt;a href="http://aplawrence.com/Basics/scripting.html"&gt;Scripting - how to write a shell script&lt;/a&gt;.   &lt;/i&gt;&lt;/p&gt;
&lt;pre&gt;
echo "hello"
echo "Input please"
tput up
tput up
tput nd
tput nd
tput nd
tput nd
tput nd
tput nd
read akey
&lt;/pre&gt;
&lt;p&gt;You'll see the script waiting for input right next to the "hello".  It does that because 
"tput up" goes up one line, and "tput nd" is a non-destructive backspace.  You can even be explicit:&lt;/p&gt;
&lt;pre&gt;
tput cup 10 50;echo "testing 1 2 3"
&lt;/pre&gt;
&lt;p&gt;puts the output at column 50 of line 10. You might want to do "clear" before running that.&lt;/p&gt;
&lt;p&gt;To learn even more about what "tput" can do, see "man terminfo" or "info terminfo" (and if you dislike "info", try "&lt;a href="http://aplawrence.com/Basics/pinfo.html"&gt;pinfo&lt;/a&gt;").  To understand more about terminfo and its cousin "termcap", see &lt;a href="http://aplawrence.com/Unixart/termcap.html"&gt;Termcap and Terminfo
&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;If you dislike Linux colorization (I do!), see &lt;a href="http://aplawrence.com/Forum/TonyLawrence10.html"&gt;Controlling Linux colors in vi (vim)&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;Comments: &lt;a href="http://aplawrence.com/cgi-bin/newcomm.pl?commenting=/Linux/setting-colors.html"&gt;Click Here.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;br /&gt;&lt;i&gt;&lt;b&gt;Many of the products and books I review are things I purchased for my own use.  Some were given to me specifically for the purpose of   reviewing them.&lt;/b&gt;&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;&lt;i&gt;&lt;b&gt;I resell or can earn commissions from the sale of some of these items.  Links within these pages may be affiliate links that pay me for referring you 
to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain.  If you have any question, please do feel free to contact me.&lt;/b&gt;&lt;/i&gt;&lt;/p&gt;
&lt;div style="font-size:80%"&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td&gt; - &lt;/td&gt;
&lt;td&gt;&lt;a href="http://aplawrence.com/Tests"&gt;Skills Tests&lt;/a&gt;&lt;/td&gt;
&lt;td&gt; - &lt;/td&gt;
&lt;td&gt;&lt;a href="http://aplawrence.com/psst.html"&gt;Psst - wanna work for yourself?&lt;/a&gt;&lt;/td&gt;
&lt;td&gt; - &lt;/td&gt;&lt;td&gt;&lt;a href="http://aplawrence.com/troubleshootingbook.html"&gt;Unix/Linux Troubleshooting e-book&lt;/a&gt;&lt;/td&gt;
&lt;td&gt; - &lt;/td&gt;
&lt;td&gt;&lt;a href="http://aplawrence.com/Kerio"&gt;Kerio Mail Server&lt;/a&gt;&lt;/td&gt;
&lt;td&gt; - &lt;/td&gt;
&lt;td&gt;&lt;a href="http://aplawrence.com/rates.html"&gt;Consulting&lt;/a&gt;&lt;/td&gt;
&lt;td&gt; - &lt;/td&gt;
&lt;td&gt;&lt;a href="http://aplawrence.com/advert.html"&gt;Advertise Here&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Rycnzl5q7prTdOkqFfdANbWDtCM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Rycnzl5q7prTdOkqFfdANbWDtCM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Rycnzl5q7prTdOkqFfdANbWDtCM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Rycnzl5q7prTdOkqFfdANbWDtCM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/aplawrence/ZPYH?a=It8Mx8C7CFU:IxS4rXXHFeA:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/aplawrence/ZPYH?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/aplawrence/ZPYH/~4/It8Mx8C7CFU" height="1" width="1"/&gt;</description>
<link>http://feedproxy.google.com/~r/aplawrence/ZPYH/~3/It8Mx8C7CFU/setting-colors.html</link>
<feedburner:origLink>http://aplawrence.com/Linux/setting-colors.html</feedburner:origLink></item>
<item rdf:about="http://aplawrence.com/Linux/strange-hack.html">
<title>A strangely compromised Linux box  </title>
<description>Linux,Security 

2009/11/05&lt;br /&gt;
&lt;!-- LEFTADOK --&gt;
&lt;!-- PCOUNT --&gt;
&lt;!-- PCOUNT --&gt;

&lt;p&gt;A customer reported that a Linux machine used for ssh access (to in turn give telnet access to an ancient SCO machine) was refusing logins.   I asked him to try logging in as root at the console; he was unable to do so.&lt;/p&gt;
&lt;p&gt;When I arrived on site, I found that I could not login as he had said.  I rebooted to single use mode and started peeking around.  The machine had been hacked; there was little doubt about that.  It's HOW it was hacked that bothers me,&lt;/p&gt;
&lt;p&gt;First, there was no attempt to hide any evidence.   I could see in wtmp and the secure logs that someone  had logged in from a German ISP address, attained su status, and created a new su user for himself.    He then changed root's password.&lt;/p&gt;
&lt;p&gt;Fine so far, right?  But then he did something very strange.  He hand edited /etc/passwd and added "/nologin" at the end of each line except root and his own.  This was what was preventing people from logging in.&lt;/p&gt;
&lt;p&gt;Why do that?&lt;/p&gt;
&lt;p&gt;My first thought was that this was just a disgruntled employee doing minor mischief.  But when I went multi-user and started checking more, I found this:&lt;/p&gt;
&lt;pre&gt;
COMMAND  PID USER   FD   TYPE DEVICE SIZE NODE NAME
3       2614 root    3u  IPv4   8033       TCP *:ircd (LISTEN)
&lt;/pre&gt;
&lt;p&gt;That looks like the machine has been put into a botnet.   I ran rkhunter but didn't find anything else unusual.&lt;/p&gt;
&lt;p&gt;This is very odd.  If you want the machine for a botnet, why disable the user logins, which only serves to immediately call attention to the machine? &lt;/p&gt;
&lt;p&gt;Another oddity:  this same issue happened several months earlier.  That is, users could not login and the root password was changed.  That time, the user access came back before I could get there and I had them boot to single user mode to change the root password.   I wish I knew if an irc daemon was running then, but I attributed all of that to user error or a router glitch.&lt;/p&gt;
&lt;p&gt;Could it be just an inept hacker?  A "kiddie script" that disables logins?  But why undo its work?  And why redo it now?&lt;/p&gt;
&lt;p&gt;And he DID redo it.  The time stamps are plain: he did all this just days 
ago. It makes no sense.&lt;/p&gt;
&lt;p&gt;I suspect that this person got in because someone's home machine is already part of the botnet.   I don't know how he attained escalated permission, but once you have physical access, all bets are off.  We'll have to reinstall the machine, but if I can't identify the source, what's the point?&lt;/p&gt;
&lt;p&gt;I don't know.  I'm really not sure what to do.   For the moment, I've locked down ssh so that only I can get on - I want to see if he does have another back door.  But I'm also concerned about other machines in the network - any of these could be compromised also.   So where do we go from here?  I don't want to put this customer to a lot of expense for nothing, but the whole situation is disquieting.&lt;/p&gt;
&lt;p&gt;It does offer a lesson though:  when something odd like that happens, we 
should take the time to look more deeply.  If I had spotted that ircd months 
ago, I'd have... what?  I don't know.  But still, I should have looked deeper then.&lt;/p&gt;


&lt;p&gt;Comments: &lt;a href="http://aplawrence.com/cgi-bin/newcomm.pl?commenting=/Linux/strange-hack.html"&gt;Click Here.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;br /&gt;&lt;i&gt;&lt;b&gt;Many of the products and books I review are things I purchased for my own use.  Some were given to me specifically for the purpose of   reviewing them.&lt;/b&gt;&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;&lt;i&gt;&lt;b&gt;I resell or can earn commissions from the sale of some of these items.  Links within these pages may be affiliate links that pay me for referring you 
to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain.  If you have any question, please do feel free to contact me.&lt;/b&gt;&lt;/i&gt;&lt;/p&gt;
&lt;div style="font-size:80%"&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td&gt; - &lt;/td&gt;
&lt;td&gt;&lt;a href="http://aplawrence.com/Tests"&gt;Skills Tests&lt;/a&gt;&lt;/td&gt;
&lt;td&gt; - &lt;/td&gt;
&lt;td&gt;&lt;a href="http://aplawrence.com/psst.html"&gt;Psst - wanna work for yourself?&lt;/a&gt;&lt;/td&gt;
&lt;td&gt; - &lt;/td&gt;&lt;td&gt;&lt;a href="http://aplawrence.com/troubleshootingbook.html"&gt;Unix/Linux Troubleshooting e-book&lt;/a&gt;&lt;/td&gt;
&lt;td&gt; - &lt;/td&gt;
&lt;td&gt;&lt;a href="http://aplawrence.com/Kerio"&gt;Kerio Mail Server&lt;/a&gt;&lt;/td&gt;
&lt;td&gt; - &lt;/td&gt;
&lt;td&gt;&lt;a href="http://aplawrence.com/rates.html"&gt;Consulting&lt;/a&gt;&lt;/td&gt;
&lt;td&gt; - &lt;/td&gt;
&lt;td&gt;&lt;a href="http://aplawrence.com/advert.html"&gt;Advertise Here&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/SCKpa-pmN7kVcZoOryR-bP_RKvw/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/SCKpa-pmN7kVcZoOryR-bP_RKvw/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/SCKpa-pmN7kVcZoOryR-bP_RKvw/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/SCKpa-pmN7kVcZoOryR-bP_RKvw/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/aplawrence/ZPYH?a=EZioqq6dzr8:w-M2dlzTX60:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/aplawrence/ZPYH?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/aplawrence/ZPYH/~4/EZioqq6dzr8" height="1" width="1"/&gt;</description>
<link>http://feedproxy.google.com/~r/aplawrence/ZPYH/~3/EZioqq6dzr8/strange-hack.html</link>
<feedburner:origLink>http://aplawrence.com/Linux/strange-hack.html</feedburner:origLink></item>
<item rdf:about="http://aplawrence.com/Linux/samba-pigs.html">
<title>When Samba Pigs Fly  </title>
<description>Troubleshooting,Linux,Samba 

2009/11/04&lt;br /&gt;
&lt;!-- LEFTADOK --&gt;
&lt;!-- PCOUNT --&gt;
&lt;!-- PCOUNT --&gt;

&lt;p&gt;Yesterday a customer called because he needed to be able to write into a certain share on his Samba server.  I ssh'd right in, made the change to the config file, restarted Samba  and shot him off an "All set!" email.&lt;/p&gt;
&lt;p&gt;Such confidence had I that immediately after hitting send, I left my house to do some errands and when I realized I had forgotten my phone, I didn't even bother to go back for it:  everything is under control, all pigs are fed and ready to fly.&lt;/p&gt;
&lt;p&gt;Yeah.  When I got home, I found both phone and email messages from my customer.  Such a nice guy he is - he was APOLOGIZING to me because it didn't work. "Maybe I'm doing something wrong?", he asked.&lt;/p&gt;
&lt;p&gt;I ssh'ed in again and saw my "mistake".  I had written "writeable" rather than "writable" in the config file.   I quickly fixed that, restarted Samba, snapped off another email explaining my error and took a break for lunch.&lt;/p&gt;
&lt;p&gt;Unfortunately the pigs seemed to still be having a little trouble with the flying stuff.  I had barely bitten into my sandwich before he called again.  Permission denied.  Can't do it.  Was he doing something wrong?, he  begged to know?  Of course not, I assured him.  The damn pigs were just being stubborn.&lt;/p&gt;
&lt;p&gt;I double checked.  Yes, he had write permission in the directory.   What the heck?   Here's part of the config file for your amusement:&lt;/p&gt;

 &lt;pre&gt;
[homes]
	comment = Home Directories
	read only = No
	browseable = No

[printers]
	comment = All Printers
	path = /var/spool/samba
	printable = Yes
	browseable = No


[Syn75]
	comment = syn75
	path = /usr/syn75
	browseable = yes
            read only= Yes

[CPONLINE]
	comment = cponline
	path = /usr/syn75/00/CPONLINE
	browseable = yes
	writable = Yes 
&lt;/pre&gt;
&lt;p&gt;Those pigs have wings, dammit!   So exactly what happens, I asked?&lt;/p&gt;
&lt;p&gt;"I choose Save As.  I navigate down to CPONLINE..."&lt;/p&gt;
&lt;p&gt;Ooops.  Magic word.  He said "Down", didn't he?  The pigs all perked up and started tentatively fluttering their wings.  I asked the $64,000 question: "Are you going through the Syn75 share or the CPONLINE share?"&lt;/p&gt;
&lt;p&gt;NO, he was not using CPONLINE.  He was navigating down through the Syn75 share.  THAT share has no write permission - it doesn't matter that CPONLINE is under it, that only is writable if you come to it through the CPONLINE share!  I had him map a network drive to CPONLINE and the pigs lifted off into the sky and everybody was happy.&lt;/p&gt;
&lt;p&gt;Because he's such a nice guy ("Maybe I'm doing something wrong?) and because I should have paid more attention when he asked that, I'm not even sending him a bill for any of it.&lt;/p&gt;
&lt;p&gt;Pigs:  to your stations!  Fly, you pink porkers, fly!&lt;/p&gt;




&lt;p&gt;Comments: &lt;a href="http://aplawrence.com/cgi-bin/newcomm.pl?commenting=/Linux/samba-pigs.html"&gt;Click Here.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;br /&gt;&lt;i&gt;&lt;b&gt;Many of the products and books I review are things I purchased for my own use.  Some were given to me specifically for the purpose of   reviewing them.&lt;/b&gt;&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;&lt;i&gt;&lt;b&gt;I resell or can earn commissions from the sale of some of these items.  Links within these pages may be affiliate links that pay me for referring you 
to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain.  If you have any question, please do feel free to contact me.&lt;/b&gt;&lt;/i&gt;&lt;/p&gt;
&lt;div style="font-size:80%"&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td&gt; - &lt;/td&gt;
&lt;td&gt;&lt;a href="http://aplawrence.com/Tests"&gt;Skills Tests&lt;/a&gt;&lt;/td&gt;
&lt;td&gt; - &lt;/td&gt;
&lt;td&gt;&lt;a href="http://aplawrence.com/psst.html"&gt;Psst - wanna work for yourself?&lt;/a&gt;&lt;/td&gt;
&lt;td&gt; - &lt;/td&gt;&lt;td&gt;&lt;a href="http://aplawrence.com/troubleshootingbook.html"&gt;Unix/Linux Troubleshooting e-book&lt;/a&gt;&lt;/td&gt;
&lt;td&gt; - &lt;/td&gt;
&lt;td&gt;&lt;a href="http://aplawrence.com/Kerio"&gt;Kerio Mail Server&lt;/a&gt;&lt;/td&gt;
&lt;td&gt; - &lt;/td&gt;
&lt;td&gt;&lt;a href="http://aplawrence.com/rates.html"&gt;Consulting&lt;/a&gt;&lt;/td&gt;
&lt;td&gt; - &lt;/td&gt;
&lt;td&gt;&lt;a href="http://aplawrence.com/advert.html"&gt;Advertise Here&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/DlysFtNqxYjssCzn-X6Jp2S_qgw/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/DlysFtNqxYjssCzn-X6Jp2S_qgw/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/DlysFtNqxYjssCzn-X6Jp2S_qgw/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/DlysFtNqxYjssCzn-X6Jp2S_qgw/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/aplawrence/ZPYH?a=Pb3iTlbbvNU:638prALjttU:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/aplawrence/ZPYH?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/aplawrence/ZPYH/~4/Pb3iTlbbvNU" height="1" width="1"/&gt;</description>
<link>http://feedproxy.google.com/~r/aplawrence/ZPYH/~3/Pb3iTlbbvNU/samba-pigs.html</link>
<feedburner:origLink>http://aplawrence.com/Linux/samba-pigs.html</feedburner:origLink></item>
</rdf:RDF>
