Running script upon startup ubuntu using crontab

5,321

Apart from what steeldriver wrote, a well known problem is that cron needs the full path. So, try:

@reboot /bin/sh /home/ubuntu/script
Share:
5,321

Related videos on Youtube

Ajayv
Author by

Ajayv

Updated on September 18, 2022

Comments

  • Ajayv
    Ajayv over 1 year
    gnome-terminal -x python abc.py
    

    I have a script that runs the above code. I have added the following line to crontab.

    @reboot sh /home/ubuntu/script
    

    My script is executable, but upon reboot I am not able to execute the python program. I am able to do this when I run the script manually.

    • steeldriver
      steeldriver about 7 years
      reboot is not the time to start GUI applications - put it in your user's Startup Applications
  • steeldriver
    steeldriver about 7 years
    Good advice in general, but /bin is most definitely in cron's default path (set up a cronjob to run printenv if you don't believe me)
  • Animesh Srivastava
    Animesh Srivastava almost 6 years
    Yes, @steeldriver, but in the context of the cron startup, the shell environment you normally have is not loaded, so you need to specify the full path to sh (or bash if you like).
  • steeldriver
    steeldriver almost 6 years
    @LifeBoy fromman 5 crontab: "Several environment variables are set up automatically by the cron(8) daemon. SHELL is set to /bin/sh, and LOGNAME and HOME are set from the /etc/passwd line of the crontab's owner. PATH is set to "/usr/bin:/bin"."