I set crontab to execute a bash script at boot
@reboot bash /home/user/linuxconfig/startup.sh
During every boot I see the bash is executed because it creates dummy files.
#!/usr/bin/bash
touch /home/user/linuxconfig/test.txt
chromium-browser https://open.spotify.com/
touch /home/user/linuxconfig/test2.txt
The files are created but chromium won't open. When I execute the script after boot on a terminal, it opens chromium.
What am I doing wrong ?
Edit: I tried to open directly chromium from crontab so I don't have to deal with the bash part:
@reboot /usr/bin/chromium-browser --no-sandbox >> /home/user/linuxconfig/log/startupCrontab.log 2>&1
also the log gave me :
[856:856:0427/103429.042950:ERROR:ozone_platform_x11.cc(243)] Missing X server or $DISPLAY [856:856:0427/103429.043040:ERROR:env.cc(257)] The platform failed to initialize. Exiting.
so I tried to set the DISPLAY:
@reboot export DISPLAY=:0
@reboot /usr/bin/chromium-browser --no-sandbox >> /home/user/linuxconfig/log/startupCrontab.log 2>&1
But the result is the same, the log still says that the $DISPLAY or X server is missing.
I'm starting to wonder if it is even possible to start a graphical application during the crontab call. Since the DISPLAY is missing during this step, but when I start chromium after boot it's working fine and $DISPLAY is set to :0 automatically
Cron isn't appopriate mechanism to automatically start graphical desktop applications. The @reboot
entries defined in the
crontab file are run when the cron daemon starts, at which time a desktop environment session hasn't been started, and the display server may not yet be running at all. Also, the environment variables required to connect to the display server are not set by default.
You can automatically launch the Chromium browser during the startup of your desktop environment by creating a Desktop Application Autostart configuration file ~/.config/autostart/chromium.desktop
like this:
[Desktop Entry]
Type=Application
Name=Chromium
Exec=chromium-browser
Comment=Start Chromium when logging into the desktop