Ubuntu 16.04设置开机启动脚本的方法

需求:公司卡片机容量过小,只有100G,因为使用的人比较的多,开机使用后有时候就会出现磁盘空间占满数据写不进去的状况,影响工做进度,并且每次使用完都得关掉卡片机,因此就有必要写个清理磁盘的脚本,当卡片机开机启动后执行脚本,若是磁盘达到设置的阈值,就进行空间的清理.ubuntu

rc.local脚本bash

rc.local脚本是一个ubuntu开机后会自动执行的脚本,咱们能够在该脚本内添加命令行指令。该脚本位于/etc/路径下,须要root权限才能修改。this

该脚本具体格式以下:spa

#!/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.
#/bin/sh /home/saneri/new_service.sh #脚本范例

exit 0

注意: 必定要将命令添加在 exit 0以前命令行

方法2:code

如何给ubuntu添加一个开机启动脚本blog

1,新建个脚本文件new_service.ship

#!/bin/bash
# command content
# ..................................
exit 0

2,设置权限rem

sudo chmod 755 new_service.sh

3,把脚本放置到启动目录下it

sudo mv new_service.sh /etc/init.d/

4,将脚本添加到启动脚本

执行以下指令,在这里90代表一个优先级,越高表示执行的越晚

cd /etc/init.d/
sudo update-rc.d new_service.sh defaults 90

移除Ubuntu开机脚本

sudo update-rc.d -f new_service.sh remove
相关文章
相关标签/搜索