[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, ce fichier est un fichier lien
[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>
Modifiez le fichier /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>
Redémarrez le système et vérifiez les résultats
<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>
Ce script a été démarré automatiquement après le démarrage
Supprimer la configuration de la méthode 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>
Ajouter à chkconfig et démarrer automatiquement au démarrage
[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>
Redémarrez le système et vérifiez les résultats
<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
Opération réussie
Éteignez et démarrez
[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>
Supprimer le test de la gestion 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>)
Les deux méthodes ci-dessus de scripts à démarrage automatique au démarrage sont uniquement à titre de référence. Les lecteurs peuvent les configurer en fonction de leurs propres circonstances !
Remarque : le système que j'utilise est la version CentOS 6.9 (finale)
Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!