0

Can anyone please help me to run a simple python script at start up? (for eg. let the script print hello) please explain me step by step,,,starting from basic steps!

I tried many examples using init.d & rc.local but not worked... may be I had gone wrong! so be precise,clear,step by step starting from basic step!

sachin
  • 1
  • 1
  • 2
    Given that you have tried many examples it seems unlikely that a new example will help you. Why not show us the closest to working example you have tried? – joan Feb 20 '15 at 11:41
  • @joan: friend,,, I have asked this question since i tried many methods even the link u have mentioned...but not working! May be I have wrong with the steps and thats why I have asked for a step by step answer. so please help me with the question posted! – sachin Feb 20 '15 at 12:05
  • 1
    Please provide more information on what you tried. Also try finding log output(or create it yourself) and provide this too. – Izzy Feb 20 '15 at 12:17
  • @MKzero : I want to run a script which prints "hello" at sartup/boot. so i kept this script file in /home/pi as hello.py and used sudo nano rc.local to edit rc.local and added location as follows; /usr/bin/python3 /home/pi/hello.py just before exit o & saved it. But at start up it gives the error either as invalid syntax or exit: illegal number o! – sachin Feb 20 '15 at 12:40
  • Can we see the python code (add it to your question)? and does the script run from the command prompt (e.g. python3 hello.py)? – Steve Robillard Feb 20 '15 at 12:49
  • As per the answer to the duplicate question, the easiest way to do this is just add the path to the script to the end of /etc/rc.local like this: /path/to/myscript.py &. No sudo, and the & is important. If this does not work, you should provide post the content of /etc/rc.local and the script on Unix & Linux. – goldilocks Feb 20 '15 at 13:21
  • Tell me the format to create the .sh file to put it in /etc/rc.local and my python script is this: print'hello' ie to print hello at boot/startup. and tell me the other things also! & somtimes it gives me error as 'permission denied'! @SteveRobillard – sachin Feb 20 '15 at 14:51
  • Still Waiting for positive reply – sachin Feb 23 '15 at 09:45

1 Answers1

0
sudo bash

create a file in /etc/init.d name it like vncboot.sh

sudo nano /etc/init.d/vncboot.sh

then

chmod 755 /etc/init.d/vncboot

then

update-rc.d /etc/init.d/vncboot defaults

if it says

update-rc.d: error: unable to read /etc/init.d//etc/init.d/vncboot

use

update-rc.d vncboot defaults

source: http://elinux.org/RPi_VNC_Server#Instructions | section: run at boot

  • Beware that there are pretty strict rules about the format of that .sh file, see /etc/init.d/README. This is the more complicated way to go and not really necessary if you just want something to run once at boot. – goldilocks Feb 20 '15 at 13:22
  • sorry @user3599188 i have no knowledge regarding 'vnc' and moreover dont want to use and hope there is still a simple way for doing this process. – sachin Feb 20 '15 at 14:56
  • waiting for a favourable reply! – sachin Feb 23 '15 at 09:46