{"id":1230,"date":"2022-09-21T06:55:00","date_gmt":"2022-09-21T06:55:00","guid":{"rendered":"https:\/\/sunucucozumleri.com\/?p=1230"},"modified":"2022-10-09T19:08:55","modified_gmt":"2022-10-09T19:08:55","slug":"linuxde-zamanlanmis-gorevler-cronjob","status":"publish","type":"post","link":"https:\/\/sunucucozumleri.com\/blog\/linuxde-zamanlanmis-gorevler-cronjob\/","title":{"rendered":"Linux\u2019de Zamanlanm\u0131\u015f G\u00f6revler (Cronjob)"},"content":{"rendered":"<p><b>Cronjobs Nedir?<br \/>\n<\/b>Cron istenilen g\u00f6revlerin belirli zaman aral\u0131klar\u0131 ile arkaplanda yap\u0131lmas\u0131na izin veren bir UNIX arac\u0131d\u0131r.<\/p>\n<p><b>Crontab (Cron TABle) Nedir?<\/b><br \/>\n\u00c7al\u0131st\u0131r\u0131lacak g\u00f6revi ve g\u00f6revin \u00e7al\u0131st\u0131r\u0131lacag\u0131 zaman\u0131 bar\u0131nd\u0131ran dosyad\u0131r.<\/p>\n<p><b>Cron g\u00f6revlerini ayarlama<\/b><br \/>\nA\u015fa\u011f\u0131da\u00a0<tt><strong>\/etc\/crontab<\/strong><\/tt>\u00a0dosyas\u0131 g\u00f6r\u00fclmektedir.<\/p>\n<p><code><br \/>\n[root@sunucucozumleri.com~]$cat \/etc\/crontab<br \/>\nSHELL=\/bin\/bash<br \/>\nPATH=\/sbin:\/bin:\/usr\/sbin:\/usr\/bin<br \/>\nMAILTO=root<br \/>\nHOME=\/<\/code><\/p>\n<p># For details see man 4 crontabs<\/p>\n<p># Example of job definition:<br \/>\n# .&#8212;&#8212;&#8212;&#8212;&#8212;- minute (0 &#8211; 59)<br \/>\n# | .&#8212;&#8212;&#8212;&#8212;- hour (0 &#8211; 23)<br \/>\n# | | .&#8212;&#8212;&#8212;- day of month (1 &#8211; 31)<br \/>\n# | | | .&#8212;&#8212;- month (1 &#8211; 12) OR jan,feb,mar,apr &#8230;<br \/>\n# | | | | .&#8212;- day of week (0 &#8211; 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat<br \/>\n# | | | | |<br \/>\n# * * * * * user-name command to be executed<\/p>\n<p>[root@sunucucozumleri.com~]$<\/p>\n<p>\u0130lk d\u00f6rt sat\u0131r, zamanlanm\u0131\u015f g\u00f6revlerin kullanaca\u011f\u0131 kabuk de\u011fi\u015fkenlerini tan\u0131mlamaktad\u0131r.<\/p>\n<ul>\n<li><strong>SHELL<\/strong>\u00a0de\u011fi\u015fkeni zamanlanm\u0131\u015f g\u00f6revin hangi komut yorumlay\u0131c\u0131 ile \u00e7al\u0131\u015ft\u0131r\u0131laca\u011f\u0131n\u0131 g\u00f6sterir.<\/li>\n<li><strong>PATH<\/strong>\u00a0de\u011fi\u015fkeni ise zamanlanm\u0131\u015f g\u00f6revdeki komutlar\u0131n hangi klas\u00f6rlerde bulundu\u011funu g\u00f6sterir.<\/li>\n<li><tt><\/tt><strong>MAILTO<\/strong>\u00a0de\u011fi\u015fkeni, cron g\u00f6revlerinin \u00e7\u0131kt\u0131s\u0131n\u0131n hangi kullan\u0131c\u0131ya mail olarak g\u00f6nderilece\u011fini belirtir.\u00a0<strong><tt>MAILTO=\"\"\u00a0<\/tt><\/strong><tt>\u015feklinde yaz\u0131l\u0131rsa hi\u00e7bir kullan\u0131c\u0131ya mail gitmez.<\/tt><\/li>\n<li><strong>HOME<\/strong>\u00a0de\u011fi\u015fkeni ise zamanlanm\u0131\u015f komutun ev dizini olarak nereyi alg\u0131lamas\u0131 gerekti\u011fi g\u00f6sterilir.<\/li>\n<\/ul>\n<p><strong>Crontab S\u0131n\u0131rlamalar\u0131<\/strong><\/p>\n<p>Crontab\u2019i kullan\u0131c\u0131 ad\u0131n\u0131z \/etc\/cron.allow dosyas\u0131nda varsa veya b\u00f6yle bir dosya bulunmuyorsa ve ad\u0131n\u0131z \/etc\/cron.deny dosyasinda yoksa kullanabilirsiniz.<\/p>\n<p>T\u00fcm kullan\u0131c\u0131lar\u0131n Crontab\u2019i kullanabilmesi i\u00e7in cron.deny dosyas\u0131n\u0131n bulunmas\u0131 ve bo\u015f olmas\u0131 gerekir. cron.deny dosyasi bulunmuyorsa Crontab\u2019i yalnizca Root kullan\u0131c\u0131 kullanabilir.<\/p>\n<p><strong>Crontab Komutlar\u0131<\/strong><br \/>\n<strong>crontab -e<\/strong>\u00a0Crontab dosyasi bulunuyorsa d\u00fczenlemenizi, bulunmuyorsa yaratman\u0131z\u0131 sa\u011flar.<br \/>\n<strong>crontab -l<\/strong>\u00a0 Crontab dosyas\u0131n\u0131 g\u00f6sterir.<br \/>\n<strong>crontab -r<\/strong>\u00a0Crontab dosyas\u0131n\u0131 siler.<\/p>\n<p><strong>Crontab Dizilimi<\/strong><\/p>\n<p>Crontab dosyasi s\u0131ras\u0131 ile<\/p>\n<ul>\n<li>Dakika (<strong>0-59<\/strong>),<\/li>\n<li>Saat (<strong>0-23<\/strong>),<\/li>\n<li>Ayin G\u00fcn\u00fc (<strong>1-31<\/strong>),<\/li>\n<li>Ay (<strong>1-12<\/strong>),<\/li>\n<li>Haftanin G\u00fcn\u00fc (<strong>0-6<\/strong>) (<strong>Pazar = 0<\/strong>) alanlar\u0131n\u0131 ve \u00e7al\u0131\u015ft\u0131r\u0131lacak komutu bar\u0131nd\u0131r\u0131r.<\/li>\n<\/ul>\n<p>Bir alan i\u00e7in girilecek birka\u00e7 de\u011fer \u00a0\u201c,\u201d(virg\u00fcl) ile ayr\u0131labilir.<\/p>\n<p>\u00d6rnek Crontab Dosyasi Herg\u00fcn saat 18:30\u2019da \/tmp klas\u00f6r\u00fcndeki dosyalar\u0131 silen crontab sat\u0131r\u0131 a\u015fa\u011f\u0131daki gibidir.<\/p>\n<p><code> 30 18 * * *   rm \/home\/kullan\u0131c\u0131ad\u0131\/tmp\/*<\/code><\/p>\n<p>Asa\u011f\u0131da birka\u00e7 zamanlama \u00f6rne\u011fi ve \u00e7al\u0131\u015ft\u0131r\u0131lma zamanlar\u0131 verilmi\u015ftir.<\/p>\n<p>dak saat g\u00fcn\/ay ay g\u00fcn\/hafta \u00c7al\u0131\u015ft\u0131r\u0131lma Zaman\u0131<\/p>\n<p>30 0 1 1,6,12 * Ocak, Haziran ve Aral\u0131k aylar\u0131n\u0131n birinci g\u00fcn\u00fc saat 00:30\u2019da<\/p>\n<p>0 20 * 10 1-5 Ekim ay\u0131n\u0131n her Pazartesi ve Cumasi saat 20:00\u2019de<\/p>\n<p>0 0 1,10,15 * * Her ay\u0131n 1\u2019inde, 10\u2019unda ve 15\u2019inde gece yar\u0131s\u0131 (00:00)<\/p>\n<p>5,10 0 10 * 1 Pazartesileri ve her ay\u0131n 10. g\u00fcn\u00fcnde saat 12:05 ve 12.10\u2019da<\/p>\n<p>Email \u0130ptali Cron, \u00f6ntan\u0131ml\u0131 olarak i\u015flemi ger\u00e7ekle\u015ftirdi\u011finde kullan\u0131c\u0131ya email g\u00f6nderir. E\u011fer bunun gerekli olmad\u0131g\u0131n\u0131 d\u00fc\u015f\u00fcn\u00fcyorsan\u0131z a\u015fa\u011fidaki kodu cron g\u00f6rev satirinin sonuna eklemelisiniz. &gt;\/dev\/null 2&gt;&amp;1 \/dev\/null<\/p>\n<p>Unix benzeri i\u015fletim sistemlerinin ayg\u0131tlar dizininde (\/dev) bulunan \u00f6zel bir belgedir. Bu belgeye yaz\u0131lan her t\u00fcr ve her hangi miktarda olan veriyi sistem yok sayar ve yazan i\u015fleme EOF g\u00f6nderilir. Bu a\u00e7\u0131dan \/dev\/null bir kara deli\u011fe benzetilir.<\/p>\n<p>Yayg\u0131n kullan\u0131mlar\u0131ndan biri uygulamalar\u0131n istenmeyen \u00e7\u0131kt\u0131lar\u0131n\u0131, y\u00f6nlendirme arac\u0131l\u0131\u011f\u0131 ile, devre d\u0131\u015f\u0131 b\u0131rakmakt\u0131r.<\/p>\n<p>\u00c7\u0131kt\u0131s\u0131n\u0131 g\u00f6rmek istemedi\u011fimiz birbetik (script)i\u00e7in;<\/p>\n<p><code>[root@sunucucozumleri.com~].\/betik.sh &gt; \/dev\/null 2&gt;&amp;1<\/code><br \/>\n\u00dcstteki \u00f6rnekte, \u00f6nce &gt; arac\u0131l\u0131\u011f\u0131 ile ola\u011fan \u00e7\u0131kt\u0131 (1) \/dev\/null\u2019a y\u00f6nlendirilir.<\/p>\n<p>Sonra da 2&gt;&amp;1 ile hata \u00e7\u0131kt\u0131lar\u0131 (2) ola\u011fan \u00e7\u0131kt\u0131 ile ayn\u0131 y\u00f6ne g\u00f6nderilir.<\/p>\n<p>Contab dosyas\u0131na yapmas\u0131n\u0131 istedi\u011fimiz i\u015flemleri yaz\u0131yoruz.<\/p>\n<p>Bu i\u015flemler arka planda yap\u0131ld\u0131\u011f\u0131 i\u00e7in bunlar\u0131n kontrol etmek i\u00e7in \/var\/log\/cron dosyas\u0131n\u0131n \u00e7\u0131kt\u0131s\u0131na bakabiliriz.<\/p>\n<p>Cronjob Hakk\u0131nda birka\u00e7 ipucu<\/p>\n<p>G\u00f6revlerin \u00e7al\u0131\u015ft\u0131r\u0131lma zaman\u0131n\u0131 belirlerken birden fazla deger virg\u00fcl ile ayrilarak yazilabilir.<\/p>\n<p>Ayrica a\u015fag\u0131daki kodlar da i\u015flemin 1, 2, 5, 10 ve 15 dakika, 1, 2, 4 ve 6 saat ara ile \u00e7alistirilmasini saglar.<\/p>\n<p>Her dakika *\/1<br \/>\nHer saat *\/1<br \/>\n\u0130ki dakikada *\/2<br \/>\nIki saatte *\/2<br \/>\nBe\u015f dakikada *\/5<br \/>\nD\u00f6rt saatte *\/4<br \/>\nOn dakikada *\/10<br \/>\nAlt\u0131 saatte *\/6<br \/>\nOnbe\u015f dakikada *\/15<br \/>\nCronjobsta UNIX komutlar\u0131n\u0131n d\u0131\u015f\u0131nda PHP ve MySQL komutlarini da kullanabilmek i\u00e7in gerekli kodlar\u0131n yaz\u0131l\u0131 oldu\u011fu dosyan\u0131n GET methodu ile \u00e7agr\u0131lmasi yeterli olur.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Cronjobs Nedir? Cron istenilen g\u00f6revlerin belirli zaman aral\u0131klar\u0131 ile arkaplanda yap\u0131lmas\u0131na izin veren bir UNIX arac\u0131d\u0131r. Crontab (Cron TABle) Nedir? \u00c7al\u0131st\u0131r\u0131lacak g\u00f6revi ve g\u00f6revin \u00e7al\u0131st\u0131r\u0131lacag\u0131 zaman\u0131 bar\u0131nd\u0131ran dosyad\u0131r. Cron g\u00f6revlerini ayarlama A\u015fa\u011f\u0131da\u00a0\/etc\/crontab\u00a0dosyas\u0131 g\u00f6r\u00fclmektedir. [root@sunucucozumleri.com~]$cat \/etc\/crontab SHELL=\/bin\/bash PATH=\/sbin:\/bin:\/usr\/sbin:\/usr\/bin MAILTO=root HOME=\/ # For details see man 4 crontabs # Example of job definition: # .&#8212;&#8212;&#8212;&#8212;&#8212;- minute (0 &hellip;<\/p>\n","protected":false},"author":1,"featured_media":1456,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[5],"tags":[],"class_list":["post-1230","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux"],"acf":[],"_links":{"self":[{"href":"https:\/\/sunucucozumleri.com\/blog\/wp-json\/wp\/v2\/posts\/1230","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sunucucozumleri.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sunucucozumleri.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sunucucozumleri.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sunucucozumleri.com\/blog\/wp-json\/wp\/v2\/comments?post=1230"}],"version-history":[{"count":0,"href":"https:\/\/sunucucozumleri.com\/blog\/wp-json\/wp\/v2\/posts\/1230\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sunucucozumleri.com\/blog\/wp-json\/wp\/v2\/media\/1456"}],"wp:attachment":[{"href":"https:\/\/sunucucozumleri.com\/blog\/wp-json\/wp\/v2\/media?parent=1230"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sunucucozumleri.com\/blog\/wp-json\/wp\/v2\/categories?post=1230"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sunucucozumleri.com\/blog\/wp-json\/wp\/v2\/tags?post=1230"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}