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
Related videos on Youtube
Author by
Ajayv
Updated on September 18, 2022Comments
-
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 about 7 yearsreboot is not the time to start GUI applications - put it in your user's Startup Applications
-
-
steeldriver about 7 yearsGood advice in general, but
/bin
is most definitely in cron's default path (set up a cronjob to runprintenv
if you don't believe me) -
Animesh Srivastava almost 6 yearsYes, @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 almost 6 years@LifeBoy from
man 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"."