Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Good Day Monks,

I'm writing a script that checks for certain events, and sends a notification when they occur. The user can set a couple of different options as to how he receives the notification (for instance, he may choose to get his notification in the form of an email). I'd like to have one of the notification options print out a message to all consoles currently connected to the system (which, if it makes a difference, is running Red Hat 8). This would be much the same as what happens when you type "shutdown -h now"....a message informing you that the system is going down appears on all consoles. Can anyone tell me how this might be accomplished?

Thanks!

Replies are listed 'Best First'.
Re: Printing a Message to All Consoles
by Nitrox (Chaplain) on Mar 05, 2003 at 18:52 UTC
    One way to do it would be:
    #! /usr/bin/perl -w use strict; open MSG, "|/usr/bin/wall" or die "Failed to open pipe to wall"; print MSG "This is message 1.\n"; print MSG "This is message 2.\n"; close MSG;

    Also check the 'wall' man page for more info.

    -Nitrox

Re: Printing a Message to All Consoles
by insensate (Hermit) on Mar 05, 2003 at 18:53 UTC
    Read the manpage of the wall command. It should suit your needs.