-->

Previous | Table of Contents | Next

Page 271

Hour 18

Personal Productivity Tools

This hour shows you some calendars, commands, and X11 clients you can use to help your personal productivity. Whether it's keeping a diary or creating reminders, you'll learn how to use these tools under Linux to keep you on track and on schedule with your life.

Each program or technique discussed in this hour can be accomplished with software you'll find on the CD-ROM that came with your book. After reading this discussion, you'll find additional ways to use these programs to craft your own set of tools and techniques for personal productivity.

Page 272

Scheduling Personal Reminders and Tasks with the at Command

If you need to keep track of important schedules, set reminders, or run programs unattended, you can use the at command. This command, found under the /usr/bin directory, will schedule commands, or jobs, to be run at a time you specify. For example, if you're working on a project but need to remember to catch your car pool, you can enter a quick at job from the command line.

TIME SAVER
Your system should allow you to use the at commands by default. If it does not, see Hour 24, "Scheduling," on how to enable at command facilities for your system.

The following shows the at command for the car pool example:


# at 16:15

xmessage -display :0.0 "The car pool is leaving in 15 minutes."

EOT

Job 4 will be executed using /bin/sh

This will tell the at command to run the xmessage program to display the text of your message about your car pool on the specified X11 display. The -display command-line option will tell the xmessage command which screen to show the message on, usually 0.0, which you can find with


# printenv | fgrep DISPLAY

This command line searches a listing of your environment variables (discussed in Hour 6, "Using the Shell") and prints the value of the DISPLAY variable. The end-of-text in the listing means that you should press Ctrl-D to close the command and then enter the job. If you make a mistake in the syntax of the command, you'll receive a mail message at the scheduled time.

You can also use the at command to provide a visual reminder, if you're using X11, by controlling the color of your desktop, for example:


# at 16:15

xsetroot -display :0.0 -solid Red

xmessage -display :0.0 "The car pool is leaving in 15 minutes."

EOT

Job 8 will be executed using /bin/sh

Page 273

This will turn your desktop a solid red color at the appointed time, then display your message. As you can see, you can combine multiple commands to do a number of things at once. If you find this approach convenient, you can also type these commands into a text file called carpool and run the commands with the following:


# at 16:15 -f carpool

As a further convenience, you can place this command line in your .xintrc script in your home directory to schedule the job after you start X11 at the beginning of the day. You can see a list of scheduled jobs with the atq command, for example:


# atq

Date                    Owner   Queue   Job#

17:00:00 12/07/97       bball   c       15

18:00:00 12/07/97       bball   c       16

19:00:00 12/07/97       bball   c       17

16:00:00 12/25/97       bball   c       18

This shows that three jobs are scheduled for December 7, with another scheduled for December 25. When you schedule jobs with the at command, a shell script containing your commands is created in the /var/spool/at directory. The atq command looks in this directory for your jobs, then prints them to your display.

You can use the at command to schedule a job minutes, hours, days, weeks, or even years in advance. If you want to run your carpool reminder file in three hours, you can use the at command's plus sign (+) command-line option, for example:


# at +3 hours -f carpool

This would run your job three hours from the current system time. If you want to remove one or two jobs, you can use the atrm command. For example, using your job queue from the earlier example, you would type


# atrm 16 18

This would remove jobs 16 and 18, but leave the other two intact. Using the at command is a handy way to program one-time reminders for specific times. In the next section, I'll show you how to schedule other jobs to run at regular intervals.

JUST A MINUTE
You can also use Rob Nation's X11 client, rclock, to schedule reminders or run programs at a selected day or time. To build a reminder, create a file called .rclock in your home directory and enter reminder command lines—for example: 11:30 mtwtf Time for lunch!

This displays a reminder for lunch during the week.

Page 274

Scheduling Regular Reminders with the crontab Command

Although the at command is helpful for scheduling one-time jobs, you'll want to use Paul Vixie's crontab command if you need regular tasks completed at regular intervals. The crontab command, found under the /usr/bin directory, is used to enter your desired times and commands into a personal file.

The crontab command works by looking for crontab schedules, by username, in the /var/spool/cron directory. The crontab file for your Linux system is called crontab and is located in the /etc directory. The program that runs the system and user cron schedules is the cron daemon, which is started when you boot Linux, and which wakes up each minute to check the system and user files.

To create your own crontab file, you must use the command's -e option, for example:


# crontab -e

TIME SAVER
Make sure you've enabled crontab use for your system. See Hour 24 for details on how to do this. You'll also want to define the default EDITOR environment variable to your favorite text editor when you create or edit your crontab files. See Hour 6 for information on how to set environment variables.

This command will launch the default text editor, defined in your shell's EDITOR environment variable, so you can create or edit your personal crontab file. If your default editor is vi, and you either don't want to use vi, or would like to use a different editor, you can temporarily change the $EDITOR variable using your shell. For example, if you're using the bash shell, and want to use the pico text editor, you can use


# EDITOR /usr/bin/pico; export EDITOR

This will set the default editor to the pico editor. You can confirm this by searching your environment variables, for example:


# printenv | fgrep EDITOR

EDITOR=/usr/bin/pico

Whichever editor you use, you'll initially be presented an empty file if you've never created a crontab file. You can then enter crontab settings. Before you can enter your own schedule, you should know how to format a crontab request. You'll find the format of crontab requests and some sample entries in the crontab manual page under the /usr/man/man5

Previous | Table of Contents | Next