How can I run a command at boot time?

I am trying to figure out how to run a command at boot, for example, I would type it in the console. I use 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 as follows:

sudo screen mono server.exe 

I tried the following solution, but since I just started working 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 
+4
source share
3 answers

Plain
Run cd ~
Then edit .profile
Put whatever you want below.

+4
source

This method worked better for me on pi:

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

Specify the file name, if you want, as long as it has .desktop at the end:

 nano screen_mono.desktop 

Then write this in the file change 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 I have found for working with pi. (I start the VNC server every time it starts)

+2
source

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

Remember that your script MUST complete with "exit 0"

+1
source

Source: https://habr.com/ru/post/1483448/


All Articles