Page 1 of 1

Cant run .sh on boot

Posted: Wed Mar 28, 2018 8:03 am
by ne0c
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

Re: Cant run .sh on boot

Posted: Wed Mar 28, 2018 8:25 am
by pcmanbob
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.

Re: Cant run .sh on boot

Posted: Wed Mar 28, 2018 10:09 am
by ne0c
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

Re: Cant run .sh on boot

Posted: Wed Mar 28, 2018 6:01 pm
by ne0c
.sh has +x permissions. And log.txt is empty. :(

Im totally stuck

Re: Cant run .sh on boot

Posted: Wed Mar 28, 2018 7:44 pm
by pcmanbob
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

Re: Cant run .sh on boot

Posted: Thu Mar 29, 2018 2:59 am
by KLL
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.

Re: Cant run .sh on boot

Posted: Thu Apr 05, 2018 5:13 pm
by ne0c
Fixed!

That was the problem! Running on autostart its ok.

Thanks very much