You may or may not be familiar with cron, a daemon which allows you to schedule repetitive tasks to run throughout the day. However, there are two additional commands, not widely used, which can really make your life just a little bit easier. They are, at and batch. at and batch are really the same commands, but do different things depending on how they're called.
at allows you to schedule tasks, or an application, to execute at a specific date and time in the future. Unlike cron, which will run the application every n minutes, hours, days, weeks, etc., at will only run a command once. I use it all the time for reminders, like:
% echo "mail -s 'REMINDER: Feed the dog' myname@myemail.com" | at 18:30This will send me an email at 6:30pm to remind me to feed my dog. You can do a man at to see its manual and learn additional things you can do.
Another command is called batch. batch is neat in that you can schedule a job to run, almost immediately. It will quietly run in the background, doing its thing. My NetInfo aliases database, and my .forward in my home-directory, automatically forward any mail sent to my local Mac account (both at and batch will generate an Email output when they're done so you can see what happened) are forwarded to my main Email address for inspection. For example, let's say I'm getting ready to go to work, but I want to have fink update everything. I can simply type:
% batch... which will show nothing but a cursor. batch is waiting for me to type whatever commands I want it to do. Now, all I need to enter is:
% sudo fink -y update-all ^DThe ^D at the end is a Control+D, and is important to tell batch that you're done entering the commands.
As soon as you type ^D, within the next five minutes, the command will run. I can safely close all applications and even log out of my Mac if I want to (but not shut it down!). When I get home at the end of the day, there will be an email waiting for me with the output of everything which would have been sent to the screen. But, in order to use these commands, you first need to enable them. OS X ships with the "at" scheduler disabled by default. Here's how to enable the at-scheduler. In the Terminal, type:
% sudo pico /etc/crontabRemove the hash-mark (#) from the line which reads:
#*/5 * * * * root /usr/libexec/atrunSo it should now read:
*/5 * * * * root /usr/libexec/atrunThen exit and save your changes. That's it!
Some suggested uses for `at` and `batch`:
- echo "mail -s 'DENTIST APPOINTMENT AT 2PM' you@yourdomain.com" | at '4/23/2003 10:00AM' - Mail yourself a reminder for upcoming dentist appointments. The single and double-quotes are required because of the spaces.
- echo "sudo fink -y selfupdate-cvs" | batch - Update fink, within the next five minutes, in the background.
- echo "sudo fink -y install bundle-kde-ssl" | at midnight - At midnight tonight, have fink install KDE for you, while you're asleep!

