We all need reminders, but without a Palm Pilot (or the soon-to-be-released Linux PDA, Yopy) or some oddball third-party application, we're pretty much stuck in a mire of forgetfulness! What's a body to do? Well, with Linux you have more options than you can imagine.
To help you remember those all-too-important luncheons, anniversaries, deadlines, and special dates, Linux offers two applications: at and mail. Using /bin/sh, the at command reads commands from standard input or a specified file to be executed at a later time and can be set up to run at any specified time. The mail command is an intelligent mail-processing system that has a command syntax reminiscent of ed, with lines replaced by messages.
The at command is a simple method (although it can take on a fairly aggressive complexion) of running programs or commands at a specified time. The syntax of at is:
at [-V] [-q queue] [-f file] [-mldcv] TIME
The above syntax includes the following possible arguments:
- at—The command itself
- -V—Prints the version number
- -q—Uses the specified queue
- -f—Reads the job from a file rather than from standard input
- -m—Sends mail to the user when the job has completed, even if there was no output
- -l—An alias for atq (It lists the user's pending jobs, unless the user is the superuser, in which case everybody's jobs are listed.)
- -d—Is an alias for atrm (It deletes jobs.)
- -c—Concatenates the jobs listed on the command line to standard output
- -v—For atq, shows completed (but not yet deleted) jobs in the queue; otherwise shows the time the job will be executed
- TIME—Shows the user-specified time for the program/command’s execution
What the above selection (from the man page) neglects to mention is that the command itself is appended after the TIME section and can be simplified by using only the following syntax:
at TIME COMMAND
In other words, let's say we want the contents of our home directory stored at 5:00 P.M. For that task, we would enter:
which will respond with:
At the > prompt, enter the command to be issued, such as:
ls /home/USER > /home/USER/listing
Note: Where USER is listed, you would enter your own username. This command creates a file, called listing, in your home directory with the contents of your home directory listed.
Once you’ve entered the command, hit [Ctrl]d and the command will be executed at the given time.
The mail command, although powerful, is an antiquated system for delivering mail to specified users. But even with its limitations, mail comes in quite handy when used in conjunction with at.
There is one simple issue to overcome before using the mail command. Out of the box, mail will treat the from attribute (in the e-mail header) as localhost or some variation of your hostname. In order to fix this problem, you must edit your /etc/hosts file to reflect your domain name. (The rest of this technique assumes that you’re on a permanent network connection.) Open up /etc/hosts in your favorite editor and take a look at the line that contains your machine’s IP address. You should see something similar to this:
127.0.0.1 localhost.localdomain localhost
172.22.1.2 domain.name alias
Note: Where domain.name is listed, you will see the name you entered when you set up your Linux box, and where alias is listed, you will see the nickname you gave your machine. You need to replace domain.name with your network’s domain name. With this change, mail will have the correct domain name after the @ symbol in its from address.
Now that you’ve configured your file correctly, you can try out mail. The basic syntax for mail is:
mail [-iInv] [-s subject] [-c cc-addr] [-b bcc-addr]
The above syntax includes the following possible arguments:
- Mail—The main command
- -I—Ignores tty interrupt signals (This is particularly useful when using mail on noisy phone lines.)
- -I—Forces mail to run in interactive mode even when input isn't a terminal (In particular, when sending mail, the ~ special character is active only in interactive mode.)
- -n—Inhibits reading /etc/mail.rc upon startup
- -v—Verbose mode (It displays the details of delivery on the user's terminal.)
- -s subject—Subject of the mail
- -c cc-addr—Address where a carbon copy of mail will be sent
- -b bcc-addr—Address where a blind carbon copy of mail will be sent
The simple method of using mail is:
After you type this command, press [Enter] and you will see this:
At this prompt, type in the subject desired and press [Enter] again. Then, you will see something like this:
Cc: [jwallen@giles jwallen]$ mail firstname.lastname@example.org
Subject: This is my test of mail
Notice that the last line is a blank. This is where your cursor will be and where you will enter the body of your message. Once you've typed your message, hit [Enter] once again followed by [Ctrl]d. You will then see
At the above prompt, you can enter any addresses where you wish to cc your e-mail (or enter nothing if you're sending to only one address). Once you've entered (or not) your cc addresses, hit [Enter] once again, and you'll be back to your prompt, and your mail will be sent.
Putting them together
Of course such simple applications will have limitations! What we are trying to develop is a very basic reminder system. The combination of at and mail gives us a very simple setup for using the subject line of an e-mail message to post our reminder—and there is the limitation. When you combine the two commands (at least in this way), you cannot enter text into the body of the e-mail, so the subject line must say it all.
In order to combine the two applications, you must run at first with the following syntax:
will run the command two minutes from now.
Once you run this command, you will see something like this:
[jwallen@giles jwallen]$ at now+2min
Here, you will enter the application to be run at the given time. For our little reminder system, we will enter something akin to the following:
mail -s "Remember to do this" email@example.com
Note: The text “Remember to do this” is the text that will be displayed in the subject of the e-mail message, and firstname.lastname@example.org is the destination e-mail address.
Once you type in the above line, hit [Enter] and then [Ctrl]d. This enters an EOF (or end of file) marker that the application can recognize.
Yes, there are applications that will do this in a much more configurable manner. There are even GUI applications, such as StarOffice, that have integrated mail schedulers and reminders. So, what is the point of this document? To be honest, it's a simple matter of showing the charm of an OS that allows the user to compose simple and creative solutions to common (and sometimes not-so-common) problems. Showing you how to combine various applications in Linux highlights the power and flexibility of the Linux system—a system that is limited only by your imagination.
Jack Wallen, Jr., editor in chief of Linux content, was thrown out of the "Window" back in 1995, when he grew tired of the Blue Screen of Death and realized that "computing does not equal rebooting." Prior to Jack's headfirst dive into the computer industry, he was a professional actor, with film, TV, and Broadway credits. (Anyone see “The Great Gilly Hopkins”?) Now, Jack is determined to use his skills as a communicator to spread the word—Linux. Ladies and gentlemen, the poster boy for the Linux Generation!The authors and editors have taken care in preparation of the content contained herein but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for any damages. Always have a verified backup before making any changes.
Jack Wallen is an award-winning writer for TechRepublic and Linux.com. He’s an avid promoter of open source and the voice of The Android Expert. For more news about Jack Wallen, visit his website jackwallen.com.