在Ubuntu 18.04 中设置开机自动执行脚本
发布日期:2022-03-11 10:18:48 浏览次数:49 分类:技术文章

本文共 1120 字,大约阅读时间需要 3 分钟。

Ubuntu18.04 不能像16.04 那样可以直接使用 /etc/rc.local 文件,需要设置

1.建立 rc-local.service 文件

sudo vim /etc/systemd/system/rc-local.service

2.复制下列内容到 rc-local.service 文件中

[Unit]Description=/etc/rc.local CompatibilityConditionPathExists=/etc/rc.local [Service]Type=forkingExecStart=/etc/rc.local startTimeoutSec=0StandardOutput=ttyRemainAfterExit=yesSysVStartPriority=99 [Install]WantedBy=multi-user.target

3.创建文件 rc.local

sudo vim /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.logexit 0

5.给 rc.local 加上权限,启用服务

sudo chmod 755 /etc/rc.localsudo systemctl enable rc-local

6.启动服务并检查状态

sudo systemctl start rc-local.servicesudo systemctl status rc-local.service

7.重启后检查test.log文件是否已经存在

————————————————
版权声明:本文为CSDN博主「命运的棋局」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/time_future/article/details/85805298

转载地址:https://blog.csdn.net/weicao1990/article/details/101121085 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:NVIDIA-SMI has failed because it couldn’t communicate with the NVIDIA driver
下一篇:PyTorch 常用代码段整理合集

发表评论

最新留言

路过按个爪印,很不错,赞一个!
[***.219.124.196]2024年04月09日 15时12分39秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章