...making Linux just a little more fun!


This month's answers created by:

[ Ben Okopnik, S. Parthasarathy, Henry Grebler, Kapil Hari Paranjape, René Pfeiffer, Mulyadi Santosa, Neil Youngman ]
...and you, our readers!

Our Mailbag

FIFO usage

Dr. Parthasarathy S [drpartha at gmail.com]

Tue, 22 Jun 2010 09:09:46 +0530

I have come across this thing called FIFO named pipe. I can see how it works, but I find no place where I can put it to good use (in a shell script). Can someone give me a good application context where a shell script would need to use FIFO ? I need a good and convincing example, to be able to tell my students.

Thanks TAG,


Dr. S. Parthasarathy                    |   mailto:drpartha at gmail.com
Algologic Research & Solutions    |
78 Sancharpuri Colony                 |
Bowenpally  P.O                          |   Phone: + 91 - 40 - 2775 1650
Secunderabad 500 011 - INDIA     |
WWW-URL: http://algolog.tripod.com/nupartha.htm

[ Thread continues here (13 messages/23.98kB) ]

2-cent tip: A safer 'rm'

Henry Grebler [henrygrebler at optusnet.com.au]

Sun, 20 Jun 2010 15:45:14 +1000


[I wrote what follows nearly a month ago. Since I started working full-time-plus, I have not been able to respond as promptly as I would prefer. For many, I suspect, the subject has gone cold. Nevertheless, ...]

As often happens, I have not phrased myself well. [sigh]

I apologise for trying to respond quickly, when clearly a fuller and more considered response was indicated.

Let me try again.

As I understand it, this is the original statement of the problem:

If you've ever tried to delete Emacs backup files with

rm *~

(i.e. remove anything ending with ~), but you accidentally hit Enter before the ~ and did "rm *", ...

Silas then goes on to suggest a solution.

Perhaps I took the problem statement too literally. When I wrote cleanup.sh, it was aimed exclusively at emacs backup files. When I talked about it, I was thinking exclusively of emacs backup files. I am not aware of any other place where tildes are used.

If it's a file I've been editing with emacs, I've usually created it. So I get to choose its name.

The message I am trying to convey to TAG's broad readership is this. If you are happy with Silas's solution, that's fine. If you are happy with any of the other solutions provided, that's fine too. I myself have felt the need to deal with this problem. I offer my approach to dealing with emacs backup files for your consideration.

Part of my approach is the cleanup script; this is the technical outcome, the tangible I can offer to others.

More important is a holistic approach to the problem as originally stated. I took it to mean that certain behaviours are more risky than others. This is again in the eyes of the beholder. Some people always alias 'rm' to 'rm -i'. If they do this, they will always be prompted before deleting any file. If they specify multiple files, there will be a prompt for each file individually.

Such an approach would have saved Silas.

Again, if such an approach appeals to you, by all means adopt it.

It seems to me ill-advised to adopt a safe behaviour in one circumstance and a risky behaviour in another. The nett effect will not be as safe as your safest behaviour, but rather as risky as your riskiest behaviour. (A chain is no stronger than its weakest link.)

So, first of all, according to my philosophy, don't go creating files with dangerous characters in them. It's really not important to me to call a file 'a b' when I can just as easily call it 'a_b'. If I download a file with spaces in the filename AND I plan to edit it with emacs, it's worth renaming the file, replacing spaces with underscores (or any other innocuous character).

And I am strongly recommending this behaviour of mine to others.

If you live largely in a Linux world, you should rarely encounter filenames containing dangerous characters. If you are creating files, you can choose to avoid dangerous characters. Or not. It's up to you.

[ ... ]

[ Thread continues here (2 messages/9.65kB) ]

Face detection in Perl

Jimmy O'Regan [joregan at gmail.com]

Sun, 27 Jun 2010 18:46:50 +0100

Since I got commit access to Tesseract, I've been getting a little more interested in image recognition in general, and I was pleased to find a Java-based 'face annotation' system on Sourceforge: http://faint.sourceforge.net

