Rumah > Artikel > Tutorial sistem > Dua cara untuk mengkonfigurasi Linux untuk mula melaksanakan skrip secara automatik semasa but
[root@c69-01 scripts]<span class="hljs-comment"># vim /server/scripts/qidong.sh</span> [root@c69-01 scripts]<span class="hljs-comment"># cat /server/scripts/qidong.sh</span> <span class="hljs-meta">#!/bin/bash</span> /bin/<span class="hljs-built_in">echo</span> $(/bin/date +%F_%T) >> /tmp/qidong.log
/etc/rc.local, fail ini ialah fail pautan
[root@c69<span class="hljs-number">-01</span> ~]# ll /etc/rc.<span class="hljs-keyword">local</span> lrwxrwxrwx. <span class="hljs-number">1</span> root root <span class="hljs-number">13</span> Feb <span class="hljs-number">5</span> <span class="hljs-number">10</span>:<span class="hljs-number">03</span> /etc/rc.<span class="hljs-keyword">local</span> -> rc.d/rc.<span class="hljs-keyword">local</span>
Ubah suai fail /etc/rc.local
[root<span class="hljs-variable">@c69</span>-<span class="hljs-number">01</span> scripts]<span class="hljs-comment"># tail -n 1 /etc/rc.local </span> /bin/bash /server/scripts/qidong.sh ><span class="hljs-regexp">/dev/null</span> <span class="hljs-number">2</span>><span class="hljs-regexp">/dev/null</span>
Mulakan semula sistem dan semak hasilnya
<span class="hljs-selector-attr">[root@c69-01 ~]</span># <span class="hljs-selector-tag">cat</span> /<span class="hljs-selector-tag">tmp</span>/<span class="hljs-selector-tag">qidong</span><span class="hljs-selector-class">.log</span> <span class="hljs-selector-tag">2018-02-19_23</span><span class="hljs-selector-pseudo">:30</span><span class="hljs-selector-pseudo">:56</span>
Skrip ini telah dimulakan secara automatik selepas boot
Padamkan konfigurasi kaedah 1
[root@c69-01 ~]<span class="hljs-comment"># vim /etc/init.d/test </span> <span class="hljs-meta">#!/bin/bash</span> <span class="hljs-comment"># chkconfig: 3 88 88</span> /bin/bash /server/scripts/qidong.sh >/dev/null 2>/dev/null [root@c69-01 ~]<span class="hljs-comment"># chmod +x /etc/init.d/test</span>
Tambah pada chkconfig dan mulakan secara automatik semasa but
[root<span class="hljs-variable">@c69</span>-<span class="hljs-number">01</span> ~]<span class="hljs-comment"># chkconfig --add test</span>
[root<span class="hljs-variable">@c69</span>-<span class="hljs-number">01</span> ~]<span class="hljs-comment"># chkconfig --list test</span> test <span class="hljs-number">0</span><span class="hljs-symbol">:off</span> <span class="hljs-number">1</span><span class="hljs-symbol">:off</span> <span class="hljs-number">2</span><span class="hljs-symbol">:off</span> <span class="hljs-number">3</span><span class="hljs-symbol">:on</span> <span class="hljs-number">4</span><span class="hljs-symbol">:off</span> <span class="hljs-number">5</span><span class="hljs-symbol">:off</span> <span class="hljs-number">6</span><span class="hljs-symbol">:off</span>
Mulakan semula sistem dan semak hasilnya
<span class="hljs-selector-attr">[root@c69-01 ~]</span># <span class="hljs-selector-tag">cat</span> /<span class="hljs-selector-tag">tmp</span>/<span class="hljs-selector-tag">qidong</span><span class="hljs-selector-class">.log</span>
<span class="hljs-selector-tag">2018-02-19_23</span><span class="hljs-selector-pseudo">:30</span><span class="hljs-selector-pseudo">:56</span>
2018-02-19_23:59:10
Operasi berjaya
Matikan dan mulakan
[root<span class="hljs-variable">@c69</span>-<span class="hljs-number">01</span> ~]<span class="hljs-comment"># chkconfig test off</span> [root<span class="hljs-variable">@c69</span>-<span class="hljs-number">01</span> ~]<span class="hljs-comment"># chkconfig --list test</span> test <span class="hljs-number">0</span><span class="hljs-symbol">:off</span> <span class="hljs-number">1</span><span class="hljs-symbol">:off</span> <span class="hljs-number">2</span><span class="hljs-symbol">:off</span> <span class="hljs-number">3</span><span class="hljs-symbol">:off</span> <span class="hljs-number">4</span><span class="hljs-symbol">:off</span> <span class="hljs-number">5</span><span class="hljs-symbol">:off</span> <span class="hljs-number">6</span><span class="hljs-symbol">:off</span>
Alih keluar ujian daripada pengurusan chkconfig
[root<span class="hljs-variable">@c69</span>-<span class="hljs-number">01</span> ~]<span class="hljs-comment"># chkconfig --list test</span> test <span class="hljs-number">0</span><span class="hljs-symbol">:off</span> <span class="hljs-number">1</span><span class="hljs-symbol">:off</span> <span class="hljs-number">2</span><span class="hljs-symbol">:off</span> <span class="hljs-number">3</span><span class="hljs-symbol">:off</span> <span class="hljs-number">4</span><span class="hljs-symbol">:off</span> <span class="hljs-number">5</span><span class="hljs-symbol">:off</span> <span class="hljs-number">6</span><span class="hljs-symbol">:off</span> [root<span class="hljs-variable">@c69</span>-<span class="hljs-number">01</span> ~]<span class="hljs-comment"># chkconfig --del test</span> [root<span class="hljs-variable">@c69</span>-<span class="hljs-number">01</span> ~]<span class="hljs-comment"># chkconfig --list test</span> service test supports chkconfig, but is <span class="hljs-keyword">not</span> referenced <span class="hljs-keyword">in</span> any runlevel (run <span class="hljs-string">'chkconfig --add test'</span>)
Dua kaedah skrip permulaan sendiri di atas adalah untuk rujukan sahaja Pembaca boleh mengkonfigurasinya mengikut keadaan mereka sendiri!
Nota: Sistem yang saya gunakan ialah keluaran CentOS 6.9 (Akhir)
Atas ialah kandungan terperinci Dua cara untuk mengkonfigurasi Linux untuk mula melaksanakan skrip secara automatik semasa but. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!