ubuntu-18.04 设置开机启动脚本

参阅下列链接

https://askubuntu.com/questions/886620/how-can-i-execute-command-on-startup-rc-local-alternative-on-ubuntu-16-10

ubuntu-18.04不能像ubuntu14一样通过编辑rc.local来设置开机启动脚本,通过下列简单设置后,可以使rc.local重新发挥作用。

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.

echo "看到这行字,说明添加自启动脚本成功。" > /usr/local/test.log
exit 0

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

8、重启并检查test.log文件

cat /usr/local/test.log  

如果能看到内容,说明设置成功,你就可以通过编辑rc.local文件来设置启动脚本了

ubuntu-18.04 设置开机启动脚本的更多相关文章

  1. Ubuntu 18.04 设置开机启动脚本 rc.local systemd

    ubuntu18.04不再使用initd管理系统,改用systemd. ubuntu-18.04不能像ubuntu14一样通过编辑rc.local来设置开机启动脚本,通过下列简单设置后,可以使rc.l ...

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

    需求:公司卡片机容量太小,只有100G,由于使用的人比较的多,开机使用后有时候就会出现磁盘空间占满数据写不进去的情况,影响工作进度,而且每次使用完都得关掉卡片机,所以就有必要写个清理磁盘的脚本,当卡片 ...

  3. Ubuntu 14.04设置开机启动脚本的方法

    rc.local脚本 rc.local脚本是一个ubuntu开机后会自动执行的脚本,我们可以在该脚本内添加命令行指令.该脚本位于/etc/路径下,需要root权限才能修改. 该脚本具体格式如下: #! ...

  4. ubuntu-18.04 设置开机启动脚本-亲测有效

    ubuntu-18.04不能像ubuntu14一样通过编辑rc.local来设置开机启动脚本,通过下列简单设置后,可以使rc.local重新发挥作用. 2.将下列内容复制进rc-local.servi ...

  5. Ubuntu14.04设置开机启动脚本(转)

    原文:https://www.magentonotes.com/ubuntu-config-autostart-shell-script.html 方法一:将脚本添加到文件/etc/rc.local ...

  6. ubuntu-server-18.04 设置开机启动脚本

    ubuntu-16.10 开始不再使用initd管理系统,改用systemd systemd is now used for user sessions. System sessions had al ...

  7. Ubuntu-18.04设置开机启动脚本

    参考:https://www.cnblogs.com/defifind/p/9285456.html    http://www.cnblogs.com/airdot/p/9688530.html s ...

  8. Ubuntu 16.04设置开机启动应用程序

    在终端通过以下命令进行设置,Dash已经搜索不到Startup了: gnome-session-properties 或者直接在Dash中搜索:gnome-session

  9. ubuntu 18.04设置开机自动挂载移动硬盘

    首先在命令行执行df -h指令,可以看到如下结果: zifeiy@zifeiy-PC1:~$ df -h 文件系统 容量 已用 可用 已用% 挂载点 udev 964M 0 964M 0% /dev ...

随机推荐

  1. 获取Shell脚本当前的目录

    https://qiushao.net/article/1489983836453?p=1&m=0 SCRIPT_DIR=$(cd $(dirname ${BASH_SOURCE[0]}); ...

  2. Anaconda安装python tensorflow 环境

    1.安装Anaconda3 https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/ 2.安装python 3.6 (base) C:\Users\ ...

  3. 在Net MVC中应用JsTree

    先实现个基本用法 1 - 引入js和css 2 -  html <div id="list_left" class="col-md-2 pre-scrollable ...

  4. .net 获取配置文件AppSettings的键值

    //AppSettings.config 节点代码 <appSettings> <add key="IsUpdate" value="false&quo ...

  5. RabbitMQ 保证消息不丢失

    参考:https://www.imooc.com/article/49814 发送消息的时候,加上messageId字段,数据库记录消息日志表 ,插入的时候为发送中 当收到消息的时候,更改为已发送 , ...

  6. Linux 安装qt5-designer并集成到Pycharm

    在前面,有过介绍 Pycharm集成pyrcc4 =====>链接:  Pyqt 打包资源文件  这个是在Windows下集成,且pyqt在Windows下一个双击exe搞定. 在pyqt5之前 ...

  7. IMCASH:卖掉了比特币回老家生活的现在怎么样了?

    2012年大学毕业后,我不经意间接触到了比特币,抱着本人对新鲜事物的好奇心和知乎上的一些流言蜚语,我把一部分上学时期辛苦兼职赚的钱换成了比特币,当时真的觉得自己中了邪,不知道为什么会入这个坑. 比特币 ...

  8. Python爬虫代理IP池

    目录[-] 1.问题 2.代理池设计 3.代码模块 4.安装 5.使用 6.最后 在公司做分布式深网爬虫,搭建了一套稳定的代理池服务,为上千个爬虫提供有效的代理,保证各个爬虫拿到的都是对应网站有效的代 ...

  9. I - Infinite Improbability Drive

    I - Infinite Improbability Drivehttp://codeforces.com/gym/241750/problem/I不断构造,先填n-1个0,然后能放1就放1,最后这个 ...

  10. JS与CSS那些特别小的知识点区别

    1:target与currentTarget的区别 currentTarget指向的事件绑定的元素,target指向的是你点击的元素 2:attr与jprop在jQuery在API当中的区别 2.1: ...