l i n u x - u s e r s - g r o u p - o f - d a v i s
L U G O D
 
Next Meeting:
April 21: Google Glass
Next Installfest:
TBD
Latest News:
Mar. 18: Google Glass at LUGOD's April meeting
Page last updated:
2001 Dec 30 16:59

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] mutt question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] mutt question


  • Subject: Re: [vox-tech] mutt question
  • From: Matt Roper <MAPSmdroper@ucdavis.edu>
  • Date: Wed, 10 Jan 2001 19:45:14 -0800
  • References: 20010110112928.A9989@dirac.org

I don't use mutt, so I don't know whether it has a builtin feature to
rotate sigs, but I think you can get this type of behavior by writing a
simple perl script that uses named pipes (also known as FIFOs).  Basically
you convert your .signature file into a named pipe and then have a perl
script (or other small program) that acts as a daemon and sits in a loop
writing randomly selected signatures into .signature (re-opening and
closing the file for each signature).  When another program (e.g. mutt)
wants to get your signature, it opens .signature for reading and reads
until it hits EOF.  The reading program never even knows that .signature
isn't a regular file.  When a program (in this case the daemon) tries to
open a named pipe for writing, the operating system causes the function
call to block until there is actually another program on the other side
trying to read from the named pipe, so your daemon isn't actually spinning
around inside an infinite loop if no programs are reading your signature.

I realize that explanation isn't very well written, so here's an example
of a signature daemon (written in perl) that basically does what you want.
I just hacked out this program in a few minutes, so there may be some
minor bugs in it that need to be ironed out, but it should give you the
general idea of what I'm talking about...


#!/usr/bin/perl

use strict;

my $NAMED_PIPE = "signature_file";
my $SIG_DB = "sigs.txt";
my $SIG_DELIM = "<<SIG>>";    ### Delimiter in sig database

my @allsigs;                  ### List of all signatures
my @cursig;                   ### Lines of signature being read from DB

### Make sure the named pipe exists.  If not, set it up.
unless (-p $NAMED_PIPE) {
  system("rm $NAMED_PIPE") if -e $NAMED_PIPE;
  if (system("mkfifo $NAMED_PIPE")) {
    die "Couldn't make named pipe ($NAMED_PIPE)\n";
  }
}

### Read in possible signatures.
open(SIGDB,$SIG_DB) || die "Can't open signature database: $!\n";
while(my $line = <SIGDB>) {
  if ($line =~ /$SIG_DELIM/) {
    push(@allsigs,join("",@cursig));
    @cursig = ();
    next;
  }
  push(@cursig, $line);
}
push(@allsigs,join("",@cursig));


### Loop forever
while(1) {
  open(SIG,">signature_file") || die "Can't write to named pipe.\n";

  ### Pick a signature file somehow...
  my $sig = $allsigs[rand(scalar(@allsigs))];

  ### Send it to the named pipe
  print SIG $sig;

  ### Close the named pipe (the current program will think it has read the
  ### entire file.
  close(SIG);

  ### Prevent the next pipe we open from catching the end of the current
  ### request.
  sleep 1;

}


On Wed, 10 Jan 2001, Peter Jay Salzman wrote:

> i assume this is a mutt question.
>
> is there a way of getting rotating .sigs?
>
> pete
>


Matt

=========================
Matt Roper
mdroper@ucdavis.edu
http://www.mattrope.com
=========================



LinkedIn
LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
facebook
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
EDGE Tech Corp.
For donating some give-aways for our meetings.