How to run shell commands on debian startup?

Asked

Viewed 5,830 times

1

I need you to call my Raspberry pi 3 for it to execute the following scripts:

$cd ~/Desktop
$source ~/.profile
$workon cv
$python raspberry.py

only that, then it will already run my program directly.

  • Do you have any graphical user interface installed ??

  • I got it, it’s the Raspbian

1 answer

3

Follow the steps:

  1. Create a file for your script and write the commands in it.

    $ sudo nano /etc/init.d/SEUSCRIPT
    
    • Example:

      #!/bin/bash 
      echo "Script de exemplo"
      
  2. Save and get out: CTRL+ X, Y, ENTER

  3. Permission to be executable

    $ sudo chmod 755 /etc/init.d/SEUSCRIPT
    
  4. Logs the script to run on startup

    $ sudo update-rc.d superscript defaults
    

Obs: SEUSCRIPT is the name of the file you want to create


If you want to start when you boot into the environment LXDE do:

  1. Sail to:

    ~/.config/lxsession/LXDE-pi
    
  2. Open the file autostart

    $ sudo nano autostart
    
  3. Add each command in a new row
  4. Save and get out: CTRL+ X, Y, ENTER
  5. Reboot the system.

For more information raspberrypi stackexchange

  • i want to start as soon as you boot the system. Can you show me what the syntax of the script is like? I don’t work with linux. is just I write my commands in a script.sh ? will the $ in front or just write normal.

  • Yes I will edit put an example of Script

  • had seen that you have to use #!/bin/sh in Raspberry, do you have any idea if bash works normal? If I choose to sh mute anything else than you had explained to me?

  • #!/bin/sh is just a link to #!/bin/bash

Browser other questions tagged

You are not signed in. Login or sign up in order to post.