Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> 關於 Linux

SUSE Linux 10 建立 rc.local 實現開機自動執行腳本的兩種方法

編輯:關於 Linux

SUSE Linux 10 預設無 rc.local,需自行建立啟動腳本並納入服務管理。本文提供兩種實作方案。

方法一:修改 /etc/init.d/rc

  1. 編輯 /etc/init.d/rc,在最後 exit 0 前插入:
    rc_local=/etc/rc.d/rc.local
    current_runlevel=$(runlevel | awk '{ print $NF }')
    if [ -x $rc_local ];then
      ((current_runlevel>1)) && ((current_runlevel<6)) && {
        echo -e "\n\n\n"
        echo "-----------------------Startup $rc_local---------------------------"
        $rc_local
      }
    fi
  2. 建立腳本並賦權:
    chmod 0755 /etc/rc.d/rc.local

方法二:建立獨立 rclocal 服務

  1. 建立 /etc/rc.d/rclocal:
    case "$1" in
      start)
        if ! test -x /etc/init.d/rc.local ; then
          echo '/etc/rc.local is not exsit!'
          exit 1
        fi
        /etc/init.d/rc.local &
        ;;
      stop)
        ;;
    esac
  2. 建立 /etc/rc.d/rc.local 放置啟動命令。
  3. 賦權並註冊服務:
    chmod 0755 /etc/rc.d/rc.local /etc/rc.d/rclocal
    chkconfig --add rclocal

兩種方法均可實現開機自動執行自定義腳本,按習慣選擇即可。

Copyright © Windows教程網 All Rights Reserved