Cov vev xaib tuaj yeem Tso Teem Caij Ua Haujlwm nrog Cron

moos

Peb muaj ib tug xov tooj ntawm redundant xyuas systems nyob rau hauv kev ua hauj lwm uas tsis tu ncua ua cov txheej txheem. Ib txhia khiav txhua feeb, qee qhov ib zaug ib hmos nyob ntawm seb lawv ua dab tsi. Piv txwv li, peb yuav txim tuag ib tsab ntawv uas xa tawm txhua tus neeg siv khoom uas tsis tau ua yuav khoom hauv 30 hnub xa lawv daim coupon.

Ntau dua li sim ua qhov kev soj ntsuam tag nrho cov no los ntawm txhais tes, nws yooj yim dua rau kev tsim cov haujlwm uas tau teem caij thiab tua. Ntawm Unix-based systems, qhov no ua tiav nrog Cron. Rau koj cov neeg koj paub uas koj ua dab tsi, xav qhia ntawv rau kuv thiab cov neeg nyeem yog tias kuv pov cov ntaub ntawv twg tawm.

Nws tsis muaj hmoo, tab sis cov neeg tsim tawm web raug tsis paub nrog Cron txhua. Txawm hais tias lawv nyob, lub web hosting tuam txhab feem ntau tsis muab kev nkag mus rau, los yog kev txhawb nqa ntawm, Cron. Kuv tus tswv tsev yog ib qho ntawm tom kawg - lawv tso cai rau koj siv nws, tab sis lawv tsis txhawb nws.

Cron yog dab tsi?