The problem is, it doesn't support face detection on Linux, but it does have a relatively straightforward way of annotating the image using XMP tags. Perl to the rescue - there's a module called Image::ObjectDetect on CPAN... it's a pity the example in the POD is incorrect.

Here's a correct example that generates a simple HTML map (and nothing else :)


use warnings;
use strict;

use Image::ObjectDetect;

my $cascade = '/usr/share/opencv/haarcascades/haarcascade_frontalface_alt2.xml';
my $file = $ARGV[0];
my @faces = Image::ObjectDetect::detect_objects($cascade, $file);
my $count=1;

print "<map name='mymap'>\n";
for my $face (@faces) {
    print "  <area shape='rect' alt='map$count'
href='http://www.google.com' coords='";
    print $face->{x}, ", ";
    print $face->{y}, ", ";
    print $face->{x}+$face->{width}, ", ";
    print $face->{y}+$face->{height}, "'/>\n";
print "</map>\n";

print "<img src='$file' usemap='mymap'/>\n";

(to install Image::ObjectDetect, you first need OpenCV. On Debian, that's
apt-get install libcv-dev libcvaux-dev libhighgui-dev
cpan Image::ObjectDetect
and you're done :)

<Leftmost> jimregan, that's because deep inside you, you are evil.
<Leftmost> Also not-so-deep inside you.

[ Thread continues here (4 messages/6.48kB) ]

Testing new anti-spam system

Ben Okopnik [ben at linuxgazette.net]

Sun, 6 Jun 2010 13:31:12 -0400

From: John Hedges <john@drystone.co.uk>
To: TAG <tag@lists.linuxgazette.net>
Subject: RE: Testing new anti-spam system
Hi Ben

I've read with interest the thread on C/R antispam technique.

The gmail solution sounds promising except in one use case - where you open an account through a website. Unfortunately this often results in a confirmation email - sometimes even with a username and password - exacly the kind of information you would not want sniffed. One solution, as suggestesd by Martin Krafft (http://madduck.net/blog/2010.02.09:sign-me-up-to-social-networking/), is to use a unique receiver address, such as myname-googlesignup at mydomain.co.uk for these signups that you can whitelist in anticipation of a response, and with the advantage that you can blacklist the address in the future if it gets abused.

Please share with the list if you see fit.

I've enjoyed LG for many years, thanks.

John Hedges

Error when execute cgate_migrate_ldap.pl

Ben Okopnik [ben at linuxgazette.net]

Fri, 4 Jun 2010 08:39:06 -0400

On Fri, Jun 04, 2010 at 12:22:51PM +0800, bayu ramadhan wrote:

> dear linuxgazette,
> i've read about migrating mail server to postfix/cyrus/openldap, , ,
> i've tried u'r tutorial, , ,

Who's "u'r"? I'm pretty sure it was Rene Pfeiffer who wrote that article, not "u'r".

HINT: please use standard English, and preferably standard punctuation as well. As you already know, your English isn't of the best; please don't make it any more difficult by adding more levels of obscurity to it.

> but i've some error when execute the perl script,,
> i've attach the screenshoot of the error  and the script, , ,

Next time, please just copy and paste the error. It's plain text, so there's no need for screenshots. The error - which I've had to transcribe from your screenshot (an unnecessary waste of time) - was

Communications Error at ./cgate_migrate_ldap.pl line 175, <DATA> line 225.

Taking a look at line 175 of the script shows a pretty good possibility for where the possible problem might be:

173 -->  # Bind to servers
174 -->  $mesg = $ldap_source->bind($binddn_source, password => 'ldapbppt');
175 -->  $mesg->code && die $mesg->error;

That is, you're trying to bind to a server using the same password that Rene had used in his article. Unless you're using that password, the connection is going to fail.

* Ben Okopnik * Editor-in-Chief, Linux Gazette * http://LinuxGazette.NET *

[ Thread continues here (2 messages/3.37kB) ]

mbox selective deletion

Ben Okopnik [ben at okopnik.com]

Sun, 27 Jun 2010 14:20:44 -0400

Hi, Evaggelos -

On Sun, Jun 27, 2010 at 08:44:01PM +0300, Evaggelos Balaskas wrote:

> Hi,
> First of all let me introduce my self:
> My name is: Evaggelos Balaskas, or ebal for short, and i dont know perl!

Welcome! That's a good Alcoholics-Anonymous-style introduction. :)

> I wanted to add many subjects to my search/clear function,
> so i used a list.

Not a bad idea so far...

> while ( my $msg = $mb->next_message ) {
>   my $flag = 0;
>   my $s = $msg->header->{subject};
>   if ( !$s ) {
>     $s = "empty_subject";
>   }

If you're trying to set a default value for a variable, Perl has a nifty way to do that by using "reflexive assigment":

$s ||= "empty_subject";

This essentially says "if $s is true - i.e., contains anything - then leave it alone; otherwise, assign this value."

>   foreach (@subjects) {
> 	  if ( $s =~ $_ ) {

Although that will work, it's not a good idea: the binding operator (=~) is intended to work with the match operator (/foo/ or m/foo/), and omitting the latter makes your code fragile (i.e., since the usage is non-standard, your code could fail with a later version of Perl.) In addition to that, since $_ is the default binding for regexes, you don't need to use it explicitly; you could just write

if (/$s/){

and be done with it.

However, there's a larger problem here: you don't need to build a state machine to determine whether your messages contain one of the above subjects - you can just use 'grep', or (my preferred method) a hash lookup. I also noticed that you don't use the default value in "$s" anywhere after defining it - and if you're just throwing it away, you don't need to define it in the first place.

# Using grep
my @subjects = ("aaaaaa", "bbbbbb", "ccccc", "ddddd");
while ( my $msg = $mb->next_message ) {
	print "$msg\n" unless grep /$msg->header->{subject}/, @subjects;

Alternate method, faster lookup with less grinding:

# Using a hash lookup
my %subjects = map { $_ => 1 } ("aaaa", "bbbb", "cccc", "dddd");
while ( my $msg = $mb->next_message ) {
    print "$msg\n" unless defined $subjects{$msg->header->{subject}};

This latter version will also deal gracefully with undefined subject lines.

> PS: Plz forgive me for my bad english - not my natural language.

[smile] I'll be sure to "forgive" you - as soon as my Greek is as good as your English (which, incidentally, is excellent as far as I can see.) Again, welcome!

                       OKOPNIK CONSULTING
        Custom Computing Solutions For Your Business
Expert-led Training | Dynamic, vital websites | Custom programming
               443-250-7895    http://okopnik.com


Jimmy O'Regan [joregan at gmail.com]

Fri, 18 Jun 2010 14:48:14 +0100

A friend just sent me a Sierpi?ski triangle generator in 14 lines of C++ (http://codepad.org/tD7g8shT), my response is 11 lines of C:

#include <stdio.h>

int main() {
  int a, b;
  for (a = 0; a < 64; ++a) {
    for (b = 0; b < 64; ++b)
      printf ("%c ", ((a + b) == (a ^ b)) ? '#' : ' ');
  return 0;

...but I'm wondering if Ben has a Perl one-liner? :)

(BTW, CodePad is awesome!)

<Leftmost> jimregan, that's because deep inside you, you are evil.
<Leftmost> Also not-so-deep inside you.

[ Thread continues here (15 messages/15.96kB) ]

Knowing from what pc a certain file came

Deividson Okopnik [deivid.okop at gmail.com]

Mon, 21 Jun 2010 11:49:03 -0300

Hello TAG

I have an ubuntu linux machine here thats got a samba shared folder, writable by anyone.

Is there any way i can know from what IP a certain file came?

Cause one of the windoze machines on my network is spreading some virus, and I cant figure out what machine is that. It creates an autorun.inf and a .exe on my ubuntu shared folder, thats the reason I wanted to try to figure out where it came from.

Thanks Deividson

[ Thread continues here (4 messages/5.60kB) ]


Talkback: Discuss this article with The Answer Gang

Copyright © 2010, . Released under the Open Publication License unless otherwise noted in the body of the article. Linux Gazette is not produced, sponsored, or endorsed by its prior host, SSC, Inc.

Published in Issue 176 of Linux Gazette, July 2010