Wie man Aufgaben auf Linux mit dem `' am Befehl festlegt

durch Sukrit Dhandhania auf 4. Mai 2009

Linux

Schedulingjobs ist ein wesentliches Teil des Ausübens der Linux Bediener. Wir nahmen einen Blick an, wie man Jobs auf Linux Maschine dem Verwenden festlegt cron Befehl früh. Ist hier eine Alternative zu cron - an. Der Primärunterschied zwischen den zwei ist, daß, wenn Sie eine Aufgabe mit cron es festlegen, wiederholt ohne die Notwendigkeit an der Neufestlegung durchführen Sie. Mit aneinerseits ist die Terminplanung einer Aufgabe nur für eine einzelne Durchführung. Beide dieser Befehle haben ihren Gebrauch, und ich würde vorschlagen, daß Sie ein gutes Verständnis von ihnen beide erhalten.

Lassen Sie uns betrachten, wie man eine Aufgabe festlegt, nur einmal verwenden durchzuführen an Befehl. Überprüfen Sie zuerst ob am Dämon läuft mit einem Befehl so:

# ps - E-F | grep atd
Wurzel 8231 1 0 18:10? 00:00: 00 /usr/sbin/atd

Wenn Sie nicht sehen atd laufender Anfang es mit diesem Befehl:

# /etc/init.d/atd Anfang

Sobald der Dämon erfolgreich begonnen worden ist, können Sie festlegen an Aufgabe, die zwei Wahlen verwendend - f, für die durchgeführt zu werden Akte und - v, während der Zeit, zu der sie durchgeführt werden sollte. So, wenn Sie den Oberteilindex durchführen möchten shellscript.sh bei 6:30 P.M. würden Sie den folgenden Befehl laufen lassen:

# an - f shellscript.sh - v 18:30

Erinnern Sie sich das mit an beherrschen Sie den Index shellscript.sh führt bei 6:30 P.M. durch und dann verschwindet die Terminplanung. So, wenn dieses nicht ist, was Sie wünschen, sind Sie weg vom Verwenden besser cron.

an Befehl ist dadurch recht gescheit, daß er etwas Aufträge auf englisch nehmen kann, wenn Sie mögen. Z.B. können Sie Jobs mit der folgenden Syntax festlegen außerdem:

# an - f shellscript.sh 10pm morgen

# an - f shellscript.sh 2:50 Dienstag

# an - f shellscript.sh 6:00 11. Juli

# an - f shellscript.sh 2:00 folgende Woche

In Verbindung stehende Pfosten:
  • Erhöhen Sie Ihr Linux/Unix-Produktivität: Wie man crontab benutzt
  • Armaturenbrett Widget: MLB Zeitplan
  • Wie man Ihren Mac vom Aufwachen stoppt, wenn es schlafen sollte
  • Wie man Pakete in Linux mit U/min anbringt und handhabt
  • How to save the output of a Linux command to a file
  • Get Simple Help tutorials just like this one in your email inbox every day - for free! Just enter your email address below:

    You can always opt out of this email subscription at any time.

    { 2 comments… read them below or add one }

    1 MikeT 05.04.09 at 5:26 am

    If you don’t see atd running start it with this command:

    # /etc/init.d/atd start

    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).

    2 MikeT 05.04.09 at 5:32 am

    I have another followup for you on use of the at command.

    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.

    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.

    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.

    Leave a Comment

    You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>