【问题标题】:How can I run a command at boot?如何在启动时运行命令?
【发布时间】:2013-05-25 06:32:29
【问题描述】:

我试图弄清楚如何在启动时运行命令,就像我将它输入控制台一样。我在我的 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

【问题讨论】:

  • 您尝试运行的命令实际上是三个单独的命令; 1.“sudo”以超级用户身份运行下一个命令。 2. “screen”是终端多路复用器,然后是 3. “mono server.exe”,如果我们根据文件名判断,它是调用可执行文件的运行时。如果没有更多信息,很难知道为什么它不能工作。

标签: command debian raspberry-pi startup boot


【解决方案1】:

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

【讨论】:

  • 实际会在特定用户账号ssh登录后运行。它在启动时没有运行。
【解决方案2】:

简单易行的答案,你去/etc/rc.local 并添加你的命令。

别忘了,你的脚本必须以“exit 0”结尾。

【讨论】:

    【解决方案3】:

    这种方式在 Raspberry 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
    

    这是我发现在 Raspberry Pi 上工作的唯一方法(我每次启动时都会启动 VNC 服务器)。

    【讨论】:

    • 可以,但是screen不能连接到终端吗?
    • screen 可能必须开始分离才能使其工作:screen -dm &。并在前面加上sleep 60,让系统处于可以成功启动IRC客户端irssi并连接IRC频道的状态。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-05-29
    • 2010-10-09
    • 1970-01-01
    • 2020-12-31
    • 1970-01-01
    • 2021-12-31
    • 1970-01-01
    相关资源
    最近更新 更多