Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

328
Visualizações
Autostart does not work after user reboot

I want to autostart a sh script after reboot.

I add below line to /etc/xdg/lxsession/LXDE-pi/autostart.

@/home/pi/mog/run.sh

Everything works fine if i plug the raspberrypi-2 to power line or switch on it after halt. However when i run shell command sudo shutdown -r now the autostart method does not work after reboot?

I want to run a C++ application after reboot and my run.sh script is below.

#!/bin/bash sleep 5 /home/pi/mog/mog -platform xcb

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

I guess it depends on what type of shell script you are trying to run.

Looks like there are several ways to do it:

1. Start with Console

Create a file for your startup script and write your script in the file:

 $ sudo nano /etc/init.d/superscript
 Save and exit: Ctrl+X, Y, Enter

Make the script executable:

 $ sudo chmod 755 /etc/init.d/superscript

Register script to be run at startup:

 $ sudo update-rc.d superscript defaults

2. Start At Login

Make sure you are in the pi folder:

 $ cd ~

Create a file and write a script to run in the file:

 $ sudo nano superscript

Paste contents of sh script here

 Save and exit: Ctrl+X, Y, Enter

Open up .bashrc for configuration:

 $ sudo nano .bashrc

Scroll down to the bottom and add the line: ./superscript

 Save and exit: Ctrl+X, Y, Enter

3. Start with Desktop Environment

(Your method which sounds like its not working for your needs)

over 4 years ago · Santiago Trujillo Relatório

0

I suggest to edit your crontab.

$crontab -e

or

$sudo crontab -e

The last line should be

@reboot /home/pi/mog/run.sh

If it doesn't work you can try creating an autostart folder

mkdir ~/.config/autostart
cd ~/.config/autostart

create a .desktop file like this:

[Desktop Entry]
Type=Application
Exec=yourscript.sh
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name=Startup Script

Move your yourscript.sh in /usr/local/bin folder and it should run after reboot

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda