Linux 系统有两种交互模式,文本交互及图形化桌面交互,根据用户的脚本功能的不同,就要选择合适的启动方式。
下面介绍两种随开机自启动脚本方法。
如果脚本功能不涉及桌面图像界面的话,就使用方法一,否则使用方法二。
方法一:
修改 /etc/rc.local 文件,该文件是Linux系统运行级别为2-5时启动调用的文件,可在该文件中添加运行脚本的指令。
如运行 /opt/mystart.sh 脚本,添加如下,保存,即可随系统启动自动运行脚本。
# vim /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.
# Generate the SSH keys if non-existent
if [ ! -f /etc/ssh/ssh_host_rsa_key ]
then
# else ssh service start in dpkg-reconfigure will fail
systemctl stop ssh.socket||true
# dpkg-reconfigure openssh-server
dpkg --force-confdef --force-confold --configure -a
fi
/opt/mystart.sh
exit 0
方法二:
随用户桌面启动,该方法通过桌面启

本文介绍了在Ubuntu 16.04系统中如何设置脚本随开机或桌面启动。对于不涉及桌面图像界面的脚本,可以修改 /etc/rc.local 文件;涉及桌面的脚本,可以通过图形界面或命令行配置,如gnome-session-properties和创建.desktop文件。如果遇到权限问题,可创建密码文件或修改用户权限。
最低0.47元/天 解锁文章
7738

被折叠的 条评论
为什么被折叠?



