起動時にスクリプトを実行するようにLinuxを構成する方法は何ですか?一般的な紹介!

  起動時にスクリプトを実行するようにLinuxを構成する方法はたくさんあります。今日は、/ etc /rc.localを変更する方法とchkconfig管理設定の方法の2つの方法を紹介します。

  起動時に開始するスクリプトとしてtest.shを設定します

  [root @ oldboyスクリプト] #vim /server/scripts/test.sh

  [root @ oldboyスクリプト] #cat / server / scripts / test.sh

  #!/ bin / bash

  / bin / echo $(/ bin / date +%F_%T)>> /tmp/test.log

  方法1:/etc/rc.localを変更する

  [root @ oldboy〜] #ll /etc/rc.local

  lrwxrwxrwx。1ルートルート13Mar 30 10:50 /etc/rc.local-> rc.d / rc.local

  /etc/rc.localファイルを変更します

  [root @ oldboyスクリプト] #tail -n 1 /etc/rc.local

  / bin / bash /server/scripts/test.sh> / dev / null 2> / dev / null

  システムを再起動し、結果を表示します

  [root @ oldboy〜] #cat /tmp/test.log

  2018-03-30_12:00:10

  方法2:chkconfig管理

  メソッド1の構成を削除します

  [root @ oldboy〜] #vim /etc/init.d/test

  #!/ bin / bash

  #chkconfig:3 88 88

  / bin / bash /server/scripts/test.sh> / dev / null 2> / dev / null

  [root @ oldboy〜] #chmod + x /etc/init.d/test

  chkconfigに追加し、起動後に自動的に起動します

  [root @ oldboy〜] #chkconfig --add test

  [root @ oldboy〜] #chkconfig --list test

  テスト0:オフ1:オフ2:オフ3:オン4:オフ5:オフ6:オフ

  システムを再起動し、結果を表示します

  [root @ oldboy〜] #cat /tmp/test.log

  2018-03-30_12:00:10

  2018-03-30_12:33:20

  正常な操作

  スタートアップをオフにする

  [root @ oldboy〜] #chkconfig test off

  [root @ oldboy〜] #chkconfig --list test

  テスト0:オフ1:オフ2:オフ3:オフ4:オフ5:オフ6:オフ

  chkconfig管理からテストを削除します

  [root @ oldboy〜] #chkconfig --list test

  テスト0:オフ1:オフ2:オフ3:オフ4:オフ5:オフ6:オフ

  [root @ oldboy〜] #chkconfig --del test

  [root @ oldboy〜] #chkconfig --list test

  サービステストはchkconfigをサポートしますが、どのランレベルでも参照されません(run'chkconfig --add test ')

おすすめ

転載: blog.51cto.com/15052541/2605572