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
/