How can I run a command at boot?

余生长醉 提交于 2019-12-09 11:51:21

问题


I'm trying to figure out how to run a command at boot, like I would type it into the console. I'm using Rasbian with my Raspberry Pi, but I think this question is the same for Debian in general. The command I'm trying to run is:

sudo screen mono server.exe

I tried the following solution, but since I just started with Linux, I'm not sure if this is correct.

 #! /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:


Simple
Run cd ~
Then edit .profile
At the bottom, put whatever you would like.




回答2:


This way has worked best for me on the pi:

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

Set file name to whatever you want as long as it has.desktop on the end:

nano screen_mono.desktop

Then write this in that file changing commands to suit your needs:

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

This is the only method that I have found to work on the pi.(I start a VNC server every time it starts)




回答3:


The simple and easy answser, you go to /etc/rc.local and add your commands.

Dont forget, your script MUST end with "exit 0"



来源:https://stackoverflow.com/questions/16823361/how-can-i-run-a-command-at-boot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!