Linux 新增开机启动脚本
Posted xhoufei2010
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux 新增开机启动脚本相关的知识,希望对你有一定的参考价值。
Linux 新增开机启动脚本
1、说明
在linux 环境下,新增开机自启动脚本
2、环境说明
硬件环境: NVIDIA 开发板
软件环境: Ubuntu 18
3、操作
3.1 增加开机脚本
sudo vi /etc/init.d/test.sh
其中脚本的内容如下
#!/bin/sh
### BEGIN INIT INFO
# Provides: test.sh
# Required-Start: $remote_fs
# Required-Stop:
# Should-Start:
# Default-Start: 2 3 4 5
# Default-Stop:
# X-Interactive: true
# Short-Description: Just test script
### END INIT INFO
exit 0
3.2 将脚本添加到开机服务
cd /etc/init.d/
sudo chmod 777 test.sh
sudo update-rc.d test.sh defaults 98
其中 98 为开机序号,范围0-99,数字越大,开机启动的顺序越慢。
修改之后,重启即可成功
sudo reboot
3.3 效果查看
开机重启后,可以查看每次开机都有 ~/test_result.txt 文件产生,查看文件
sky@ubuntu:~$ cat test_result.txt
just for a automatic script
3.4 卸载方法
cd /etc/init.d
sudo update-rc.d -f test remove
4 延伸说明
4.1 自启动脚本都有哪些
系统自带的启动脚本以及顺序,都存放于 /etc/rcN.d/
查看系统使用的是哪个rc 文件夹
sky@ubuntu:~$ runlevel
N 5
说明采用的是 rc5.d 文件夹,查看文件夹里面的内容
ls /etc/rc5.d/ -al
total 16
drwxr-xr-x 2 root root 4096 Sep 18 17:24 .
drwxr-xr-x 133 root root 12288 Oct 13 10:09 ..
lrwxrwxrwx 1 root root 27 Sep 17 14:41 K01speech-dispatcher -> ../init.d/speech-dispatcher
lrwxrwxrwx 1 root root 15 Sep 17 14:41 S01acpid -> ../init.d/acpid
lrwxrwxrwx 1 root root 17 Sep 17 14:41 S01anacron -> ../init.d/anacron
lrwxrwxrwx 1 root root 16 Sep 17 14:41 S01apport -> ../init.d/apport
lrwxrwxrwx 1 root root 22 Sep 17 14:41 S01avahi-daemon -> ../init.d/avahi-daemon
lrwxrwxrwx 1 root root 24 Sep 17 16:57 S01binfmt-support -> ../init.d/binfmt-support
lrwxrwxrwx 1 root root 19 Sep 17 14:41 S01bluetooth -> ../init.d/bluetooth
lrwxrwxrwx 1 root root 26 Sep 17 14:41 S01console-setup.sh -> ../init.d/console-setup.sh
lrwxrwxrwx 1 root root 14 Sep 17 14:41 S01cron -> ../init.d/cron
lrwxrwxrwx 1 root root 14 Sep 17 14:41 S01cups -> ../init.d/cups
lrwxrwxrwx 1 root root 22 Sep 17 14:41 S01cups-browsed -> ../init.d/cups-browsed
lrwxrwxrwx 1 root root 14 Sep 17 14:41 S01dbus -> ../init.d/dbus
lrwxrwxrwx 1 root root 14 Sep 17 14:41 S01gdm3 -> ../init.d/gdm3
lrwxrwxrwx 1 root root 21 Sep 17 14:41 S01grub-common -> ../init.d/grub-common
lrwxrwxrwx 1 root root 20 Sep 17 14:41 S01irqbalance -> ../init.d/irqbalance
lrwxrwxrwx 1 root root 20 Sep 17 14:41 S01kerneloops -> ../init.d/kerneloops
lrwxrwxrwx 1 root root 14 Sep 18 17:24 S01nmbd -> ../init.d/nmbd
lrwxrwxrwx 1 root root 17 Sep 17 14:41 S01openvpn -> ../init.d/openvpn
lrwxrwxrwx 1 root root 18 Sep 17 14:41 S01plymouth -> ../init.d/plymouth
lrwxrwxrwx 1 root root 37 Sep 17 14:41 S01pulseaudio-enable-autospawn -> ../init.d/pulseaudio-enable-autospawn
lrwxrwxrwx 1 root root 15 Sep 17 14:41 S01rsync -> ../init.d/rsync
lrwxrwxrwx 1 root root 17 Sep 17 14:41 S01rsyslog -> ../init.d/rsyslog
lrwxrwxrwx 1 root root 21 Sep 18 17:24 S01samba-ad-dc -> ../init.d/samba-ad-dc
lrwxrwxrwx 1 root root 15 Sep 17 14:41 S01saned -> ../init.d/saned
lrwxrwxrwx 1 root root 14 Sep 18 17:24 S01smbd -> ../init.d/smbd
lrwxrwxrwx 1 root root 23 Sep 17 14:41 S01spice-vdagent -> ../init.d/spice-vdagent
lrwxrwxrwx 1 root root 13 Sep 17 15:11 S01ssh -> ../init.d/ssh
lrwxrwxrwx 1 root root 29 Sep 17 14:41 S01unattended-upgrades -> ../init.d/unattended-upgrades
lrwxrwxrwx 1 root root 15 Sep 17 14:41 S01uuidd -> ../init.d/uuidd
lrwxrwxrwx 1 root root 18 Sep 17 14:41 S01whoopsie -> ../init.d/whoopsie
按照字母和数字顺序执行
以上是关于Linux 新增开机启动脚本的主要内容,如果未能解决你的问题,请参考以下文章