Cov ntxiab: ua rau koj cov ntawv bash zoo dua

Dej das thoob lub teb chaws network Kuv tuaj hla ib nthuav xov xwm (uas kuv coj tuaj ntawm no qhov ntawv vim tias nws tau piav qhia meej) qhov twg nws cov kws sau qhia peb paub yuav ua li cas kom peb Bash scripts ntxiv zog siv cuab.

Ua kom koj cov ntawv bash ntau zog nrog cov ntxiab

Xav txog tias koj muaj cov ntawv sau bash uas sau txhua hnub txhua rau teev thiab nyob rau qee kis nws poob los yog tib tsab ntawv sau ob zaug ua ke. Ob qhov xwm txheej no tsis yooj yim vim lawv yuav tsum muaj kev cuam tshuam los ntawm tib neeg los kho qee lub sijhawm lossis qee lub sijhawm lawv tsis tuaj yeem daws qhov teebmeem, tawm hauv lub system mus rau lub xeev tsis sib haum Kev daws rau qhov no, ntawm lwm tus, yog siv ntxiab.

Ntxiab yog txoj kev yooj yim thiab ua tau zoo los tswj kev tawm ntawm bash scripts. Cia peb rov qab mus rau qhov xwm txheej thawj zaug, yog tsab ntawv nres manually, piv txwv li nrog ctrl-c, nws cuam tshuam los rov xa cov teeb liab tawm

INT

thiab yog tias nws xaus nrog

kill

ces cov zis yuav tau

TERM.

Txhua txoj kev tawm tau tuaj yeem pom nrog

kill -l

Txawm li cas los xij, feem ntau siv yog qhov tseeb

INT, TERM, RAU HAUV

Yog hais tias tsab ntawv muaj, piv txwv li, ntawm cov ntaub ntawv synchronization nrog

rsync

qhov kev txiav txim siab zoo tshaj plaws yog cia siab rau ntawv cov ntaub ntawv uas tsis pub dhau ntawm cov ntawv sau ua ke:

XAUV = "/ var / khiav / rsync.lock" yog [! -e $ LOCK]; ces kov $ LOCK rsync -avz foo bar rm $ LOCK lwm echo "rsync twb khiav" fi

Hauv cov lus Mev meej, cov ntawv sau saum toj no yog tias cov ntaub ntawv kaw thiab yog tias nws tsis muaj, nws tsim nws thiab tom qab ua tiav cov lus sib thooj, thaum kawg muab cov ntawv kaw. Yog tias qhov ntawv tshwm sim, tsab ntawv tsuas yog xa ib cov lus rau tus neeg siv qhia tias qhov lus txib twb khiav lawm.

Txawm li cas los xij thaum muaj teeb meem qhov teeb meem nws tuaj yeem tshwm sim tias lub xauv cov ntaub ntawv tsis raug tshem tawm, rhuav tshem cov kev xav tsis zoo. Kev daws yog yooj yim heev:

XAUV = "/ var / khiav / rsync.lock" yog [! -e $ LOCK]; tom qab ntawd cuab "rm -f $ LOCK; tawm" INT TERM EXIT kov $ LOCK rsync -avz foo bar rm $ LOCK cuab - INT TERM EXIT lwm echo "rsync twb khiav" fi

Qhov tshwj xeeb ntawm qhov kev daws no yog tias qhov kev hais kom tau ntim rau hauv cov ntxiab, yog li ntawd thaum lub teeb liab tau txais

INT, TERM, RAU HAUV

tsab ntawv nres thiab rhuav tshem lub xauv cov ntaub ntawv.

Nws yog tsim nyog hais tias tej zaum yuav muaj kev sib tw ntawm cov ntawv sau saum toj no nyob nruab nrab ntawm lub sijhawm cov ntaub ntawv kaw tau tshawb xyuas qhov tseeb thiab lub sijhawm nws tsim. Tau txais ib qho kev daws teeb meem yuav tau siv ib qho hloov pauv thiab bash's noclobber hom uas tsis hloov rau cov ntawv uas twb muaj lawm:

XAUV = "/ var / khiav / rsync.lock" yog (teev -o noclobber; ncha $$> "$ LOCK") 2> / dev / thov; tom qab ntawd cuab 'rm -f "$ LOCK"; tawm $? ' INT TERM EXIT rsync -avz foo bar rm -f $ LOCK kev ntxiab - INT TERM EXIT lwm tus ncha "rsync twb khiav lawm: $ (miv $ LCK)" fi

Qhov peculiarity ntawm tom kawg yog tias nws yog siv raws li kuv tau hais lawm, tus tsis siv hom thiab tias cov ntaub ntawv kaw muaj PID ntawm cov txheej txheem uas tau raug tua.

Nws tseem tsim nyog teev tias muaj lwm cov kev daws teeb meem xws li

flock

o

solo

txawm li cas los xij hauv no ncej Kuv xav qhia cov kev daws teeb meem nrog bash tus kheej cov peev txheej. Koj tuaj yeem kawm me ntsis ntxiv txog Traps nrog qhov no qhia zoo.


Cov ntsiab lus ntawm tsab xov xwm ua raws li peb cov ntsiab cai ntawm kev tswj hwm kev ncaj nceesCov. Tshaj tawm ib qho yuam kev nyem no.

5 lus, tawm koj li

Tso koj saib

Koj email chaw nyob yuav tsis tsum luam tawm.

*

*

  1. Lub luag haujlwm rau cov ntaub ntawv: Miguel Ángel Gatón
  2. Lub hom phiaj ntawm cov ntaub ntawv: Tswj SPAM, kev tswj xyuas tawm tswv yim.
  3. Sau raws cai: Koj kev tso cai
  4. Kev sib txuas lus ntawm cov ntaub ntawv: Cov ntaub ntawv yuav tsis raug xa mus rau lwm tus neeg thib peb tsuas yog los ntawm kev txiav txim siab raug cai.
  5. Cov ntaub ntawv khaws cia: Cov Ntaub Ntawv khaws tseg los ntawm Occentus Networks (EU)
  6. Txoj Cai: Txhua lub sijhawm koj tuaj yeem txwv, rov qab thiab tshem tawm koj cov ntaub ntawv.

  1.   Raphael Castro said

    Zoo heev! Tsaug rau sib qhia.

  2.   nx said

    Cov tshooj lus zoo, tsuas yog hloov 'ncha "rsync twb khiav lawm: $ (miv $ LCK)"' rau 'ncha "rsync twb khiav lawm: $ (miv $ LOCK)"'

    regards

  3.   dglangos said

    Ib tsab xov xwm nthuav heev, yog Tswv! Qhov no kuv thiaj.

  4.   Joaquin said

    Nws yog ib qhov lus txib muaj txiaj ntsig zoo rau hauv siab. Kuv siv nws hauv tsab ntawv uas kuv luam tawm hauv kev tshaj xo, kom rho tawm qee cov ntaub ntawv uas tsab ntawv tsim thaum nws nres.

  5.   DaniFP said

    Lus hauv no teb Nthuav heev, yawg.