2013-05-29 269 views
4

我想弄清楚如何在启动时运行一个命令,就像我将它输入到控制台。我在Raspberry Pi上使用了Rasbian,但我认为这个问题对于Debian来说是一样的。我试图运行的命令是:如何在启动时运行命令?

sudo screen mono server.exe 

我尝试了以下解决方案,但因为我刚开始使用Linux,我不知道这是否是正确的。

#! /bin/sh 
# /etc/init.d/server 

### BEGIN INIT INFO 
# Provides:   server 
# Required-Start: $remote_fs $syslog 
# Required-Stop:  $remote_fs $syslog 
# Default-Start:  2 3 4 5 
# Default-Stop:  0 1 6 
# Short-Description: Simple script to start a program at boot 
# Description:  .. 
### END INIT INFO 

# If you want a command to always run, put it here 
sudo screen mono server.exe  

exit 0 
+0

你试图运行的命令实际上是三个单独的命令; 1.作为超级用户运行下一个命令的“sudo”。 2.作为终端多路复用器的“屏幕”,然后是3.“mono server.exe”,如果我们通过文件名来判断,它是一个运行时调用可执行文件。很难知道为什么没有更多的信息它不工作。 – jeremiah

回答

1

简单易用的answser,你到/etc/rc.local并添加你的命令。

不要忘记,你的脚本必须以 “退出0” 结尾

4

简单
运行cd ~
然后编辑.profile
在底部,放置任何你想。

2

这样已经工作最适合我的PI:

cd /home/pi 
cd .config 
mkdir autostart 
cd autostart 

设置文件名以任何你想要的,只要它具有.desktop的结尾:

nano screen_mono.desktop 

然后在写这篇文章该文件更改命令,以满足您的需求:

[Desktop Entry] 
Type=Application 
Name=Screen_mono 
Exec=sudo screen mono server.exe 
StartupNotify=false 

这是我唯一的方法发现在pi上工作(我每次启动时启动一个VNC服务器)