2

The main idea is to make my pc run a script on boot in wich x11docker takes care of lifting a container with a youtube video.

this is mi crontab -e:

@reboot /usr/local/sbin/script-exo.sh

script im trying to run:

#!/bin/bash
x11docker --xephyr -I exo-test

script is located in /usr/local/sbin

the status of cron.service is active (running), logs doesn't have any issue or warning. Also, the script by itself it's fine, if i run bash script-exo.sh it works. I've also tried to run the script with SystemD and Init.d but nothing makes it start on boot. Any suggestion?
x11docker repo https://github.com/mviereck/x11docker

ømen
  • 21
  • 1
    Is x11docker a GUI tool? From the name, I assume it runs under X, right? Starting graphical tools with cron is not straightforward. Can you please [edit] your question and explain what the final objective is since it might be enough to run this when you log in and not on reboot. Next, change your cron line to @reboot /usr/local/sbin/script-exo.sh 2>/tmp/cron.xd.log and then reboot and show us the contents of /tmp/cron.xd.log. Finally, try changing x11docker in the script to instead be the full path to the x11docker executable. – terdon Feb 09 '24 at 12:37
  • 1
    That is probably because the command in your script requires a display server/session which might not be available/accessible during boot ... Please see Startup script not executing and How can I launch a script in a terminal window from a service – Raffa Feb 09 '24 at 13:13
  • @terdon Yes it does. The main idea is to use x11docker to run a container wich displays a youtube video.,i added that to the crontab and nothing was created inside tmp, also added the path to the executable. – ømen Feb 09 '24 at 13:34
  • @Raffa i add the startup program, it executes when the pc starts but it needs sudo privileges to work. The command i added: Sh -c '/usr/local/bin/x11docker --xephyr -I exo-test'. It's not really clear to me, is that the correct way this works? – ømen Feb 09 '24 at 13:37
  • 1
    small sh i.e. sh -c 'x11docker --xephyr -I exo-test' ... If sudo is a must, then probably see https://askubuntu.com/a/425762 and change it to something like sh -c 'sudo x11docker --xephyr -I exo-test' – Raffa Feb 09 '24 at 13:53
  • forgot to mention that i added my user to the sudo group with: addser username sudo – ømen Feb 09 '24 at 13:54
  • already tried adding sudo and nothing executes – ømen Feb 09 '24 at 13:55
  • 1
    That is not enough as it will still ask for password in the background ... You'll need to set that particular command for that particular user to be passwordless in the sudoers file ... See How do I run specific sudo commands without a password? – Raffa Feb 09 '24 at 13:56
  • i added the following lines to visudo: " username ALL=(ALL) NO PASSWD path/to/script " and " username ALL = NOPASSWD: ALL ". The second one was because the first didn't work. still same error – ømen Feb 09 '24 at 14:12
  • could it be that is trying to run the script before docker starts? – ømen Feb 09 '24 at 14:42

1 Answers1

0

This was solved using StartUp apps preferences from ubuntu 20.04. You just add the command: sh -c 'path/to/script' and in the bash script i added sudo at the start.

Also this post provided by @Raffa was super usefull How to set a timer that starts when I login and then alerts after a set time

ømen
  • 21