Imigibe: yenza izikripthi zakho ze-bash zomelele ngakumbi

Ukujonga ujongano lwelizwe ndafumana a Inqaku elinomdla (endizisa apha ngokubhaliweyo kuba icaciswe kakuhle) apho umbhali waso esibonisa indlela yokwenza izikripthi zethu zeBash zomelele ngakumbi sisebenzisa Iingxube.

Yenza izikripthi zakho ze-bash zomelele ngakumbi ngemigibe

Khawufane ucinge ukuba une-bash script eqhuba yonke imihla rhoqo emva kweeyure ezintandathu kwaye ngamanye amaxesha iyaphazamiseka okanye iskripthi esifanayo sihamba kabini ngaxeshanye. Ezi meko zimbini azonwabanga kuba zifuna ukungenelela kwabantu ukuba kulungiswe okanye ngamanye amaxesha kungenziwa ukuba kusonjululwe, kushiya inkqubo ikwimeko yokungahambelani. Isisombululo soku, phakathi kwabanye, kukusebenzisa imigibe.

Imigibe yindlela elula nesebenzayo yokulawula ukuphuma kweempendulo ze-bash. Masibuyele kwimeko efanayo, ukuba iskripthi simisiwe ngesandla, umzekelo nge-ctrl-c, iphazamisekile ukubuyisa umqondiso wokuphuma

INT

kwaye ukuba iphela ngo

kill

ke imveliso iya kuba

TERM.

Zonke iikhowudi zokuphuma ezinokubakho zinokujongwa kunye nazo

kill -l

Nangona kunjalo, ezona zisetyenzisiweyo zichanekile

INT, IKOTA, Phuma

Ukuba iskripthi siqukethe, umzekelo, wokuvumelanisa iifayile kunye

rsync

eyona nto inengqondo kukuxhomekeka kwifayile yokutshixa engavumeli iskripthi ukuba sisebenze ngaxeshanye:

LOCK = "/ var / run / rsync.lock" ukuba [! -e $ LOCK]; chukumisa i-LOCK rsync -avz foo bar rm $ LOCK enye i-echo "rsync sele isebenza" fi

Ngokucacileyo iSpanish, iskripthi esingentla sijonga ukuba ngaba ifayile yokutshixa ikhona kwaye ukuba ayikho, iyayenza emva koko iphumeze umyalelo ohambelana nayo, ekugqibeleni isuse ifayile yokutshixa. Ukuba ifayile ikhona, iskripthi sithumela umyalezo kumsebenzisi obonisa ukuba umyalelo sele usebenza.

Nangona kunjalo xa kukho imeko enengxaki kunokwenzeka ukuba ifayile yokutshixa ayipheliswa, konakalise iziphumo ezingafunekiyo. Isisombululo silula:

LOCK = "/ var / run / rsync.lock" ukuba [! -e $ LOCK]; emva koko "umgibe"

Ukubaluleka kwesi sisombululo kukuba umyalelo ufakwe kwisicupho, ukuze xa kufunyenwe umqondiso

INT, IKOTA, Phuma

Iskripthi siyema kwaye siyicime ifayile yokutshixa.

Kuyimfuneko ukuba kunokubakho imeko yokhuphiswano kwiskripthi esingentla phakathi kwexesha lokuvavanywa kwefayile kunye nexesha eyenziweyo ngalo. Isisombululo esinokubakho kukusebenzisa ukuhambisa kwakhona kunye ne-bash's noclobber mode engahambisi kwifayile esele ikho:

LOCK = "/ var / run / rsync.lock" ukuba (set -o noclobber; echo $$> "$ LOCK") 2> / dev / null; emva koko ubambe 'rm -f "$ LOCK"; phuma $? ' UKUPHUMA KWENKQUBO rsync -avz foo bar rm -f $ LOCK trap - INT TERM EXIT enye echo "rsync sele isebenza: $ (cat $ LCK)" fi

Ubume bokugqibela kukuba isetyenziswa njengoko benditshilo, imo ye-noclobber kwaye ukuba ifayile yokutshixa iqulethe i-PID yenkqubo eqhubayo.

Kukwafanelekile ukukhankanya ukuba kukho ezinye izisombululo ezinje

flock

o

solo

nangona kunjalo kule posi bendifuna ukwabelana ngezisombululo ngezixhobo zika-bash. Unokufunda okungakumbi malunga neMigibe ngale nto Isikhokelo esihle kakhulu.


Umxholo wenqaku uyabambelela kwimigaqo yethu imigaqo yokuziphatha yokuhlela. Ukuxela impazamo cofa apha.

Izimvo ezi-5, shiya ezakho

Shiya uluvo lwakho

Idilesi yakho ye email aziyi kupapashwa. ezidingekayo ziphawulwe *

*

*

  1. Uxanduva lwedatha: UMiguel Ángel Gatón
  2. Injongo yedatha: Ulawulo lwe-SPAM, ulawulo lwezimvo.
  3. Umthetho: Imvume yakho
  4. Unxibelelwano lwedatha: Idatha ayizukuhanjiswa kubantu besithathu ngaphandle koxanduva lomthetho.
  5. Ukugcinwa kweenkcukacha
  6. Amalungelo: Ngalo naliphi na ixesha unganciphisa, uphinde uphinde ucime ulwazi lwakho.

  1.   URafael Castro sitsho

    Kakhulu! Enkoso ngokwabelana.

  2.   nx sitsho

    Inqaku elimnandi, tshintsha 'echo "rsync sele isebenza: $ (cat $ LCK)"' to 'echo "rsync sele isebenza: $ (cat $ LOCK)"'

    Phendula nge quote

  3.   idglangos sitsho

    Inqaku elinomdla kakhulu, ewe mhlekazi! Oku ndiya kugcina.

  4.   Joaquin sitsho

    Umyalelo eluncedo kakhulu ukugcina engqondweni. Ndayisebenzisa kwiskripthi endasipapasha ngeposi, ukucima ezinye iifayile ezazenziwe siskripthi xa simisiwe.

  5.   UDaniFP sitsho

    Inomdla kakhulu, ewe mhlekazi.