Cron yog muaj npe rau lo lus Greek Chronos, lub ntsiab lus lub sij hawmCov. Cron khiav hauv lub voj tas mus li los khiav cov haujlwm uas tau sau los ntawm Crontab (kab tias muaj npe rau tabulator. Cov haujlwm no feem ntau hu ua Cronjobs, thiab tuaj yeem siv cov ntawv sau hauv koj lub xaib.

Cron Daim Duab piav qhia Piav Qhia

Kuv yuav teeb lub Crontab li cas?

Tau txais Cron los ua qhov kev sib tw yeej yog qhov nyuaj, yog li ntawm no yog qhov kuv kawm thiab kuv yuav ua li cas rau Yog Suck:

  1. Kuv teeb kuv tsab ntawv los tshawb xyuas Twitter's API saib seb puas muaj leej twg teb rau @ifsuckCov. Kuv muab cov lus sib piv rau cov lus uas kuv tau khaws cia hauv lub vev xaib, nkag mus rau ib qho tshiab.
  2. Thaum cov ntawv sau tau ua haujlwm, Kuv tau tso cai pom zoo rau Tus Neeg Siv los ua cov ntawv (744) thiab ntxiv cov ntawv sau rau kuv Cronjob cov ntaub ntawv - ntxiv rau ntawd tom qab.
  3. Kuv ces yuav tsum tau nkag mus rau kuv lub vev xaib ntawm SSH. Ntawm lub Mac, uas muab qhib Terminal thiab ntaus ntawv SSH username@domain.com qhov twg cov npe nkag yog lub npe Kuv xav siv thiab sau yog lub vev xaib. Kuv ces tom qab ntawv rau thiab muab tus password.
  4. Kuv mam li sim khiav cov ntawv ncaj qha los ntawm qhov kev hais kom ua los ntawm kev ntaus lub filename thiab txoj kev txheeb ze ntawm lub server: /var/www/html/myscript.php
  5. Thaum kuv tau txais nws ua haujlwm kom raug, Kuv tau ntxiv Unix code tsim nyog hauv thawj kab ntawm cov ntawv: #! / usr / rau hauv / php -q Cov. Kuv ntseeg tias qhov no tsuas yog qhia Unix kom siv PHP txhawm rau ua tsab ntawv.
  6. Ntawm cov kab hais kom ua Terminal kab, Kuv ntaus crontab (lwm tus yuav xav ntaus crontab -e) thiab ntaus ntaus… thiab qhov ntawd yog txhua yam uas xav tau!

Syntax rau koj Cov Ntaub Ntawv Cronjob

Hais txog # 2 saum toj no, Cron siv tus txheej txheem sib txawv rau kev txiav txim thaum koj cov ntawv yuav raug tua. Qhov tseeb, koj tuaj yeem tuaj yeem luam thiab muab qhov no rau hauv koj Cronfile (ntawm kuv tus tswv, nws tau nyob hauv / var / spool / cron / nrog lub filename tib yam li kuv lub npe).

# + —————- feeb (0 - 59)
# | + ————- teev (0 - 23)
# | | + ———- hnub ntawm lub hlis (1 - 31)
# | | | + ——- hli (1 - 12)
# | | | | + —- hnub ntawm lub lim tiam (0 - 6) (Hnub Sunday = 0 lossis 7)
# | | | | |
* * * * * * /var/www/html/myscript.php

Qhov saum toj no yuav ua rau kuv cov ntawv sau cia txhua feeb. Yog tias kuv tsuas xav kom nws khiav ib zaug ib teev, Kuv tsuas yog yuav tso pes tsawg feeb tom qab teev uas kuv xav kom nws khiav, yog li nws yog ntawm 30 feeb cim:

30 * * * * /var/www/html/myscript.php

Nco ntsoov tias koj teeb cov ntawv tso cai rau cov ntaub ntawv no ua tiav, ib yam nkaus! Kuv pom tias syntax, kev tso cai, thiab kev ua cov crontab los ntawm Lub Pob Zeb Terminal yog qhov tseem ceeb tshaj plaws. Txhua zaus kuv yuav rov pib dua cov ntaub ntawv, Kuv yuav pom kuv cov kev tso cai xav tau rov pib dua thiab!

Hloov tshiab: Yog tias koj xav kom ntseeg tau cov haujlwm tau khiav, ib txoj kev yooj yim yog los hloov cov chaw khaws ntaub ntawv nrog lub sijhawm kawg ntawm tsab ntawv tau tsim. Yog tias nws muaj qhov tsis tshua muaj txiaj ntsig, koj tsuas yog sau ntawv email xa mus rau koj tus kheej.

Cov Khoom Siv Cron Ntxiv:

Koj muaj pes tsawg txoj haujlwm koj tuaj yeem siv siv Cron?

8 Comments

  1. 1

    Zoo hais txog tsab xov xwm ntawm kev teeb tsa cron, rau ib tus neeg tshiab rau crojobs, qhov nyuaj tshaj plaws nyob rau hauv kev teeb tsa cron yog xam qhov cronjob tiav lub sijhawm, thiab nws yog qhov sib txawv kom tau txais lub sijhawm tsis raug ntawm thawj zaug. Yog tias koj lub cronjobs yog lub sijhawm nkag siab, nws yog qhov zoo uas yuav suav nrog qee cov lej hauv tsab ntawv los ncha tawm cov xwm txheej yog li koj tau khaws cia cov ntaub ntawv ntawm txoj haujlwm kev ua haujlwm.

  2. 2

    Kuv tuaj los Doug,

    Ob peb yam xav txog thaum ua haujlwm nrog cov haujlwm cron.

    Ua ntej, tom qab ob peb lub kaum os, koj yuav xav koj muaj ib daim UI, ib qho chaw nyob thiab nrhiav cov lus Askiv uas siv lus Askiv

    Thib ob, cron yuav taws tawm haujlwm nyob rau lub sijhawm tau hais tseg, tsis hais seb puas muaj kev thov ua haujlwm dhau los. Yog li khiav txoj haujlwm ib zaug ib feeb uas siv 2 feeb yuav ua rau ntau cov hauj lwm tib si khiav.

    Tom ntej no, tom ntej no tsis muaj qhov tsis ceeb toom qhia kev ua yuam kev thaum muaj ib yam dab tsi mus tsis yog, yog li koj yuav tsum tau sau koj tus kheej qhov ceeb toom yuam kev.

    Kuv twb hais txog qhov no ob peb txoj kev:
    - muaj daim ntawv thov triggered ntawm cron saib hauv ib qho chaw khaws ntaub ntawv los txiav txim seb dab tsi yuav tsum tau khiav. Khiav nws ib zaug ib feeb lossis teev nyob ntawm seb koj xav tau
    - muaj txhua tsab ntawv tsim lub 'xauv' cov ntaub ntawv hauv / tmp thiab yog tias nws tshwm sim, tsis txhob pib dua, qhov no tiv thaiv cov haujlwm duplicate yog tias koj tsis xav tau
    - yog tias tsab ntawv pom lub xauv cov ntawv loj dua 1 teev (lossis dab tsi qhia tias koj tuag) xa email ceeb toom
    - muaj tsab ntawv xa email ntawm kev tsis ua tiav ntawm txoj haujlwm kom koj paub tias muaj qee yam tsis raug
    - saib cov qauv siv xws li Flux lossis cov chaw tsim khoom lag luam thaum koj cov kev xav tau dhau dhau ntawm ob peb cov ntawv sau

    Chris

  3. 4

    Kuv tseem yuav ntxiv ntxiv tias feem ntau ntawm Linux / Unix systems, "crontab -e" yog qhov koj siv los kho koj tus crontab. Kuv xav tias koj tus tswv tsev (Jumpline) siv qhov hloov kho tshiab rau kev nyab xeeb vim li cas.

  4. 5

    Kuv tseem nco qab thawj hnub uas kuv ntsib Cronnie. Kuv tau hnov ​​ntau yam txog nws, tias nws tso siab tau rau txhua lub sijhawm, tab sis qee zaum kuj tsis meej pem txog nws qhov kev mob siab.

    Kuv pom qhov no muaj tseeb vim tias nws yog tus qhia tsis meej rau kuv thaum xub thawj. Tom qab nug ib ncig ntawm nws, Kuv ntes tau ncaj ncaj raws li qhov nws nyiam ua haujlwm. Tam sim no, Kuv tsis tuaj yeem xav txog ib hnub dhau mus yam tsis muaj nws nyob hauv kuv lub neej. Nws ua rau mundane zoo siab heev, thiab tau nqa ntau lub nra ntawm kuv lub xub pwg.

    Hauv qhov tiag, Kuv xav tias kuv tsuas yog kos lub nplaim nrog dab tsi kuv tuaj yeem siv zog nrog cov haujlwm cron. Lawv tiag tiag yog tus phooj ywg tsim kho zoo tshaj plaws. Yog tias koj tab tom siv ib tus neeg zoo li CPanel los tswj koj cov neeg rau zaub mov, nws muaj ntau tus phooj ywg zoo dua los tsim cov crons. Ua kom tiav nrog tso cov menus rau feeb, teev, hnub, hli, thiab lwm yam uas tsim txoj kab xov tooj rau koj.

  5. 7

    Kuv pom tseeb tias qhov no yog qee yam uas txhua tus tub lag luam yuav tsum tau siv… Puas muaj ib tus neeg tuaj yeem muab cov kev pabcuam no vim tias nws zoo li me ntsis “techy”?

Yuav ua li cas koj xav hais tias?

Qhov Web site no siv Akismet los txo cov kev pabcuam. Kawm li cas koj cov ntaub ntawv tawm tswv yim tiav.