朱林森 發表於 2021-5-9 17:47:00

deepin深度linux,开机自动执行shell脚本

<p><strong>最近正在折腾写一个开机自动安装软件的shell脚本,用于批量给系统安装软件,</strong></p>
<p><strong>特此记录一个shell脚本开机自动执行的的方法:</strong></p>
<p>大家可能都知道,在其他Linux发行版本如CentOs等在<code>etc</code>目录下会有一个<code>rc.local</code>文件,这个文件是<strong>启动加载文件</strong>,也就是说,在我们开机后,系统会检查一遍这个文件,并且会自动执行里面写入的命令;</p>
<p>那么,我们只需要把我们想开机自动执行的脚本的执行路径写在这里就可以实现开机自动执行。</p>
<p>以下是rc.local的截图,里面的内容大概如下:</p>
<p><img alt="" width="1024" height="433" class="wp-image-958 loaded lazyload" loading="lazy" data-was-processed="true" data-src="https://obs.wanpeng.life/wp-content/uploads/2020/09/Snipaste_2020-09-29_09-54-33-1024x433.png"></p>
<p>我们只需要把文件写入最下边就可以了。</p>
<h4>注意:</h4>
<p><code>rc.local</code>文件需要加上执行权限,<span style="background-color: rgba(255, 0, 0, 1)"><code>chmod +x rc.local</code></span></p>
<h3>但是,你可能发现你的deepin系统中没有这个<code>rc.local</code>文件,没有关系,自己写一个就可以啦,是可以正常执行的。可以直接复制以下内容:</h3>
<p><code>vim /etc/rc.local</code></p>
<div class="cnblogs_code">
<pre>#!/bin/<span style="color: rgba(0, 0, 0, 1)">bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this </span><span style="color: rgba(0, 0, 255, 1)">file</span><span style="color: rgba(0, 0, 0, 1)">.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run </span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">chmod +x /etc/rc.d/rc.local</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)"> to ensure
# that this script will be executed during boot.<br>
exit </span><span style="color: rgba(128, 0, 128, 1)">0</span></pre>
</div>
<p>&nbsp;</p>
<p>需要执行的放在 exit 0 上边就可以啦!</p>
<p>重启试验一下吧!</p><br><br>
来源:https://www.cnblogs.com/penglaoban/p/14748374.html
頁: [1]
查看完整版本: deepin深度linux,开机自动执行shell脚本