Cron & crontab, ya bayyana

Lucaine buga wani lokaci da suka wuce kyakkyawan koyawa akan cron da crontab abin da nake ganin ya cancanci rabawa. Cron wani nau'in kwatankwacin Ayyuka ne wanda aka tsara a cikin Windows, kawai ana sarrafa shi daga tashar. Waɗanda suka fi son kallon gani don cimma manufa ɗaya, na iya ganin wannan wani labarin.

Menene cron?

Sunan cron ya fito ne daga Girkanci chronos wanda ke nufin "lokaci". A cikin tsarin aiki na Unix, cron shine manajan tsari na yau da kullun (daemon) wanda ke gudanar da matakai ko rubuce-rubuce a cikin tazara na yau da kullun (misali, kowane minti, rana, mako, ko wata). Ayyukan da dole ne a aiwatar da su da kuma lokacin da dole ne a aiwatar da su an ayyana su a cikin fayil ɗin crontab.

Yadda yake aiki

Cron daemon yana farawa daga /da dai sauransu/rc.d/ o /etc/init.d ya dogara da rarrabawa. Cron yana gudana a bango, yana duba teburin aikin crontab kowane minti / sauransu / crontab ko a / var / spool / cron don neman ayyukan da za a cim ma. Kamar yadda mai amfani za mu iya ƙara umarni ko rubutun tare da ɗawainiya don cron don sarrafa wasu matakai ta atomatik. Wannan yana da amfani misali misali don sanya atomatik tsarin aiki ko kuma kyakkyawan tsarin adana abubuwa.

Labari mai dangantaka:
Koyawa: Sanya .tar.gz da .tar.bz2 Kunshin

Menene Crontab?

Crontab fayil ɗin rubutu ne mai sauƙi wanda ke adana jerin umarnin da za a aiwatar a lokacin da mai amfani ya kayyade. Crontab zai duba kwanan wata da lokacin da yakamata a aiwatar da rubutu ko umarni, izinin izini kuma zaiyi shi a bangon. Kowane mai amfani na iya samun nasa fayil ɗin crontab, a zahiri / sauransu / crontab ana zaton shine asalin fayil ɗin mai amfani, yayin da masu amfani na yau da kullun (har ma da tushe) suke son samar da fayil ɗin crontab nasu to zamuyi amfani da umarnin crontab.

Crontab ita ce hanya mafi sauƙi don gudanar da ayyukan cron akan tsarin mai amfani da yawa, ko dai azaman mai amfani da tsarin mai sauƙi ko tushen mai amfani.

Yin amfani da crontab

Muna farawa da misali mai sauki.

Zamuyi aiki da sabunta tsarin ne, don kawar da bacin rai na "Kullum sai na sabunta kuma bana son hakan!"

yadda za a
Labari mai dangantaka:
Umarni don sanin tsarin (gano kayan aiki da wasu ƙayyadaddun software)

Da farko zamuyi rubutun. Wannan rubutun za'a kira shi ta cron kuma zai kunshi dukkan umarnin da muke so yayi, saboda haka ya zama dole a gwada shi a cikin lamura da dama kuma ta hanyoyi da dama kafin a saka shi a cikin cron, ingantaccen rubutun sabuntawa kamar haka:

#! / bin / bash #script update misalin # zabi kayan aikinka # debian-ubuntu # apt-samun sabuntawa & apt-get -y haɓakawa #fedora #yum -y sabuntawa #Arch #pacman --noconfirm -Syu

Cire # daga layin distro ɗinku. Idan ya kasance Ubuntu / Debian, zai fara da dace-samu.

Mun adana rubutun azaman update.sh (misali rubutun gidan ka). Muna canza izinin izinin aiwatarwar rubutun tare da:

chmod a + x ~ / rubutun / sabuntawa.sh

