motd question

Joshua Oreman oremanj at
Mon Aug 25 11:02:34 PDT 2003

On Mon, Aug 25, 2003 at 12:37:44PM -0400 or thereabouts, Louis LeBlanc wrote:
> Probably not possible, but I was wondering (and have for some time,
> though I can't find any info on it either way) whether /etc/motd is
> strictly a text in/text out file, or if there is a way to get it to
> execute a command, the output of which is to be included in the text
> output?

You could make it a FIFO and put a Perl script or something at the
other end, if you want dynamically-generated output. For example:
#!/usr/bin/env perl
use constant FILE => "/etc/motd";
use POSIX qw/setsid mkfifo/;

# Comment these if you want it to run in foreground:
exit 0 if fork;

while (1) {
	unless (-p FILE) {
		unlink FILE;
		mkfifo FILE, 0644;

	my $fortune_msg;

	open FORTUNE, "/usr/bin/env fortune |" or die "Can't open pipe from fortune: $!\n";
	$fortune_msg .= $_ while <FORTUNE>;
	close FORTUNE;

	open FIFO, ">".FILE or die "Can't open ".FILE." for writing: $!\n";
	print FIFO $fortune_msg;
	close FIFO;

	sleep 2;
would generate a `fortune' message every time someone read motd. Run it like so:
# /path/to/

Note that this script will *DELETE YOUR EXISTING MOTD*... back it up first.

If you want to use this for something else, for example a .signature, change
the `use constant FILE => <<the-file-goes-here-in-quotes>>' line.

If you have two (or more) of these things running, it can produce unexpected results.
Be careful.

-- Josh

> Lou
> -- 
> Louis LeBlanc               leblanc at
> Fully Funded Hobbyist, KeySlapper Extrordinaire :)
>                     Ô¿Ô¬
> Make it right before you make it faster.
> _______________________________________________
> freebsd-questions at mailing list
> To unsubscribe, send any mail to "freebsd-questions-unsubscribe at"

More information about the freebsd-questions mailing list