-1

I am trying to run a python script at ubuntu startup. The script(play.py) plays a youtube video in chrome browser.

import webbrowser
import time
import subprocess as sp

val = 0;
while(val <1):
    time.sleep(1)
    #webbrowser.open("https://www.youtube.com/watch?v=dO1rMeYnOmM")
    child = sp.Popen("google-chrome %s" % "https://www.youtube.com/watch?v=dO1rMeYnOmM", shell=True)
    val = val +1

To run this script at ubuntu startup I added the following entry in rc.local:

python /home/user_name/Desktop/python/play.py &

And changes the mode of play.py to 777. I also tried copying this script file to /etc/init.d. But still the script does not execute at system startup.

triandicAnt
  • 1,328
  • 2
  • 15
  • 40

1 Answers1

0

Try sudo /usr/bin/python /home/user_name/Desktop/python/play.py & instead.

r0xette
  • 898
  • 3
  • 11
  • 24
  • What is not working? The command or the script is not working upon loading? First ensure that the following command works fine. `/usr/bin/python /home/user_name/Desktop/python/play.py &` – r0xette Nov 03 '16 at 20:12
  • `sudo /usr/bin/python /home/user_name/Desktop/python/play.py &` I added in `rc.local` but the browser is not opening at system startup. – triandicAnt Nov 03 '16 at 20:16
  • We are back to square one. You still didn't answer whether the command only worked on terminal or not? First establish the command is working fine on terminal and then try to automate it. So again? What happened when you ran the command on terminal? – r0xette Nov 03 '16 at 20:17
  • Everything in `/etc/rc.local` is run as root, there's no need to use `sudo`. – Barmar Nov 03 '16 at 20:18
  • @triple.s add sheband on top of the script. `#!/usr/bin/python` – r0xette Nov 03 '16 at 20:21
  • @r0xette still does not work while including python path – triandicAnt Nov 04 '16 at 02:26