Muna aiwatar da rubutun sau biyu don tabbatar da cewa komai yana tafiya daidai, muna gyara abin da ya kamata (bazai sami kurakurai ba, in ba haka ba cron zai maimaita kuskure ne sau da yawa). Yanzu don ƙara aikin a crontab ɗin mu.

Tasksara ayyuka zuwa crontab

Muna aiwatar da bugun crontab tare da crontab -e, a wasu distros (kamar Ubuntu) yana bamu zaɓi mu zaɓi editan rubutu da muke so, sauran kuma an barmu da vi. Fayil na crontab zai yi kama da wannan.

# mh dom mon dow umarnin mai amfani

ina:

  • m ya yi daidai da minti ɗaya da za a kashe rubutun, ƙimar daga 0 zuwa 59
  • h ainihin lokacin, ana tafiyar da tsarin awa 24, ƙimar daga 0 zuwa 23, tare da 0 kasancewa 12:00 tsakar dare.
  • Dom yana nufin ranar wata, misali zaka iya tantance 15 idan kanaso kayi gudu duk bayan kwana 15
  • Dow na nufin ranar mako, yana iya zama adadi (0 zuwa 7, inda 0 da 7 suka kasance Lahadi) ko haruffa 3 na farko na ranar a Turanci: mon, tue, wed, thu, fri, sat, sun.
  • mai amfani - yana bayyana mai amfani wanda zai aiwatar da umarnin, yana iya zama tushen, ko mai amfani daban-daban matuƙar suna da izini don aiwatar da rubutun.
  • umurnin yana nufin umarni ko cikakkiyar hanyar rubutun don aiwatarwa, misali: /home/usuario/scripts/update.sh, idan ya kira rubutun dole ne a aiwatar dashi

Don bayyana 'yan misalai na ayyukan cron da aka bayyana:

15 10 * * * mai amfani /home/user/scripts/update.sh

Zai gudanar da rubutun update.sh da karfe 10:15 na safe a kowace rana

15 22 * * * mai amfani /home/user/scripts/update.sh

Zai gudanar da rubutun update.sh da karfe 10:15 na dare a kowace rana

00 10 * * 0 tushen dace-samu -y sabunta Tushen mai amfani

Zai fara aiki a duk ranar Lahadi da karfe 10:00 na safe

45 10 * * sun root apt-get -y sabuntawa

Mai amfani da tushen zaiyi aiki da sabuntawa kowace Lahadi (Rana) da karfe 10:45 na safe

30 7 20 11 * mai amfani /home/usuario/scripts/updata.sh

A Nuwamba 20 a 7:30 mai amfani zai gudanar da rubutun

30 7 11 11 mai amfani da rana /home/usuario/scripts/pastel_con_velitas.sh

