
Die crontab wird verwendet, um bestimmte Aufgaben in regelmäßigen Abständen auszuführen. Die Linux-Crontab ähnelt den Windows-Task Schedule. Die Crontab ist sehr nützlich für Routineaufgaben wie die Planung von System-Scans, tägliche Backups, tägliche Statistiken, usw.
Die Crontab führt die Jobs automatisch im Backend zu einem bestimmten Zeitpunkt und in einem bestimmten Intervall aus. In diesem Tutorial lernen Sie die Verwendung der Crontab anhand von 10 nützlichen Beispielen für die Planung von Jobs. Sie können die crontab auch für die Aufgaben verwenden, die in Zukunft nur einmal ausgeführt werden sollen. Für alle Aufgaben, die einmal ausgeführt werden sollen, empfehlen wir jedoch, Linux auf Befehl zu verwenden.
Die Linux-Crontab hat sechs Felder. 1-5 Felder definieren das Datum und die Uhrzeit der Ausführung. Die 6’ten Felder werden für den auszuführenden Befehl oder das auszuführende Skript verwendet. Die Syntax der Linux-Crontab lautet wie folgt:

- Stern (*) – Passt zu allem
- Bereich definieren – Sie können den Bereich mit Hilfe des Hypen like definieren: 1-10 oder 20-30 oder sun-fri oder feb-apr
- Mehrere Bereiche definieren – Sie können mehrere Bereiche mit Befehlen definieren, die wie folgt lauten: jan-mar,jul-sep
Wie man Crontab bearbeitet
Um Jobs in der crontab hinzuzufügen oder zu aktualisieren, verwenden Sie den folgenden Befehl. Dadurch wird eine crontab-Datei im Editor geöffnet, in der ein Job hinzugefügt/aktualisiert werden kann.
crontab -e |
Planen Sie einen Cron, der täglich um 1 Uhr morgens ausgeführt werden soll
Dies ist nützlich, um Datenbank-Backups auf täglicher Basis zu planen. Der Skript backup.sh wird um 01:00 täglich automatisch aufgerufen
0 1 * * * /var/backup.sh |
Planen Sie einen Cron, der zweimal am Tag ausgeführt wird.
Der unten stehende Befehl wird täglich um 1 Uhr morgens und 19 Uhr abends ausgeführt. Sie können mehrere Zeitstempel durch Komma getrennt angeben.
0 1,19 * * * /var/backup.sh |
Planen Sie für jede Minute einen Cron zur Ausführung ein.
Im Allgemeinen benötigen wir kein Skript, das jede Minute ausgeführt wird, aber in einigen Fällen müssen Sie es möglicherweise konfigurieren.
* * * * * /var/script.sh |
Planen Sie alle 5 Minuten einen Cron zur Ausführung
Wenn Sie Ihr Skript im 5-Minuten-Intervall ausführen möchten, können Sie wie unten beschrieben konfigurieren. Diese Arten von Crons sind für die Überwachung nützlich.
*/5 * * * * /var/script.sh |
Planen Sie einen Cron zur Ausführung für ausgewählte Monate.
Manchmal mussten wir eine Aufgabe so planen, dass sie nur für ausgewählte Monate ausgeführt wird. Das unten stehende Beispielskript wird in den Monaten Januar, Mai und August ausgeführt.
* * jan,may,aug * /var/script.sh oder * * 1,5,8 * /var/script.sh |
Planen Sie alle vier Stunden einen Cron zur Ausführung ein
Wenn Sie ein Skript im 4-Stunden-Intervall ausführen möchten. Es kann wie unten konfiguriert werden.
* */4 * * * /var/script.sh |
Planen Sie einen Cron, der alle 15 Sekunden ausgeführt wird.
Eine Aufgabe zu planen, die alle 15 Sekunden ausgeführt werden soll, ist nicht durch Zeitparameter möglich, aber es kann durch den Zeitplan der gleichen cron viermal wie unten ausgeführt werden.
* * * * * /var/script.sh * * * * * sleep 15;/var/script.sh * * * * * sleep 30;/var/script.sh * * * * * sleep 45;/var/script.sh |
Planen Sie mehrere Aufgaben in einem einzigen Cron.
Um mehrere Aufgaben mit einem einzigen Cron zu konfigurieren, können Aufgaben durch das Semikolon ( ; ) getrennt werden.
* * * * * /var/script.sh ; /var/new-script.sh |
Weitere Beispiele
#Jährlich ein Skript ausführen @yearly /var/script.sh #Monatlich ein Skript ausführen @monthly /var/script.sh #Täglich ein Skript ausführen @daily /var/script.sh #Stündlich ein Skript ausführen @hourly /var/script.sh |
pregabalin 75mg ca – pregabalin 150mg over the counter buy lyrica 75mg without prescription
buy clomid 100mg for sale – buy clomiphene pill zyrtec for sale online
cytotec without prescription – prednisolone 40mg for sale synthroid 100mcg sale
sildenafil for women – buy neurontin 800mg gabapentin 100mg price
best cialis sites online – cenforce 50mg cheap cenforce cheap
order diltiazem generic – diltiazem ca order zovirax 400mg pills
buy hydroxyzine generic – purchase hydroxyzine pill buy generic crestor
purchase zetia pills – domperidone for sale oral celexa 40mg
viagra online order – sildenafil for men cost cyclobenzaprine
viagra 150mg canada – real viagra pills tadalafil brand name
buy toradol 10mg generic – oral baclofen 25mg baclofen pill
colchicine 0.5mg without prescription – purchase inderal online oral strattera
sildenafil overnight shipping – buy methotrexate 10mg generic plavix 150mg over the counter
cheap viagra sale – buy sildenafil sale order plavix 150mg online
buy sildenafil 150mg sale – sildenafil 100mg price viagra 25mg
buy esomeprazole without prescription – oral promethazine phenergan cost
cialis buy online – Buy cheap cialis online canadian cialis and healthcare
provigil 100mg brand – canadian pharmacy legitimate best ed pills at gnc
buy isotretinoin 10mg generic – buy amoxicillin for sale buy zithromax 250mg without prescription
order lasix 40mg pill – sildenafil 50mg tablet overnight delivery viagra
tadalafil 10mg canada – tadalafil 10mg canada viagra 150mg tablet
tadalafil 5mg cost – brand losartan 25mg warfarin generic
topamax 200mg without prescription – sumatriptan price purchase sumatriptan for sale
purchase avodart generic – tadalafil 20mg ca buy generic tadalafil 40mg
cost viagra 150mg – buy viagra 50mg for sale cialis 40mg price
best ed drugs – buy prednisone 40mg online oral prednisone 20mg
order accutane 40mg pills – amoxil 500mg generic amoxil order online
order lasix 40mg generic – buy azithromycin 500mg generic order azithromycin 500mg pill
purchase doxycycline online – order chloroquine sale chloroquine drug
real cialis pills – Buy no rx cialis pfizer viagra 50mg
provigil 200mg pill – order provigil online purchase sildenafil without prescription
pills erectile dysfunction – ed pills order deltasone 5mg online cheap
buy isotretinoin online cheap – celebrex 100mg generic purchase celecoxib online cheap
order tamsulosin 0.2mg generic – generic tamsulosin order spironolactone generic
zocor without prescription – valtrex 1000mg generic paper writing websites
sugarhouse casino online – pay for assignments buy a research paper online
best online casino real money – order ampicillin 250mg acillin ca
purchase cipro online – order cipro 1000mg generic cialis next day delivery usa
sildenafil sale – order viagra 150mg for sale buy vardenafil next day delivery
erectile dysfunction medicines
what to do when cialis stops working generic cialis? i want to buy cialis in australia
causes for ed shots for ed cheap ed drugs
prednisone 50 mg for sale buy prednisone online prednisone brand name canada
cost prednisolone 20mg – is cialis generic cialis 40mg pills
hydroxychloronique https://keys-chloroquinehydro.com/
cialis online with no prescription cialis from india buy cialis online in new zealand
purchase prednisone no prescription buy prednisone online prednisone 4 mg daily
cialis generika paypal cheap cialis online overnight shipping how many milligrams of cialis can you take in a day ?
ivermectin pyrantel generic where can i buy stromectol ivermectin ivermectin sheep drench tractor supply
augmentin pills – order augmentin 1000mg pills order tadalafil 40mg online
п»їerectile dysfunction medication ed pills comparison best otc ed pills
trimethoprim sale – bactrim online buy viagra over the counter
buy prescription drugs online without buy prescription drugs online legal to buy prescription drugs without prescription
ivermectin antiviral effects stromectol drops ivermectin antiparasitic
ed drugs compared best ed treatment pills erectile dysfunction medicines
buy cephalexin – cephalexin 250mg ca erythromycin generic
propesia propecia without a prescription propecia generic no prescription
sildenafil without a doctor’s prescription non prescription ed pills how to get prescription drugs without doctor
pain meds online without doctor prescription how to get prescription drugs without doctor prescription drugs
stromectol 12 mg tablets stromectol for humans for sale prescribing stromectol
discount prescription drugs online highest rated canadian pharmacies buying from canadian online pharmacies
natural ed remedies ed remedies impotence pills
rhinocort online order – cialis pills brand antabuse
stromectol 3 mg tablets price stromectol stromectol
ivermectin without a doctor prescription stromectol 12 mg tablets prescribing stromectol
order ceftin 250mg for sale – ceftin 500mg us cialis 5mg canada
tadalafil without a doctor’s prescription tadalafil without a doctor’s prescription price of cialis 20 mg
viagra where to buy sildenafil 100 mg sildenafil citrate tablets 100 mg
ampicillin 250mg brand – buy cipro 1000mg online cialis 5mg uk
buy clomid 50mg buy clomid buy clomid
clomid for sale canada clomid for sale canada clomid for sale
buy clomid clomid for sale canada buy clomid
cheap amoxicillin tablets – cheap zithromax 250mg levitra without prescription