Vincent Danen introduces two command-line programs, wall and mail, that allow you to send simple alerts and e-mail messages to users.
The command line is a great environment for doing many things. It can be used to schedule commands, navigate directories, chain simple commands together to create complex commands, automate system monitoring, and more. The flexibility that the command line offers makes it worth investing the time into learning more about it, as its power far exceeds that of GUI operating environments.
CLI environments, especially with multi-user systems such as servers, provide a great way to communicate between users as well. Two tools in particular are of great value: wall, which will communicate messages on all active consoles, and mail, which will send e-mail via the command-line.
Wall is an interconsole "instant messenger" and is available on all Linux and UNIX systems. With it, you can broadcast alert messages, such as an impending system reboot or other maintenance process. Using wall is simple:
$ wall "just fooling around"
Broadcast message from vdanen (pts/16) (Mon Aug 4 20:47:03 2008):
just fooling around
Any user logged into the system will see the identical notice. The only exception is when a user has set their "message" flag off. For instance, to disable seeing these wall notices, use:
$ mesg n
The mesg command takes exactly one of two arguments: y and n; if no argument is supplied, it shows the current message value.
Another useful tool is the mail command, which will send e-mail messages on the CLI. This can be used in conjunction with a command such as at to send reminder e-mails, or it can be used to send an alert when a task or command is complete. There are a few different providers of the mail command; some distributions use the mailx package, others use nail, others the original Berkely mail package. If mail doesn't work as expected, read the mail(1) manpage. Most mail commands use the same syntax for the basics, however. To send an e-mail to an SMS relay to alert you of an upcoming meeting, use:
$ echo "20 minutes to meet with Sally." | /bin/mail -s "Meeting" firstname.lastname@example.org
This will send an e-mail with the subject "Meeting" to email@example.com; the body of the message will contain, "20 minutes to meet with Sally." As has been illustrated, this can be used as a quick means of sending reminders, or it can be used to send the output of jobs when completed. The mail command takes standard input as the body of the message; other options can be used to specify CC and BCC recipients as well.
E-mail messages sent via mail are sent from the calling user on the system's hostname; for instance, if the user account joe were sending this on the system foo.bar.org, then the e-mail would be seen to come from firstname.lastname@example.org. Because of this, you may want to ensure proper message rules are in place that permit the relaying or reception of these addresses, or adjust the hostname of the computer accordingly.
Get the PDF version of this tip here.
Delivered each Tuesday, TechRepublic's free Linux and Open Source newsletter provides tips, articles, and other resources to help you hone your Linux skills. Automatically sign up today!