Linux 如何设置开机自启动脚本

Linxu开机自启动脚本

一、CentOS系统和Redhat系统如下:

1.修改/etc/rc.d/rc.local为

#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
 
touch /var/lock/subsys/local
source /root/Desktop/start.sh         

“sourece /root/Desktop/start.sh”为要添加开机自启动的脚本,并且要给“/root/Desktop/start.sh”赋予执行权限(chmod +x /root/Desktop/start.sh)
2.chmod 777 rc.local
3.重启系统后就会开始执行预设置执行的脚本。(此种自启动方式不会在GUI界面显示执行的具体进程)**

二、Suse 系统如下:

1.suse15

1)将需要开机启动脚本xxx.sh复制到 /etc/profile.d
chmod 777 xxx.sh
2)将系统改成root 自动登录
vi /etc/sysconfig/displaymanager
displaymanager-autologin=“root”

备注:

a.安装suse15系统参考:http://morecoder.com/article/1120393.html
在这里插入图片描述
b.查看OS IP指令为“ip -4 address”
c.远程连接请用putty,ssh 工具无法使用。

2.Suse12

1.修改/etc/init.d/下面有个boot.local为:

#! /bin/sh
#
# Copyright (c) 2002 SuSE Linux AG Nuernberg, Germany.  All rights reserved.
#
# Author: Werner Fink, 1996
#         Burchard Steinbild, 1996
#
# /etc/init.d/boot.local
#
# script with local commands to be executed from init on system startup
#
# Here you should add things, that should happen directly after booting
# before we're going to the first run level.
#
source /root/Desktop/start.sh

“sourece /root/Desktop/start.sh”为要添加开机自启动的脚本,并且要给“/root/Desktop/start.sh”赋予执行权限(chmod +x /root/Desktop/start.sh)
2.重启系统后就会开始执行预设置执行的脚本。(此种自启动方式不会在GUI界面显示执行的具体进程)

三、Ubuntu 系统如下:

1、建立rc-local.service文件
sudo vi /etc/systemd/system/rc-local.service
2、将下列内容复制进rc-local.service文件

[Unit]
Description=/etc/rc.local Compatibility
ConditionPathExists=/etc/rc.local

[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99

[Install]
WantedBy=multi-user.target

3、创建文件rc.local
sudo vi /etc/rc.local
4、将下列内容复制进rc.local文件

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
sudo ./root/Desktop/start.sh

5、给rc.local加上权限sudo chmod +x /etc/rc.local
6、启用服务sudo systemctl enable rc-local
7、启动服务并检查状态
sudo systemctl start rc-local.service
sudo systemctl status rc-local.service

在Redhat Redflag centOS fc linux系统里面脚本的启动先后顺序:
第一步:通过/boot/vm进行启动 vmlinuz
第二步:init /etc/inittab
第三步:启动相应的脚本,并且打开终端
rc.sysinit
rc.d(里面的脚本)
rc.local
第四步:启动login登录界面 login
第五步:在用户登录的时候执行sh脚本的顺序:每次登录的时候都会完全执行的
/etc/profile.d/file
/etc/profile
/etc/bashrc
/root/.bashrc
/root/.bash_profile
Redhat中的运行模式2、3、5都把/etc/rc.d/rc.local做为初始化脚本中的最后一个,所以用户可以自己在这个文件中添加一些需要在其他初始化工作之后,登录之前执行的命令

  • 2
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值