Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Linux Timesaving Techniques For Dummies.pdf
Скачиваний:
59
Добавлен:
15.03.2015
Размер:
15.98 Mб
Скачать

20 Setting Up

Automatic

Technique Services

Save Time By

Setting up automatic tasks with Task Scheduler

Editing existing tasks

Creating an environment for your automated tasks

Administrative tasks — such as backing up, updating data files, and updating Web site mirrors — are easy to automate. You can save tons of time by creating automatic tasks that do your job without

any help from you. To help you automate these tasks, you have two handy tools at your disposal: Task Scheduler and the Services Configuration Tool.

Task Scheduler is a graphical interface that schedules programs to run automatically with the program cron. Setting up jobs to run when network demands are low can save time (and user frustration from the bogged-down network). Task Scheduler has a nice interface and offers a quick way to set up cron jobs.

In this technique, we’ll show you how to automate your work with Task Scheduler.

Letting Task Scheduler Work for You

Task Scheduler is a graphical interface for cron (the Linux scheduling tool). With Task Scheduler, you can set up recurrent downloads, backups, or other system maintenance jobs to run at night (or when your network load is the lightest).

Task Scheduler is part of the kdeadmin package (if you’re using KDE, make sure you’ve installed the kdeadmin package or you won’t find Task Scheduler in the KDE Menu). The Mandrake 10.0 Community Edition distribution does not include the kdeadmin package (although later editions may) — if you can’t find kdeadmin in your distribution, you’ll have to download and install it from the Web.

GNOME doesn’t have an official task scheduler yet, but if you Google for GNOME and Task Scheduler, you should find a few options.

Letting Task Scheduler Work for You

127

Before Task Scheduler will work, you need to start the crond daemon. To start crond, follow these steps:

1. Open a terminal window and give yourself superuser privileges with the su command.

2. Type in the following command and press

Enter.

If you’re a Fedora or Mandrake user, use this command:

# /sbin/service crond start

SuSE users should use this command:

# /etc/init.d/cron start

Scheduling a new task

After you’ve started the crond daemon, you’re ready to set up automated tasks:

1. To start Task Scheduler, open the Main Menu and choose System Tools Task Scheduler.

The Task Scheduler window opens, showing a summary of the scheduled tasks and their environment variables (see Figure 20-1).

• Figure 20-1: The Task Scheduler window.

If you’re logged in as root, you see everyone’s scheduled tasks. If not, you’re privileged to see your own tasks only.

2. To add a new task, right-click the Tasks folder and choose New.

The Edit Task window opens (see Figure 20-2).

Figure 20-2: The Edit Task window.

3.To create a new task, fill in the following fields:

Comment: Enter a descriptive name.

Program: Enter the command you want to run.

It’s a good idea to use the complete pathname for a command, not just the command name. That way, changes to your environment (your $PATH variable in particular) won’t affect scheduled tasks. For example, enter /usr/bin/wget -r --mirror -k http://www.website.com to update a Web site nightly. If you don’t know the complete pathname, use the Browse button to find your program. Most of the commands are in /bin, /usr/bin or /usr/local/bin.

128 Technique 20: Setting Up Automatic Services

Enabled: Check this box to make the task active. If the box isn’t checked, the task won’t run.

Silent: Check this box to turn off the logging features.

Months: Check the box next to each month that you want the job to run.

Days of Month, Days of Week, or Run Every Day: You can choose when the task runs in one of three ways. Choose the days of the month that the job executes, or choose the days of the week that the job executes, or check the Run Every Day box to automatically choose all the months, days, and dates.

Hours and Minutes: Choose the hours and minutes that the task should begin.

Set up network-intensive jobs to execute at night when network traffic is low. The jobs will run faster, and you’ll be saving the bandwidth for when you really need it.

4. Click OK.

The new job is added to the Tasks list, as shown in Figure 20-3.

Figure 20-3: The new task is added to the list.

5.If you’re done using Task Scheduler, click Save. Or if you haven’t defined the environment variables, see “Adding environment variables,” later in this technique, to do so.

It’s hard to predict the environment in which your scheduled tasks will run. Use full pathnames and define the environment variables that you need. That also makes you more immune to changes in the system configuration.

If you’re scheduling a complex task (one that involves running multiple commands), write yourself a shell script and schedule the script instead of a complex command line. It’s much easier to debug a script than a complex command line that resides somewhere in the Task Scheduler’s database. Technique 10 has some handy information about creating shell scripts.

Editing a task

If you need to go back and edit a task, open the Main Menu and choose System Tools Task Scheduler. In Task Scheduler, right-click the task (refer to Figure 20-3) and choose Modify from the pop-up menu. When you’re done, click Save so that the scheduler remembers the new settings.

Adding environment variables

Task Scheduler works in its own environment, so you need to add any environment variables that your task needs to run properly (such as $PATH).

To add or edit a variable, follow these steps:

1. Choose System Tools Task Scheduler, rightclick Variables, and choose New from the popup menu.

The Edit Variable dialog opens, as shown in Figure 20-4.

2. To add a new variable, fill in the fields on the dialog:

Variable: Enter the variable name, or choose from the most common variables in the dropdown list.

If you don’t define the HOME , MAILTO, and SHELL variables, they default to your normal values. Change these variables if you want to override the defaults.

 

Letting Task Scheduler Work for You

129

The PATH variable holds the search path that

4. When you’re finished using Task Scheduler,

cron uses to locate your programs.

click the Save icon to save your changes and

Value: Enter the variable’s value.

then close the window.

 

 

 

Comment: Enter a description of the variable.

Your newly scheduled programs will run without

any help from you!

 

Enable: Check this box to make the variable

 

 

 

active. If the box is not checked, the variable

If you use a proxy server to access the net,

doesn’t take effect.

wget can use the http_proxy variable to

 

3. Click OK when you’ve completed this dialog.

 

speed up data transfers. Create the variable

Your new variable is added.

quickly with Task Scheduler, as shown in

 

Figure 20-5.

 

• Figure 20-4: The Edit Variable dialog.

• Figure 20-5: Setting the http_proxy variable.

Соседние файлы в предмете Операционные системы