zlb

Ubutun 设置开机启动程序

方法一
方法成功

终端中执行:gnome-session-properties

弹出 启动应用程序首选项 菜单

1、查找 启动应用程序 打开

添加 --名称 :run-py

命令:

/usr/bin/gnome-terminal.real -x bash -c "cd /root/qzm/rfid-py-v1.0/;python3 run_main.py" 

 /usr/bin/gnome-terminal -x bash -c "cd /root/qzm/rfid-py-v1.0/;python3 run_main.py"

开机自启动 运行 python3脚本 run_main.py

2、自动运行 spring boot

名称: run-rfid-serialPort

命令:

 /usr/bin/gnome-terminal.real  -x bash -c "cd /root/zlb/rfidSerialPort-v1.0/bin/; sh startup.sh; exec bash;"

exec bash 防止关闭终端

修改 startup.sh 文件的权限 为 可执行权限

比如要把run-nexus.sh这个脚本制作成开机启动项。

系统工具->首选项->启动应用程序。添加该文件,即可

方法二

编辑/etc/rc.local,因为其为只读文件,需使其可写

1、将/etc/rc.local的命令改成更加兼容的模式,将"#!/bin/sh"改为"#!/bin/bash"

rc.local 文件权限设置 为 可执行 权限

要执行的 startup.sh 文件权限也设置成 可执行 权限

#!/bin/bash 
#
# 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.
#/root/qzm/auto_run.sh
#************** 可以执行但是不会打开 终端
#cd /root/zlb/rfidSerialPort-v1.0.20210531/bin/
#sudo sh startup.sh
#**************
#打开新终端运行;分号隔开多条命令;exec bash防止终端一闪消失--示例
# gnome-terminal -- bash -c "cd /home/inspur/Documents/frp/;./frpc -c ./frpc.ini;exec bash"
#验证失败--没有找到原因
gnome-terminal.real -x bash -c "cd /root/zlb/rfidSerialPort-v1.0.20210531/bin/; sh startup.sh;exec bash" 

exit 0

posted on 2021-06-01 15:35  zlb  阅读(84)  评论(0编辑  收藏  举报

导航