1

I'd like to start Android Studio while my computer starting. I used crontab and @reboot parameter:

crontab -e

and scheduled this task

@reboot /home/ziko/reboot_cron.sh # JOB_ID_1
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

then in my home dir added script - reboot_cron.sh

echo "It is now $(date +%T) on $(date +%A)" >> cron_reboot.log
/opt/android-studio/bin/studio.sh

After restart my computer I didn't see log in cron_reboot.log and Android Studio wasn't fired. What did I wrong?

UPD. I added second scheduled task and it works

#!/bin/sh
#!/bin/bash
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

@reboot root /home/ziko/reboot_cron.sh # don't work!
*/5 * * * * /home/ziko/mycrontest.sh   # it works!

And if I manully run reboot_cron.sh then it works but in crontab it don't!

1 Answers1

-1

Did you try "@reboot root su -l ziko sh (script.sh)" from system crontab?

You may not get @reboot to work as non-root.

-

In system /etc/crontab:

@reboot root su -l (user_to_run_as) (your_sh_script)

or non-root 'crontab -e' user:

@reboot sh (your sh script)

( per : https://askubuntu.com/a/549646/169878 )

-

Note: I am not entirely sure if you need to be root to execute @reboot properly via crond under Ubuntu or Debian (or for that matter if it needs to be in the system wide crontab). Try the "@reboot sh " first and see if that works as non-root user.. Also consult https://unix.stackexchange.com/q/109804

EDIT:

Unless you really need this executed via crond, it might be a better idea to set this up as an init script (based on runlevel) or rc.local entry.. either one can be executed on a normal startup. Your script will execute after system is completely up. Since you do not need much more control over the script other than having it execute at startup (once), rc.local should be fine.

Example for "rc.local":

sudo nano /etc/rc.local

add this line before 'exit 0':

su -l ziko /opt/android-studio/bin/studio.sh

save.

sudo chmod 755 /etc/rc.local

(Reboot.) 'studio.sh' should have executed/started as the ziko user on startup

B. Shea
  • 1,252