ubuntu中开机不执行rc.local问题

ubuntu中开机不执行rc.local问题

今天应老师要求去调试程序,发现机器启动时没有执行rc.local脚本,脚本中的命令没有执行导致程序不能入预期运行。

首先查看了rc.local是有执行权限的,并且登录用户是root。之后在网上查了很多的解决方案,也许是产生问题的原因不同,这些都不能奏效,最后发现这样一种说法:从Ubuntu 6.10开始,默认使用dash而不是bash,但Login Shell还是bash。于是查看了一下,发现 /bin/sh 链接到了 /bin/dash/ ,而rc.local脚本使用的正是/bin/sh,故脚本没有执行。

以下解决方案引用自https://blog.csdn.net/benbenxiongyuan/article/details/58597036
(貌似只适用于ubuntu服务器版)

方法一:将rc.local中的命令改成更加兼容的模式,将"#!/bin/sh"改为"#!/bin/bash"

方法二:将/bin/sh重新链接到/bin/bash,有两种方法:
1. 执行命令:
sudo dpkg-reconfigure dash选择no
3. 重新进行软连接,执行命令:
sudo rm /bin/sh sudo ln -s /bin/bash /bin/sh

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Ubuntu 22.04,如果你想要将一个程序添加到开机启动,你可以通过修改rc.local文件来实现。在Ubuntu,有两个rc.local文件,分别是/etc/rc.local和/etc/init.d/rc.local。这两个文件有一定的关联关系。 如果你在系统找不到这两个文件,你可以自己创建一个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 然后,你可以启动rc-local.service服务并将其设置为开机自启: sudo systemctl start rc-local.service sudo systemctl enable rc-local.service 最后,你可以创建/etc/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. exit 0 记得给予脚本执行权限。通过以上步骤,你可以将程序添加到Ubuntu 22.04的rc.local,并实现开机启动。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [ubuntu系统/etc/rc.local和/etc/init.d/rc.local的区别详解](https://download.csdn.net/download/weixin_38564826/14890316)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [ubuntu没有rc.local文件](https://blog.csdn.net/qq_35002542/article/details/127999561)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值