ne0c
Posts: 15
Joined: Tue Jul 28, 2015 7:24 am

Cant run .sh on boot

Wed Mar 28, 2018 8:03 am

Hi,

I want to run a program at startup, so I create a .sh with this code:

Code: Select all

#!/bin/bash
cd /home/pi/appFolder
screen -d -m -S screenname /.app
So, if I run this .sh on terminal using "/home/pi/start.sh" everything is ok, app starts on new screen. But my problem is I cant find the way to run on boot.

I tried to add "/home/pi/start.sh" on rc.local and didnt work. And I also try "@reboot/home/pi/start.sh" on crontab.

What Im doing wrong? Thanks

pcmanbob
Posts: 7725
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Cant run .sh on boot

Wed Mar 28, 2018 8:25 am

First question did you make the start.sh executable ?

second your cron line should be

Code: Select all

@reboot /home/pi/start.sh
note the space after reboot.

if after making your start.sh executable and correcting your corn line it still does not work change your cron line so it looks like this

Code: Select all

@reboot /home/pi/start.sh >> /home/pi/log.txt 2>&1
then after your pi boots look to see if log.txt was created and see if it contains any messages which might point to why your script is not running.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

ne0c
Posts: 15
Joined: Tue Jul 28, 2015 7:24 am

Re: Cant run .sh on boot

Wed Mar 28, 2018 10:09 am

pcmanbob wrote:
Wed Mar 28, 2018 8:25 am
First question did you make the start.sh executable ?

second your cron line should be

Code: Select all

@reboot /home/pi/start.sh
note the space after reboot.

if after making your start.sh executable and correcting your corn line it still does not work change your cron line so it looks like this

Code: Select all

@reboot /home/pi/start.sh >> /home/pi/log.txt 2>&1
then after your pi boots look to see if log.txt was created and see if it contains any messages which might point to why your script is not running.
Thanks for your help. Nope I dont remember if It made it +x. I will check. And the space of crontab was a mistake writing post. Its ok on rpi.

I will add log code and I will check what cause not working. Thanks

ne0c
Posts: 15
Joined: Tue Jul 28, 2015 7:24 am

Re: Cant run .sh on boot

Wed Mar 28, 2018 6:01 pm

.sh has +x permissions. And log.txt is empty. :(

Im totally stuck

pcmanbob
Posts: 7725
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Cant run .sh on boot

Wed Mar 28, 2018 7:44 pm

re-reading your original post it seems you are trying to create a new screen with an app running in it, with your script.

seeing as both cron and rc.local both run things in the back ground neither of them are the correct way to go about this.

you need to run your script after the desktop has started, so you need to put it in your desktop autostart file. That will run it when the desktop starts.

Code: Select all

nano /home/pi/.config/lxsession/LXDE-pi/autostart
Add a line at the bottom

Code: Select all

@/path/to/your/start.sh
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

User avatar
KLL
Posts: 1453
Joined: Wed Jan 09, 2013 3:05 pm
Location: thailand
Contact: Website

Re: Cant run .sh on boot

Thu Mar 29, 2018 2:59 am

pcmanbob wrote:
Wed Mar 28, 2018 7:44 pm
seeing as both cron and rc.local both run things in the back ground neither of them are the correct way to go about this.

you need to run your script after the desktop has started, so you need to put it in your desktop autostart file. That will run it when the desktop starts.
yes, @boot too early to start a terminal and anyhow that "screen terminals" would be owned by root??

yes "desktop autostart" i try that here, works good.
( if OP use the desktop version )

i was about to say to use the
.bashrc
but as screen is calling a new terminal , and that calls .bashrc and .....
that might have been a major f*ckup.

ne0c
Posts: 15
Joined: Tue Jul 28, 2015 7:24 am

Re: Cant run .sh on boot

Thu Apr 05, 2018 5:13 pm

Fixed!

That was the problem! Running on autostart its ok.

Thanks very much

Return to “Beginners”