如何在启动时运行Linux终端命令

4
我想在启动时启动我的树莓派上的Siriproxy服务器。我必须在终端中输入以下命令才能启动Siriproxy:
  1. cd siriproxy

  2. rvmsudo siriproxy server

是否有一种方法可以在启动时运行命令?
谢谢, David
这是我编辑的脚本:
#!/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.

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi

#I added this line
/home/pi/siriproxy server

exit 0
/etc/init.d/cron start

考虑在/etc/init.d中创建一个脚本。 - devnull
@devnull 不是的,因为我不知道如何做这个,而且我对Linux还很陌生。 - David Gölzhäuser
2个回答

2

您可以将以root身份运行的命令添加到/etc/rc.local脚本中,它们将在启动时运行。(http://ubuntuforums.org/showthread.php?t=1822137)

从树莓派终端运行:

sudo nano /etc/rc.local

在 exit 0 行之前添加以下内容:
/path/to/siriproxy server

您可以通过输入以下命令获取SiriProxy的路径:

which siriproxy

或者根据您的树莓派上安装siriproxy的方式,它可能是您cd到的任何目录的完整路径,然后在末尾添加"siriproxy"。

保存文件并重新启动以查看效果!希望这可以帮助到您。


嗯,它不起作用,请检查我的原始帖子,我现在添加了脚本。 - David Gölzhäuser
在命令行中运行 sudo (或rvmsudo) /home/pi/siriproxy server 对您有用吗?之后会发生什么 - 它会释放终端,让您可以继续发出命令,还是被SiriProxy占用了? - mh00h
如果我输入rvmsudo /home/pi/siriproxy server,会提示“权限被拒绝”。 - David Gölzhäuser
听起来你的问题不在于init脚本,而是能否成功运行siriproxy。过去你是怎么启动它的?这与cd到目录然后运行命令没有任何区别。以前它对你有用吗?现在呢? - mh00h
之前这个命令是有效的,现在也是。我发布了主要帖子中的一些命令。我的问题是我必须先进入siriproxy目录,然后执行rvmsudo siriproxy server来启动代理。 - David Gölzhäuser

1
尝试
screen -S ttlp
cd /home/pi/siriproxy

然后。
rvm siriproxy server

我还没有尝试过这个,我会在我的树莓派中安装它并帮助你。

敬礼, IC0NIC


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接