launching python script in terminal at boot and keeping open if/when exception

Viewed 770

writing a data logging program that is intended to run when raspberry boots. I'm using lxsessions autostart to launch a shell script that has the command to launch my python program (my python script requires sudo)

while I continue to debug I would like the terminal window to stay open if/when it encounters an error.

I had done this successfully once before but lost my work.

my autostart file is:

#!/bin/bash
@lxpanel --profile LXDE-pi
@pcmanfm --desktop --profile LXDE-pi
@lxterminal -e sudo sh /home/pi/launcher.sh
@xscreensaver -no-splash

my script file is:

#!/bin/sh

echo Script is running

sudo /usr/bin/python3 /home/pi/hms/hms5-1.py

I thought something like this (in the autstart file) would work, but no:

@lxterminal -e -hold sudo sh /home/pi/launcher.sh

a simple internet search spit out of examples on how to execute command at boot, even launching scripts but nothing has helped so far. Thank you in advance.....

1 Answers

So I rebuilt my Raspberry Pi and had to go through this again. So after I was able to get it to work once, I followed my instructions from before, edited them to be clearer the posted here. NOTE - I think the mistake I made before was using sudo (sudo nano) when I should have just used nano....

Also note the python program I am launching is /home/pi/hms/hms2-v2.py

*** setting this up is a 4 step process *** YOU MUST HAVE XTERM

STEP 1 - INSTALL XTERM:

sudo apt-get install xterm

STEP 2

read https://www.raspberrypi.org/forums/viewtopic.php?t=227191

FIRST CREATE autostart here: /home/pi/.config/lxsession/LXDE-pi/autostart NOTE THE FOLDERS BELOW /home/pi/.config/ MAY NOT EXIST, IF NOT CREATE THEM EXACTLY AS ABOVE. NOTE: the directory must be LXDE-pi NOT LXDE

Then edit the autostart file by using nano ~/.config/lxsession/LXDE-pi/autostart

NOTE: DO NOT use sudo in the above command put the following in the file:

#!/bin/bash



@lxpanel --profile LXDE-pi
@pcmanfm --desktop --profile LXDE-pi
sh /home/pi/launcher.sh
@xscreensaver -no-splash

Step 3 create the script (.sh) file: launcher.sh in the directory /home/pi include the following in the file launcher.sh:

#!/bin/sh


echo starting script
xterm -T "HMS" -geometry 100x70+10+35 -hold -e sudo /usr/bin/python3 /home/pi/hms/hms2-v2.py

Step 4 make the .sh file executable with: sudo chmod +x launcher.sh

Related