Apart from video games one of the great advantages of using computers is that they don’t seem to mind doing boring and repetitive tasks that we would rather not do. Zusätzlich zu Video-Spiele einer der großen Vorteile der Verwendung von Computern ist, dass sie offenbar nicht in den Sinn tun, langweilig und sich wiederholende Aufgaben, die wir lieber nicht tun. For monotonous tasks such as running daily backups we are better off scheduling them to run at a certain time every day, and do more interesting stuff with our time. Für monotonen Aufgaben wie läuft täglich Backups sind wir besser dran Scheduling sie dazu, auch zu einem bestimmten Zeitpunkt jeden Tag, und noch mehr interessante Dinge mit unserer Zeit. Linux and UNIX usually come with the utility “crontab” by default. Linux-und UNIX-kommen in der Regel mit dem Dienstprogramm "crontab" standardmäßig aktiviert. This very useful command allows you to schedule tasks to run at a specified time and repeat as configured. Diese sehr nützliche Befehl können Sie zum Planen von Aufgaben zur Ausführung in einer bestimmten Zeit und wiederholen Sie mit der Konfiguration. A task scheduled using “crontab” is called a “cron job”. Eine Aufgabe geplant mit "crontab" wird als "cron-Job".
The crontab command allows you to instruct your server to execute a script at a specified minute of the specified day of the particular month. Die crontab-Kommando ermöglicht es Ihnen, Ihre Server anweisen, die Ausführung eines Skripts zu einem bestimmten Minuten in dem der angegebene Tag des jeweiligen Monats. To see what cron jobs are setup to run on your machine, run the following command: Um zu sehen, welche Cron-Jobs werden Setup, um auf Ihrem Rechner haben, führen Sie den folgenden Befehl ein:
# crontab -l # Crontab-l
If your machine has some cron jobs configured it will display something like the following: Wenn Ihr Rechner hat einige cron-Jobs konfiguriert es wird so etwas wie den folgenden:
0 6 * * * /opt/scripts/backup_script.sh 0 6 * * * / opt / scripts / backup_script.sh
The crontab configuration above shows a cron job that executes the shell script “backup_script” everyday at 6 AM. Die crontab-Konfiguration oben zeigt einen Cron-Job führt, dass die Shell-Skript "backup_script" täglich um 6 Uhr. The * means to run at every instance of the value in the field. * Die Mittel, um in jeder Instanz der Wert in das Feld ein. So an asterisk in the day, month, and day of week fields in the above example means that the script should run every day of the month, every month of the year, and every day of the week. Also ein Sternchen in den Tag, Monat und Tag der Woche Felder im obigen Beispiel bedeutet, dass das Skript ausgeführt werden soll, jeden Tag des Monats, jeden Monat des Jahres, und jeden Tag der Woche. The first and second fields tell crontab to execute the script at zero minutes and six hours, which is 6 AM. Der erste und der zweite Felder sagen crontab, um das Skript bei Null Minuten und sechs Stunden, das ist 6. So, this cron job configuration would read something like this, “Run the script /opt/scripts/backup_script.sh at zero minutes, 6 AM, every day, every month, and every day of the week.” Below is the “anatomy” of a crontab configuration explained. Also, dieser Cron-Job-Konfiguration lesen würde etwas davon, "Führen Sie das Skript / opt / scripts / backup_script.sh bei Null Minuten, 6 Uhr, jeden Tag, jeden Monat, und jeden Tag der Woche." Unten ist die "Anatomie "Einer crontab-Konfiguration erklärt.
0 6 * * * /opt/scripts/backup_script.sh 0 6 * * * / opt / scripts / backup_script.sh
| | | | | | | | | |
| | | | |________________ day of week (Sunday=0) | | | | |________________ Tag der Woche (Sonntag = 0)
| | | |__________________ month of year | | | |__________________ Monate des Jahres
| | |____________________ day of month | | |____________________ Tag des Monats
| |______________________ hour of day | |______________________ Stunden des Tages
|________________________ minute of hour |________________________ Minute der Stunde
To schedule new cron jobs or to edit old ones execute the following command: So planen neue Cron-Jobs oder zu bearbeiten alten führen Sie den folgenden Befehl ein:
# crontab -e # Crontab-e
This will bring up an editor with which you can add, edit, or delete “cron jobs”. Daraufhin wird ein Editor, mit dem Sie können hinzufügen, bearbeiten oder löschen "cron-Jobs". To schedule a job to run at 3:45 PM every Monday add entry like this: So planen Sie einen Job, um bei 3:45 PM jeden Montag hinzufügen Eintrag wie folgt aus:
45 15 * * 1 /opt/scripts/script.sh 45 15 * * 1 / opt / scripts / script.sh
You can also use a comma to add multiple entries into a field. Sie können auch ein Komma, um mehrere Einträge in einem Feld. This is useful if you want to run a script thrice a day, with an eight hour interval. Dies ist nützlich, wenn Sie wollen, führen Sie ein Skript dreimal am Tag, mit einem acht Stunden-Intervall. Make sure you do not leave space between entries in a single field, though. Stellen Sie sicher, dass Sie nicht verlassen Abstand zwischen den Einträgen in einem einzigen Bereich, wenn. Your “cron job” entry would look like this: Ihr "cron-Job"-Eintrag würde so aussehen:
0 1,9,17 * 2,11 * /opt/scripts/db_backup_script.sh 0 1,9,17 * 2,11 * / opt / scripts / db_backup_script.sh
In the above example the script “db_backup_script.sh” runs at 1 AM, 9 AM, and 5 PM every day in the months of February and November. In dem obigen Beispiel das Skript "db_backup_script.sh" läuft auf 1, 9, und 5 Uhr jeden Tag in den Monaten Februar und November. There are a lot of cool things that you can do with cron jobs. Es gibt eine Menge coole Sachen, die Sie tun können, mit cron-Jobs. The same works for day, month, and day of week. Das gleiche funktioniert für Tag, Monat und Tag der Woche. Once you get the hang of this try out the following. Sobald Sie die hängen von dieser Probieren Sie die folgenden. Crontab doesn’t only understand numbers, it can also operate on some basic English words: Crontab nicht nur Zahlen, es kann auch auf einige grundlegende englische Wörter:
string explanation String-Erklärung
—— ———– - ----
@reboot Run once, the next time the system reboots @ reboot Ausführen einmal, das nächste Mal das System neu gestartet
@yearly Run once a year, at the beginning of the year @ Jahres-Run einmal im Jahr, zu Beginn des Jahres
@annually Same as @yearly, run once annually @ jährlich gilt die gleiche Begründung wie @ jährlich, führen Sie einmal jährlich
@monthly Run once a month, at the beginning of the month @ monatlichen Führen Sie einmal im Monat, am Anfang des Monats
@weekly Run once a week, at the beginning of the week @ wöchentlichen Run einmal in der Woche, am Anfang der Woche
@daily Run once a day, at midnight @ tägliche Führen Sie einmal einen Tag, um Mitternacht
@midnight Same as @daily, run at midnight @ Mitternacht gilt die gleiche Begründung wie @ täglich, laufen um Mitternacht
@hourly Run once an hour, at the beginning of the hour @ stündlich Führen Sie einmal eine Stunde, am Anfang der Stunde
So, for example, if you want to run a script at midnight every night, this is what your crontab configuration would look like: Also, zum Beispiel, wenn Sie wollen, führen Sie ein Skript um Mitternacht jede Nacht, das ist es, was Ihre crontab-Konfiguration würde wie folgt aussehen:
@midnight /opt/scripts/script.sh @ Mitternacht / opt / scripts / script.sh
Using “@midnight” rather than “0 0 * * *” will work the same and execute the requested script at midnight every night while being a lot more readable than its numerical counterpart. Die Verwendung von "@ Mitternacht" statt "0 0 * * *" wird die gleiche Arbeit und führen Sie das Skript ersuchte um Mitternacht jede Nacht während des viel besser lesbar als ihre numerische Pendant. You can also make the use of hyphens to declare a range. Sie können auch die Verwendung von Bindestrichen zu erklären, eine Reihe. In the command below “script.sh” will be executed at the beginning of every hour from 1 AM to 6 AM: In den Befehl unter "script.sh" wird ausgeführt, die zu Beginn zu jeder vollen Stunde zwischen 1 und 6:
0 1-6 * * * /opt/scripts/script.sh 0 1-6 * * * / opt / scripts / script.sh
There are many more cool things you can do with cron. Es gibt viele weitere coole Dinge, die Sie tun können, mit cron. Every sysasmin swears by it, it’s pretty easy to use once you get the hang on it, and very powerful. Jeder sysasmin schwört auf sie, es ist ziemlich einfach zu benutzen, sobald Sie die hängen sie auf, und sehr mächtig. Use this tool wisely, as scheduling a task wrongly can sometimes do a lot of harm. Benutzen Sie dieses Tool, mit Bedacht aus, wie die Planung einer Aufgabe kann manchmal zu Unrecht tun eine Menge Schaden. Reading the “man page” of crontab would be highly recommended. Lesung der "man page" von crontab wäre sehr zu empfehlen.






















{ 0 comments… (0 Kommentare ... add one now Add jetzt ein } )
Leave a Comment Schreibe einen Kommentar