Skip to content Перейти до змісту


How to schedule tasks on Linux using the 'at' command Як запланувати завдання на Linux за допомогою 'в' команді

Linux

Scheduling jobs is an essential part of administering Linux servers. Планування робіт є невід'ємною частиною керуючої Linux-серверів. We took a look at how to schedule jobs on Linux machine using the Ми розглянули, як планувати роботу на Linux машині з допомогою cron Cron command earlier. Команда раніше. Here's an alternative to cronat . Ось альтернатива Cron - на. The primary difference between the two is that when you schedule a task using cron it execute repeatedly without the need for rescheduling. Основна різниця між ними в тому, що коли ви запланувати завдання за допомогою Cron його виконати повторно без необхідності реструктуризації. With at , on the other hand, the scheduling of a task is only for a single execution. По крайней, з іншого боку, розкладу завдання полягає лише в одному виконанні. Both of these commands have their use, and I would suggest that you get a good understanding of them both. Обидві команди мають їх використання, і я хотів би запропонувати, що ви отримаєте гарне уявлення про них обох.

Let's look at how to schedule a task to execute only once using the at command. Давайте подивимося, як запланувати завдання повинні виконати тільки один раз, використовуючи в команді. First make sure that the at daemon is running using a command like this: Спочатку переконайтеся, що в запущений демон допомогою команди:

# ps -ef | grep atd # PS-EF | Grep ATD
root 8231 1 0 18:10 ? кореневих 8231 1 0 18:10? 00:00:00 /usr/sbin/atd 00:00:00 / USR / sbin / ATD

If you don't see atd running start it with this command: Якщо ви не бачите ATD розбіг його з цією командою:

# /etc/init.d/atd start # / І т.д. / init.d / Рух початок

Once the daemon has been started successfully you can schedule an at task using the two options -f , for the file to be executed, and -v , for the time at which it should be executed. Коли демон був запущений успішно можна запланувати завдання на використання двох варіантів-F, для файлу, який буде виконуватися, а-V, на даний момент, на якому вона повинна бути виконана. So if you want to execute the shell script shellscript.sh at 6:30 PM you would run the following command: Так що якщо ви хочете виконати оболонку shellscript.sh сценарію в 6:30 вечора ви повинні запустити наступну команду:

# at -f shellscript.sh -v 18:30 # В shellscript.sh-F-V 18:30

Remember that with the at command the script shellscript.sh will execute at 6:30 PM and then the scheduling will disappear. Пам'ятайте, що з командою в сценарії shellscript.sh будуть виконуватися в 6:30 вечора, а потім розклад буде зникати. So if this is not what you desire, you are better off using cron . Так що, якщо це не те, що ви хочете, то краще використовувати Cron.

The at command is pretty clever in that it can take some orders in English if you like. У команді досить розумний, він може прийняти деякі накази англійською мовою, якщо хочете. For example, you can schedule jobs using the following syntax as well: Наприклад, можна запланувати роботу, використовуючи наступний синтаксис, а також:

# at -f shellscript.sh 10pm tomorrow # В-F shellscript.sh 10 вечора завтра

# at -f shellscript.sh 2:50 tuesday # В-F shellscript.sh 2:50 вівторка

# at -f shellscript.sh 6:00 july 11 # В-F shellscript.sh 6:00 11 липня

# at -f shellscript.sh 2:00 next week # В-F shellscript.sh 2:00 наступного тижня

Posted in Опубліковано в Linux Linux . .

Related Posts: Схожі повідомлення:

Increase your Linux/Unix Productivity: How to use crontab Підвищіть Linux / Unix Продуктивність: Як використовувати Crontab
How to enable the root user account in Ubuntu Linux Як включити обліковий запис користувача root в Ubuntu Linux
Dashboard Widget: MLB Schedule Dashboard Widget: MLB Schedule
How to save the output of a Linux command to a file Як зберегти вивід команди Linux в файл
How to post to Twitter from the Linux command line Як розмістити на Twitter з командного рядка Linux

3 Responses 3 Відповіді

Stay in touch with the conversation, subscribe to the Залишайтеся на зв'язку при розмові, підпишіться на RSS feed for comments on this post RSS-канал для коментарів на цю посаду . .

  1. MikeT says MikeT говорить

    If you don't see atd running start it with this command: Якщо ви не бачите ATD розбіг його з цією командою:

    # /etc/init.d/atd start # / І т.д. / init.d / Рух початок

    More correctly, if it isn't running, it probably is not configured to startup when the system is restarted. Більш коректно, якщо воно не виконується, то, ймовірно, не налаштований на запуск під час перезавантаження системи. Which may also keep the above command from working as expected. Які можуть також тримати над командою працювати, як очікувалося. To correct this, use: Щоб виправити це, використовуйте:

    # chkconfig atd --level 234 on
    # service atd start

    and check again to make sure it is running, if it is, continue with the instructions (which are very good BTW). і перевірте ще раз, щоб переконатися, що вона працює, якщо він, як і раніше з інструкціями (які дуже хороший BTW).

  2. MikeT says MikeT говорить

    I have another followup for you on use of the at command. У мене є інший follow-за вас на використання в команді.

    I've run into situations where I've needed a command run every hour BUT I needed the command to run ONLY if the previous run has completed. Я зіткнутися з ситуаціями, коли я мав потребу в команду "Виконати" кожен час, але мені потрібна команда для запуску тільки якщо попередній запуск завершився. It might not be hung but it might be very very busy. Це може бути не висів, але воно може бути дуже і дуже зайнятий. I don't mind skipping an hour's execution if the process is still busy. Я не заперечую пропускаючи виконання години, якщо цей процес усе ще зайнятий.

    When this situation arises, I don't use cron, I use 'at' and the last thing I put in my script is the at command itself to resubmit the job for execution. Коли ця ситуація виникає, я не використовую Cron, я використовую 'в', і останнє, що я поклав у моєму сценарії на саму команду, щоб оновити всю роботу за виконанням.

    Now, even if the job takes three hours, at the top of the following hour, the at command will launch the job as expected without cron jobs bumping into each other. Тепер, навіть якщо робота не займає три години, у верхній частині наступної години, у команді почне роботу, як і очікувалося, без Cron Jobs натикаючись один на одного.

    Yes, there's ways to put the logic into a script for cron to deal with it but that can also be difficult to maintain and not as obvious (to some) as this approach. Так, є способи, щоб поставити логіку в Cron скрипт для боротьби з ним, але які можуть також буде важко підтримувати, а не очевидна (деякі), оскільки такий підхід.

Continuing the Discussion Продовжуючи розмову

  1. Use the At command in Linux for one-off task scheduling « Linux & Stuff При використанні команди в Linux для одноразової завданням планування «Linux & Stuff linked to this post on May 24, 2009 пов'язані на цю посаду 24 травня 2009

    [...] in CLI | Tags: CLI The SimpleHelp blog has a nice post about this useful [...] [...] У CLI | Мітки: CLI SimpleHelp блог хороший пост про це корисно [...]



Some HTML is OK Деякі HTML нормально

or, reply to this post via або відповісти на цей пост через trackback Архів . .