tofubob
Posts: 4
Joined: Mon Oct 27, 2014 1:11 am

Can't get a shell script to Autostart

Tue Oct 28, 2014 5:12 am

I'm attempting to run ScratchGPIO on boot of the gui in raspbian. I have the following file set up and have tried two methods to auto start it. I'm a total newbie so speak slowly. Big thanks in advance.

Shell Script - this is located in the folder /home/pi/.config/autostart/scratchauto.sh. I want the script to run once the raspbian GUI boots.

Code: Select all

cd /home/pi/scratchgpio5
sudo python scratchgpio_handler5.py &
scratch presentation "/home/pi/scratchgpio5/scratchApp.sb"
I've tried the following 2 methods to get it to auto run:

Method 1 - crontab

Code: Select all

@reboot sh /home/pi/.config/autostart/scratchauto.sh >home/pi/logs/cronlog 2>&1
It didn't work and didn't show anything in the log folder

Method 2 - etc/rc.local
My first attempt at getting it to run by adding a command to the etc/rc.local file

Code: Select all

sudo /home/pi/.config/autostart/scratchauto.sh
I tried this one in case it was the user that was the issue....

Code: Select all

su - pi -c " /home/pi/.config/autostart/scratchauto.sh"

knute
Posts: 550
Joined: Thu Oct 23, 2014 12:14 am
Location: Texas
Contact: Website

Re: Can't get a shell script to Autostart

Wed Oct 29, 2014 4:28 am

The format for files in ~/.config/autostart is to name them something.desktop. The syntax as far as I can tell is:

[Desktop Entry]
Name=TheNameYouWantToShowUpInTheFileManager
Type=Application
Exec=path/to/script.sh
Icon=path/to/icon.png

That will start the script, path/to/script.sh, when the GUI starts. I'm using it to start a couple of GUI programs and to turn off the screensaver. Seems to work just fine.

IgorZ
Posts: 1
Joined: Wed Nov 05, 2014 3:28 am

Re: Can't get a shell script to Autostart

Wed Nov 05, 2014 3:33 am

Hello!
I installed on my Raspberry Pi OS http://www.raspberrypi.org/downloads/ (NOOBS) then set x11vns. Then do all the operations described here http://www.thefruitycomputer.com/forums ... -raspbian/ but when booting the OS user pi server x11vnc not strarte. What is the reason? How do I configure autostart x11vnc server as user pi or how do I change the user runs by default at startup RaspberryPi?

knute
Posts: 550
Joined: Thu Oct 23, 2014 12:14 am
Location: Texas
Contact: Website

Re: Can't get a shell script to Autostart

Thu Nov 06, 2014 3:07 am

IgorZ wrote:Hello!
I installed on my Raspberry Pi OS http://www.raspberrypi.org/downloads/ (NOOBS) then set x11vns. Then do all the operations described here http://www.thefruitycomputer.com/forums ... -raspbian/ but when booting the OS user pi server x11vnc not strarte. What is the reason? How do I configure autostart x11vnc server as user pi or how do I change the user runs by default at startup RaspberryPi?
I haven't used x11vnc, I have installed tightvncserver. Here are the instructions I recorded for doing that. Use sudo where appropriate.


Install VNC server:
apt-get install tightvncserver

tighvncserver /to enter password

add script below to /etc/init.d that starts and stops the vncserver then
update-rc.d script defaults


### BEGIN INIT INFO
# Provides: vncboot
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start VNC Server at boot time
# Description: Start VNC Server at boot time.
### END INIT INFO

#! /bin/sh
# /etc/init.d/vncboot

#USER=root
#HOME=/root
USER=pi
HOME=/home/pi

export USER HOME

case "$1" in
start)
echo "Starting VNC Server"
#Insert your favoured settings for a VNC session
#/usr/bin/vncserver :0 -geometry 1920x1080 -depth 24
sudo -u pi /usr/bin/vncserver :0 -geometry 1920x1080 -depth 24
;;
stop)
echo "Stopping VNC Server"
/usr/bin/vncserver -kill :0
;;
*)
echo "Usage: /etc/init.d/vncboot {start|stop}"
exit 1
;;
esac

exit 0

lisztfr
Posts: 8
Joined: Sun Nov 16, 2014 1:18 pm

Re: Can't get a shell script to Autostart

Sun Nov 23, 2014 10:53 am

Well it doesn't work for me. VNC just won't start, i have to start it manually, also adafruit's method to create a desktop script in the .config/autostart directory doesn't work (it crashes the RPI)

Thanks, L

lisztfr
Posts: 8
Joined: Sun Nov 16, 2014 1:18 pm

Re: Can't get a shell script to Autostart

Sun Nov 23, 2014 11:51 am

Ok, it's working now...


pi@raspberrypi ~ $ cat /etc/init.d/vncboot
### BEGIN INIT INFO
# Provides: vncboot
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start VNC Server at boot time
# Description: Start VNC Server at boot time.
### END INIT INFO

#! /bin/sh
# /etc/init.d/vncboot

#USER=root
#HOME=/root
USER=pi
HOME=/home/pi

export USER HOME

case "$1" in
start)
echo "Starting VNC Server"
#Insert your favoured settings for a VNC session
#/usr/bin/vncserver :0 -geometry 1920x1080 -depth 24
sudo -u pi /usr/bin/tightvncserver :1 -geometry 1024x768 -depth 16
;;
stop)
echo "Stopping VNC Server"
/usr/bin/tightvncserver -kill :1
;;
*)
echo "Usage: /etc/init.d/vncboot {start|stop}"
exit 1
;;
esac

exit 0

Return to “Raspberry Pi OS”