1

I have been struggling with this all day. My set up is a RPi 3 B, running Raspbian.

I need to simply fulfil the following:

  1. Once booted automatically open Terminal
  2. cd to/my/directory
  3. run_my_script.py
  4. After 10 minutes, close terminal (or reboot) and repeat

I have limited knowledge of shell and desktop scripts.

Chetan Bhargava
  • 1,262
  • 3
  • 15
  • 29
Infernez
  • 11
  • 1
  • 2
  • You want to reboot RPi every 10 minutes after running the script? why? You probably don't need to launch terminal to run a python script. – hcheung Jan 10 '18 at 10:41

1 Answers1

1

wrote a bash script with folling content:

#!/bin/bash

python3 /path_to_your_script/python_script.py


sudo shutdown -r +10
# or with sleep
sleep(600)
sudo reboot now

r: reboot

+10: 10 minutes

go to:

sudo nano /etc/rc.local

and fill in the path to bash script, before the exit 0 statement:

bash /path_to_bash/bash_script.sh &

of course you could do it with python so you would not need a separate bash script

https://docs.python.org/3/library/subprocess.html

bierschi
  • 350
  • 1
  • 2
  • 7
  • Thanks for the advice, I will attempt to implement this now.

    One query I have is that the script seems to not have a command to open the terminal window, is this not possible in a bash script?

    – Infernez Jan 10 '18 at 08:09
  • to open a terminal, use command "lxterminal -e "command_to_execute" http://manpages.ubuntu.com/manpages/precise/en/man1/lxterminal.1.html – bierschi Jan 10 '18 at 09:57
  • Here is my script.
     #!/bin/bash
    
     lxterminal -e "cd /home/pi/iot-hub-python-raspberrypi-client-app/ && 
     python wbuoy4.py"
    
    
     sudo shutdown -r +10
    
    – Infernez Jan 10 '18 at 11:09