赞
踩
开机运行写好的脚本文件,启动terminal,执行ros及相关桌面程序
gnome-terminal -x bash -c “roscore; exec bash;”
编辑/etc/rc.local
文件完成此功能,在exit 0
之前写入要执行的代码即可。可以加入如下代码片段,方便查看执行情况
#log
exec 2> /tmp/rc.local.log # send stderr from rc.local to a log file
exec 1>&2 # send stdout to the same log file
set -x # tell sh to display commands before execution
开机后,在/tmp/rc.local.log
文件中可以看到该文件执行的具体信息
可以运行到这个脚本,但运行不了terminal.
在etc/init.d/
文件夹下,可以看到很多脚本,最好任意打开一个作为参照仿写。
cd /etc/init.d/
sudo touch new.sh #这个文件夹好像不需要sudo权限
先尝试脚本能不能正常运行,可能会遇到以下错误:
insserv: script new.sh is not an executable regular file, skipped!
# 需要给权限
sudo chmod +x /etc/init.d/new.sh
insserv: warning: script 'xxxx' missing LSB tags and overrides
insserv: Starting nifi depends on plymouth and therefore on system facility `$all' which can not be true!
需要仿照其它文件,加上说明头:
### BEGIN INIT INFO
# Provides: scriptname
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start daemon at boot time
# Description: Enable service provided by daemon.
### END INIT INFO
继续操作,设定更新,具体可以查看开头的参考文章,90是执行顺序
sudo update-rc.d new.sh defaults 90
理论上,这样更新rc-d
之后,会生成S90
开头的软链接,但我操作完生成的软链接都是S01
开头的…尴尬…
移除上面生成的软链接:
sudo update-rc.d -f new.sh remove
与方法1是同样的,在这个级别启动时,桌面尚未启动,运行不了terminal.
设置Linux自启服务以及优先级,这一篇讲的很复杂,照着做的时候做到创建软链接
sudo ln -vsf /etc/init.d/proxyserver S98proxyserver
不知道是不是我没有-vsf
,系统提示我不能这样创建,就停在这里了。
将写好的脚本赋予权限后,在左上角搜startup applications
,出来对话框后,直接增加一个,在command
里面输入要运行的脚本文件路径即可。
这种方式适合启动桌面程序,执行优先级最低
找不到的话,命令行运行也可以起到同样的效果:
gnome-session-properties
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。