我一整天都在面对启动脚本问题。
我正在寻找一种在启动/登录前 这将配置我的机器并运行适当的服务。(所有用户使用单一脚本会很酷 - 易于维护)
简单脚本“/machineSetup.sh”
#LC_NUMERIC - Specifies the decimal delimiter
export LC_NUMERIC="en_US.UTF-8"
#-------------------------------------------------------------------
#add custom aliases path
export PATH=$PATH:/home/user/aliases
#-------------------------------------------------------------------
#run backburnerServer (tool to control remote computing) run process
/usr/discreet/backburner/backburnerServer &
#-------------------------------------------------------------------
#run x11vnc run process
/usr/bin/x11vnc &
我在 Ubuntu14.04 上。我已经用 /etc/rc.local 做过测试,但毫无效果。我试过 /etc/profile.d/machineSetup.sh,但只有在登录后才有效。
如果你能给我一些提示就太好了。是否可以将配置存储在单个文件中?提前感谢你的建议!
答案1
您可以从以下位置启动任何脚本
/etc/rc.local
最好创建一个 upstart .conf 文件。这些文件存储在
/etc/init/*.conf
例如,以下是该文件的内容/etc/init/hostname.conf
:
#
# This task is run on startup to set the system hostname from /etc/hostname,
# falling back to "localhost" if that file is not readable or is empty and
# no hostname has yet been set.
description "set system hostname"
start on startup
task
exec hostname -b -F /etc/hostname
另一个解决方案是使用 crontab 功能@reboot
,了解有关crontab 在这里
答案2
声明环境变量通常在 ~/.profile 中完成,因此您只需将这些行添加到该文件的末尾即可。我不确定这是否回答了您的问题,但如果您同意执行脚本登录时,你应该尝试将脚本添加到你的启动应用程序。只需打开 dash,输入启动应用程序,然后点击添加。输入你喜欢的任何名称,然后在命令字段浏览到您的脚本。然后单击添加,您就完成了。
答案3
从 rc.local 调用时,您需要有一个可执行的 shell 脚本:
sudo -i
vi /machineSetup.sh
内容:
#!/bin/bash
#LC_NUMERIC - Specifies the decimal delimiter
export LC_NUMERIC="en_US.UTF-8"
#-------------------------------------------------------------------
#add custom aliases path
export PATH=$PATH:/home/user/aliases
#-------------------------------------------------------------------
#run backburnerServer (tool to control remote computing) run process
/usr/discreet/backburner/backburnerServer &
#-------------------------------------------------------------------
#run x11vnc run process
/usr/bin/x11vnc &
使其可执行:
chmod 0755 vi /machineSetup.sh
答案4
我不知道为什么我没有早点想到这一点。您所要做的就是在文本编辑器中打开 /etc/rc.local,然后将脚本的内容粘贴到文件中的行之前exit 0
。我知道这确实有效,因为我让我的笔记本电脑在启动时自动关闭蓝牙。