Yog tias koj pom nplooj ntawv no hauv kev tshawb nrhiav, tej zaum koj tab tom sim daws qee qhov teeb meem nrog kev khiav bash.
Tej zaum koj ib puag ncig bash tsis teeb tsa ib puag ncig hloov pauv thiab koj tsis nkag siab vim li cas. Tej zaum koj yuav tau daig ib yam dab tsi hauv ntau cov ntaub ntawv bash khau raj lossis cov ntaub ntawv lossis txhua cov ntaub ntawv ntawm random kom txog thaum nws ua haujlwm.
Nyob rau hauv txhua rooj plaub, lub ntsiab lus ntawm daim ntawv no yog nteg tawm cov txheej txheem rau pib bash kom yooj yim li sai tau kom koj tuaj yeem daws teeb meem.
Daim duab
Daim ntawv qhia no qhia txog tag nrho cov txheej txheem thaum khiav bash.
Tam sim no cia peb saib ze dua ntawm txhua ntu.
ID nkag mus Plhaub?
Ua ntej koj yuav tsum xaiv seb koj puas nyob hauv lub log log lossis tsis.
Lub plhaub nkag mus yog thawj lub plhaub koj nkag thaum koj nkag rau hauv kev sib tham sib tham. Tus ID nkag mus plhaub tsis tas yuav tsum muaj tus username thiab password. Koj tuaj yeem yuam kom lub plhaub nkag mus pib los ntawm kev ntxiv tus chij --login
thaum hu bash
, piv txwv:
bash --login
Lub plhaub nkag mus teeb tsa lub hauv paus ib puag ncig thaum koj thawj zaug pib lub plhaub bash.
Sib tham sib?
Tom qab ntawd koj txiav txim siab seb lub plhaub puas muaj kev cuam tshuam los yog tsis.
Qhov no tuaj yeem kuaj xyuas los ntawm qhov muaj qhov sib txawv PS1
(nws nruab qhov hais kom ua input muaj nuj nqi):
yog ["${PS1-}"]; ces ncho sib tham lwm echo non-interactive fi
Los yog saib seb qhov kev xaiv tau teeb tsa -i
, siv ib tug tshwj xeeb hyphen sib txawv -
hauv bash, piv txwv li:
$echo$-
Yog muaj ib lub cim nyob rau hauv cov zis i
, ces lub plhaub yog sib tham sib.
Nyob rau hauv lub log log?
Yog tias koj nyob hauv lub plhaub nkag, ces bash nrhiav cov ntaub ntawv /etc/profile
thiab khiav yog tias muaj.
Tom qab ntawd tshawb rau ib qho ntawm peb cov ntaub ntawv hauv qab no:
~/.bash_profile ~/.bash_login ~/.profile
Thaum nws pom ib qho, nws pib nws thiab hla lwm tus.
Hauv kev sib tham sib plhaub?
Yog tias koj nyob hauv lub plhaub uas tsis yog nkag mus, nws xav tias koj twb tau nyob hauv lub plhaub nkag mus, ib puag ncig tau teeb tsa thiab yuav tau txais txiaj ntsig.
Hauv qhov no, ob cov ntaub ntawv hauv qab no raug ua tiav hauv kev txiav txim, yog tias lawv muaj:
/etc/bash.bashrc ~/.bashrc
Tsis muaj kev xaiv?
Yog tias koj tsis nyob hauv ib lub log nkag lossis lub plhaub sib tham sib tham, ces koj qhov chaw yuav tsum khoob. Qhov no ua rau muaj kev ntxhov siab ntau (saib hauv qab no txog cov haujlwm cron).
Hauv qhov no bash saib ntawm qhov sib txawv BASH_ENV
koj ib puag ncig thiab tsim cov ntaub ntawv sib raug tau teev tseg rau ntawd.
Common Difficulties and Rules of Thumb
cron cov haujlwm
95% ntawm lub sij hawm kuv debug bash startup nws yog vim hais tias cov cron txoj hauj lwm tsis khiav raws li xav tau.
Qhov haujlwm damn no ua haujlwm zoo thaum kuv khiav nws ntawm kab hais kom ua, tab sis ua tsis tiav thaum kuv khiav hauv crontab.
nws yog ob vim:
- Cron txoj haujlwm tsis muaj kev sib tham.
- Tsis zoo li cov kab lus hais kom ua, cov haujlwm cron tsis tau txais lub plhaub ib puag ncig.
Feem ntau koj yuav tsis pom lossis saib xyuas tias daim ntawv plhaub tsis sib tham vim hais tias ib puag ncig tau txais los ntawm lub plhaub sib tham. Qhov no txhais tau tias txhua yam PATH
ΠΈ alias
configured raws li koj xav tau.
Qhov no yog vim li cas nws yog feem ntau yuav tsum tau teem ib qho tshwj xeeb PATH
rau cov haujlwm cron zoo li ntawm no:
* * * * * PATH = ${PATH}:/path/to/my/program/folder myprogram
Scripts hu ib leeg
Lwm qhov teeb meem tshwm sim yog thaum cov ntawv sau yuam kev raug teeb tsa los hu rau ib leeg. Piv txwv li, /etc/profile
thov kom ~/.bashrc
.
Qhov no feem ntau tshwm sim thaum ib tus neeg sim kho qee qhov yuam kev thiab txhua yam zoo li ua haujlwm. Hmoov tsis zoo, thaum koj xav tau cais cov kev sib txawv no, cov teeb meem tshiab tshwm sim.
Sandboxed Docker duab
Txhawm rau sim nrog khiav lub plhaub, kuv tsim Docker duab uas tuaj yeem siv los daws qhov kev khiav lub plhaub hauv qhov chaw nyab xeeb.
Tua tawm:
$ docker run -n bs -d imiell/bash_startup
$ docker exec -ti bs bash
Dockerfile nyob hauv
Txhawm rau yuam tus ID nkag mus thiab simulate lub plhaub nkag mus:
$ bash --login
Txhawm rau kuaj ib txheej ntawm kev hloov pauv BASH_ENV
:
$ env | grep BASH_ENV
Rau kev debugging crontab
ib tsab ntawv yooj yim yuav raug tua txhua feeb (hauv /root/ascript
):
$ crontab -l
$ cat /var/log/script.log
Tau qhov twg los: www.hab.com