A ranar 11 ga Nuwamba a 7:30 na safe kuma wannan Lahadi, mai amfani zai yi bikin sysadmin (ma'ana, ni)

01 * * * * mai amfani /home/usuario/scripts/molestorecordatorio.sh

Tunatarwa mai ban haushi kowane minti na kowane sa'a kowace rana (BA a ba da shawarar ba).

Ana iya sarrafa su har yanzu jeri na musamman:

30 17 * * 1,2,3,4,5

Da karfe 5:30 na yamma kowace rana daga Litinin zuwa Juma'a.

00**

A 12 na rana a ranar farko, goma sha biyar da 28 na kowane wata (manufa don biyan kuɗi)

Idan wannan yana da rikitarwa, crontab iyawa kebul na musamman don ayyana waɗannan jeri.

@ sake yi Run sau ɗaya, a farawa
@ yana gudana sau ɗaya kawai a shekara: 0 0 1 1 *
@ shekara-shekara iri daya da @yearly
@watanna yana gudana sau ɗaya a wata, ranar farko: 0 0 1 * *
@ mako-mako Mako na farko na farkon sa'a na mako. 0 0 * * 0 ″
@aily daily, da 12:00 A.M. 0 0 * * *
@midnight daidai da @daily
@hourly a farkon minti na kowane awa: 0 * * * *

Amfani da shi mai sauqi ne.

@hourly mai amfani /home/user/scripts/molestorecordatorio.sh @monthly mai amfani /home/user/scripts/backup.sh @daily root apt-get update && apt-get -y upgrade

Na ƙarshe amma ba mafi ƙaranci ba:

Gudanar da aikin Cron

fayil din crontab

Sauya fayil ɗin crontab na yanzu tare da ajiyayyen fayil ɗin mai amfani

crontab -e

Shirya fayil ɗin crontab na mai amfani, kowane sabon layi zai zama sabon aikin crontab.

crontab -l

Rubuta duk ayyukan crontab na mai amfani

Crontab -d

Share crontab ɗin mai amfani

crontab -c dir

Yana bayyana kundin adireshin mai amfani (wannan dole ne mai amfani ya rubuta kuma ya aiwatar da izini)

Crontab -u mai amfani

prefix don ɗaukar crontab na wani mai amfani, misalai:

$ sudo crontab -l -u tushen $ sudo crontab -e mai amfani2 #crontab -d -u mai amfani

Wannan kayan aikin, kamar sauran mutane, ana iya ganin su cikin zurfin ciki da daki-daki a cikin:

Godiya ga Lucain!

Abubuwan da ke cikin labarin suna bin ka'idodinmu na ka'idojin edita. Don yin rahoton kuskure danna a nan.

48 comments, bar naka

Bar tsokaci

Your email address ba za a buga.

*

*

  1. Mai alhakin bayanan: Miguel Ángel Gatón
  2. Dalilin bayanan: Gudanar da SPAM, gudanar da sharhi.
  3. Halacci: Yarda da yarda
  4. Sadarwar bayanan: Ba za a sanar da wasu bayanan ga wasu kamfanoni ba sai ta hanyar wajibcin doka.
  5. Ajiye bayanai: Bayanin yanar gizo wanda Occentus Networks (EU) suka dauki nauyi
  6. Hakkoki: A kowane lokaci zaka iyakance, dawo da share bayanan ka.

  1.   Alvaro Ortiz mai sanya hoto m

    Ugh ... dan rikicewa.

  2.   tonic m

    * / 30 ya ɓace (a cikin filin mintuna) wanda ke gudana kowane minti 30 ...

    1.    erm3nda m

      Zan yi sharhi a kan wannan har sai na yanke shawarar yin nazarin maganganun 😀
      Wannan gyararren bayani ne mai matukar muhimmanci kuma abu ne mai matukar amfani.

      1.    Kika m

        Hello!
        A yanzu haka ina gwada jituwa kowane minti 45.

        * / 45 * * * *, kuma ana aiwatar da umarnin a mintuna 45 na kowane awaI DA kowace awa. Wannan yana nufin:

        Yana gudana a 3:45, sannan 4:00, 4:45, sannan 5:00, 5:45, 6:00, 6:45, da sauransu.

        Ina da wani abu da ba daidai ba? Me zan iya yi don kawai ya kasance kowane minti 45, ko aƙalla sau ɗaya a minti 45 a kowace awa.

    2.    Kika m

      Hello!
      A yanzu haka ina gwada jituwa kowane minti 45.

      * / 45 * * * *, kuma ana aiwatar da umarnin a mintuna 45 na kowane awaI DA kowace awa. Wannan yana nufin:

      Yana gudana a 3:45, sannan 4:00, 4:45, sannan 5:00, 5:45, 6:00, 6:45, da sauransu.

      Ina da wani abu da ba daidai ba? Me zan iya yi don kawai ya kasance kowane minti 45, ko aƙalla sau ɗaya a minti 45 a kowace awa.

  3.   slack m

    Barka dai yayi amfani sosai da bayanin don bayyana yadda cron yake aiki.
    Bytes

  4.   slack m

    don *

  5.   Mafarauta m

    Madalla, godiya saboda bayanin yadda cron yake aiki .. bari mu sanya ɗan hannu 🙂

  6.   Yakubu m

    Wannan layin kamar yadda na fahimta za a zartar da shi ne da karfe 10:15 na dare, a gyara ni idan na yi kuskure
    Da kyau can yana cewa 10:15 am
    15 22 * * * mai amfani /home/user/scripts/update.sh

  7.   Agustin m

    Barka dai! kyakkyawan bayani.
    Don aiwatar da Rubutun kowane rabin sa'a, layin da ya kamata a ƙara zuwa CronTab zai zama: "30 * * * * tushen Scrip.sh" Daidaita? Na gode sosai!

  8.   bari muyi amfani da Linux m

    A'a Idan na tuna dai dai, don haka dole ka sanya / 30 * * * * tushen Scrip.sh.
    Wato, ƙara / kafin 30.
    Murna! Bulus.

  9.   Jonathan m

    Barka dai, naji daɗin post ɗin ku, ya cika sosai amma ina so in tambaye ku wani abu.
    Ina samun matsala game da wannan umarnin kuma daya kamar "at".

    Ina so in gudanar da rubutu a wani lokaci in sanya

    at -f /home/mi_user/Desk/script.sh 18:08 misali

    kuma ba a aiwatar da rubutun a kan allo ba, wato, a cikin tashar, ana aiwatar da shi a bango?

    Kuma da cron irin wannan abu ya faru da ni, na gyara fayil ɗin crontab tare da "crontab -e"

    a karshen na kara wannan layin:

    46 19 my_user /home/mi_user/Desk/script.sh

    kuma baya yin komai, baya nuna rubutun.

    Wani shawara? Na gode sosai da neman afuwa game da duk wata damuwa

    1.    bari muyi amfani da Linux m

      Domin tashar ta bayyana, maiyuwa ne ya fara amfani da tashar sannan ya wuce rubutun a matsayin siga.

      Alal misali:

      lxterminal -e "my_user /home/mi_user/Desktop/script.sh"

      Sigar don amfani zata iya bambanta dangane da tashar emulator da kuke amfani da ita.

      Ina fatan zai yi aiki

      Rungume! Bulus.

  10.   patrecas m

    An yaba da gudummawar.

    10 maki !!

    sallah 2!!

  11.   Rodolfo m

    Na gode kwarai da gaske, ya taimaka min matuka wajen bayyana wasu abubuwa, jimillar godiya, don karin bayani ko shakku zan je SHAFIN MUTUM, na sake gaishe gaisuwa.

  12.   jahir m

    mutum na gode sosai, Na kasance ina karantawa ina gwada misalai. na gode sosai ... yana da matukar fahimta. Murna

  13.   geovanni m

    Na yi amfani da Ubuntu Server 12.04.2 LTS, da sigar crontab da nake da ita, don share jerin ayyukan mai amfani ana amfani da, crontab -r (da -l, kamar yadda wannan littafin ya faɗi). Tabbatar da shi ne ta hanyar tambaya na iri.

    A gefe guda, sau ɗaya kawai na gudu kawai crontab kuma irin wannan bari in ƙirƙiri fayil na kisa, amma wannan ba ita ce ake kashewa ba. Wanda ke gudana shine wanda yake cikin / etc / crontab. wataƙila wani zai yi amfani da sharhin.

    PS (Ina bincika tare da ganowa kuma ina crontab amma sai kawai ya dawo da adireshin da aka ambata da wani fayil wanda aka ɓoye, don haka idan wanda aka zartar shine wanda yake cikin / sauransu / crontab, amma lokacin da na zartar da umarnin crontab -e, sai na bayyana tare da duk ayyukan da na bayyana) a ina aka ajiye wannan fayil ɗin '???? Gaisuwa. Kullum ina shiga tare da tushe.

  14.   Sebastian m

    Madalla, da amfani sosai !!!

  15.   Mmm m

    Barka dai, ina son yin wannan ………… «15 10 * * * tushen ifdown eth0»

    ma'ana a wani lokaci an cire katin hanyar sadarwa ………… da kyau, na sanya shi a cikin crontab kuma bai yi aiki ba …… .. me ke faruwa?

    Gaisuwa da godiya

  16.   Miguel m

    Ka rasa ma'anar "mon" bayan taken "tasksara ayyuka zuwa crontab"

    Labarin har yanzu yana da kyau, cron yana da amfani ƙwarai.

  17.   Oscar m

    Yaya sanyi wannan kyakkyawan sakon, tambayata
    Idan ina so in ci gaba da lura da bayanan da aka bari ta hanyar aiwatar da ayyuka, a ina zan ganta?

    ina yanke hukunci Ina so in ga tarihin ayyukan da aka yi a baya na wannan fayil ɗin kuma ina so in ga wanda ya gyara shi da kwanan wata

    gracias

  18.   Oscar m

    Ina so in duba tarihin gyara wannan

    yaya zan iya yi

    gracias

  19.   Andres Ledo m

    Da safe,

    Ina tsammanin cewa a cikin rubutun ubuntu kunyi kuskure, kun sanya haɓaka-ap-get -y maimakon inganta-samu -y haɓakawa. (Kun bar wani t).

    A gaisuwa.

    1.    bari muyi amfani da Linux m

      Hakanan haka ne. Na gode!
      Rungume! Bulus

  20.   Gabriel m

    Ina so in san yadda ake ƙirƙirar fayil ɗin cron don samun damar tantance lokacin kowannensu lokacin da aka aiwatar da shi, kundin adireshi, da sauransu.

  21.   Valentin m

    Godiya don bayyana aikin da ƙa'idodi na asali don cron, yanzu don nishadantar da kanku ɗan kaɗan.

  22.   Sander m

    Duk lokacin da na nemi bayani a kan kowane batun da ya shafi Gnu / Linux sai na zagaya zagaye a karshen koyaushe ina samun kashi 90% na shari'o'in da suka fi dacewa a cikin wannan babbar al'umma, Ina ganin daga yanzu zan fara nan sannan kuma a wani wuri.

    gaisuwa

    1.    bari muyi amfani da Linux m

      Na gode Sander! Rungumewa! Bulus.

  23.   dario m

    dom = ranar wata
    dow = ranar mako
    da sauki idan kunyi tarayya

  24.   Ƙasiri m

    Na gode sosai, wannan cikakke ne kuma an bayyana shi da kyau.

  25.   Maxilia m

    Wannan shine irin abinda malamin OS dinmu ya bamu, ban canza komai ba, yanzu na ga dalilin da yasa aji yayi muni .-. To, wannan daidai yake da aikin gida xD

  26.   Marcelo m

    Kimanta,

    Tambaya, ana iya iyakance lokacin aiki?
    Misali Ina da wani aiki da ake maimaitawa kowane minti 5, kan maimaitawa idan wannan aikin har yanzu yana aiki, kashe shi kuma sake gudu.

    Na gode,
    Marcelo -.

    1.    bari muyi amfani da Linux m

      Sannu, Marcelo!

      Ina tsammanin zai fi kyau idan kun gabatar da wannan tambayar a cikin tambayoyinmu da sabis ɗin amsar da ake kira Tambayi Daga Linux domin dukkan al'umma su taimake ku game da matsalar ku.

      Runguma, Pablo.

  27.   aj m

    kyakkyawan matsayi.
    Mene ne umarni a kowane tashar don ƙara ayyuka a cikin crontab (ba tare da shiga crontab ba kuma ƙara su da hannu tare da 'crontab -e' ko maye gurbin crontab ɗin tare da wani ƙirar tare da 'fayil ɗin crontab').
    Manufar ita ce ƙirƙirar rubutun waje don ƙara ayyuka zuwa crontab
    Gracias

    1.    david m

      da alama a gare ni cewa zaku iya amfani da 'echo' duk abin da kuke son ƙarawa '| cat >> 'Hanyar cronotab (/ sauransu / cronotab)' «

  28.   Raphael Vera m

    Ta yaya magana zata gudana kowane kwana 3 daidai

  29.   Jose Antonio m

    Hello.

    Ina da matsala wajen aiwatar da aikin cron.

    Ina gudanar da wannan aiki tare da cronta -e:

    01 * * * * tushen /home/user/script/mfile.sh

    amma ba a yi aikin ba. Na tabbatar cewa myfile.sh yana da izinin aiwatarwa kuma mai amfani wanda ya aiwatar da shi tushe ne.

    Ina gudanar da aiki iri ɗaya a cikin / sauransu / crontab kuma bayan sake farawa sabis ɗin, shima baya aiki a gare ni.
    Abun cikin myfile.sh umarni ne wanda yake sabunta DB kuma idan nayi amfani dashi a cikin na'urar wasan yana aiki.
    wani ra'ayin menene matsalar na iya zama?

    1.    fred m

      Da alama mai amfani da bayanan ba shi da dukkan izini kuma da farko za ku fitar da masu canjin yanayi daga injin bayanan ku.
      Misali a cikin db2 wannan layin zai tafi farkon rubutun
      . / gida / db2inst1 / sqllib / db2profile

      Wani dalili kuma na iya kasancewa rubutun yana buƙatar haɗi zuwa bayanan bayanan, sanya haɗin kan bayanan cikin rubutun

  30.   LA3 m

    Ban san cewa dole ne in sake farawa ba, na kasance ina yaƙi da wannan na ɗan lokaci

  31.   Kenya m

    Za su san yadda za su nuna cewa ana gudanar da aikin a kowane ƙarshen wata, a lokacin da aka nuna .. cikakken bayanin shi ne cewa ba zan iya cimma yadda na san shi ya ɗauki ranar ƙarshe ta kowane wata ba .. ??? Dole ne in rubuta su daya bayan daya amma idan karshen watan Fabrairu ya zo da cewa biciesto yana da wahala a gare ni ..

  32.   Yesu m

    ina kwana!!

    Ta yaya zan dakatar da aikin da ake aiwatarwa a cikin crontab?

  33.   Yesu m

    aiwatar * …………

  34.   Julianna m

    Shin zai iya zama kun taimake ni? eu tenho um rubutun da minha ya wallafa wanda baya aiki babu crontab! jб dei duk masu izinin, babu takamaiman mai ba da sabis ko mai amfani wanda zai iya aiwatar da shi-mafi yawan abin da ya faru! Ina so in san ko zaku iya taimaka mani, wasu abubuwan ba su aiki ba! Vlws

  35.   Anthox m

    Ta yaya zaku sanya aiki don gudanar da kowace ranar ƙarshe ta wata (ranaku: 31-30-28)?

  36.   tafe m

    Kamar yadda kuka sani, ana amfani da umarnin su don canza mai amfani a cikin na'ura mai kwakwalwa. Idan na yi amfani da umarnin su kamar haka: "mai amfani da ku" ya canza mai amfani amma ba tare da saitunan da ya dace na "mai amfani" ba, idan na gudu su kamar haka: "su - mai amfani" canza mai amfani ta hanyar loda saitunan mai amfani. Tare da cron nake nuna mai amfani, amma ta yaya zan ɗora bayanan wannan mai amfanin?

  37.   Rob m

    Kuma idan ina so in dakatar da shi?

  38.   Reg m

    Sannu,
    Ban san abin da nake kuskure ba, amma na bi matakai kuma ba a aiwatar da komai. Na gwada:
    59 * * * * / usr / bin / gedit
    * * * * * / usr / bin / gedit
    * * * * * tushen / usr / bin / gedit
    * * * * * usr / bin / test.sh
    * * * * * tushen usr / bin / test.sh

    kuma babu komai. Ba ya aiwatar da komai. Na sake kunnawa da komai.

  39.   Ferqos m

    muchas gracias