0

I've been trying to get a very simple startup script but no matter what I try I can't get it to actually run on boot. For simplicity sake I while testing I just wanted to open my Browser, which works perfectly fine when manually executing the script. I'm using Ubuntu 22 LTS. The script itself looks the following and is named:

#!/bin/bash
google-chrome

I tried everything, from placing the script under home/user and naming it startup.sh, trying to get it executed via a cronjob using @ Reboot or using init.d and later even trying to write up a systemd service. NOTHING WORKS. How can it take me multiple days of googling and nothing works? I've already tried the following tutorials and troubleshooting instructions: https://www.baeldung.com/linux/run-script-on-startup https://medium.com/@girishbhasinofficial/configuring-a-script-to-run-at-startup-on-ubuntu-22-04-ffe1f3e649d1 https://www.squash.io/executing-bash-script-at-startup-in-ubuntu-linux/ https://linuxconfig.org/how-to-run-script-on-startup-on-ubuntu-20-04-focal-fossa-server-desktop https://stackoverflow.com/questions/12973777/how-to-run-a-shell-script-at-startup

1 Answer 1

2

It seems: You don't want to run this on boot, but as soon as your graphical session starts; and that's the complication here.

All the methods you've tried are starting things, ripped out of context of the graphical session you're in.

That can't work! You need to start the browser from within the context of a running desktop environment. How would the browser display anything without knowing where (and being allowed to) display a window? How would it get keyboard and mouse input, output sound?

So, these methods you found are all for a different use case.

By the way, your desktop environment has a "startup applications", or "autostart", or similar configuration tool. (KDE, Gnome, XFCE4, cinnamon, mate, … all do! So, there's something that you can click on to solve this issue, unless you're using something very strange/custom, but then you'd probably not be the kind of user that would need help with this, no offense at all intended there!).

In case that configuration center isn't there, in ~/.config/autostart/, you can put .desktop files.

For example, I start my password manager like this: There's a file called mypasswordmanager.desktop

[Desktop Entry]
Name=KeePassXC
GenericName=Password Manager
Exec=keepassxc
TryExec=keepassxc
Terminal=false
Type=Application

And so, every time my graphical user session starts, my password manager (keepassxc) also gets started. I'm sure you can modify that to start your browser – or just copy your browser's .desktop file from e.g. /usr/share/applications/org.mozilla.firefox.desktop to your ~/.config/autostart.


Regarding your sources:

  • Baeldung: known for low-quality content, probably mostly AI-generated nonsense, usually mixes things that were already old 20 years ago with things that are modern and don't quite work like described. The article you linked to is a prime example of that. I'd recommend blocking that website out of your search results.

  • random medium post: uh, this guy is copying baeldung.

  • squash.io: article starts with machine-generated stock image. You can close it at that point. No useful content to be expected afterwards. (I know this sounds cynic, but not once have I found what I was looking for and was accurate on such articles. They get written to get page impressions through google search, not to help people. YOU ARE A HUMAN! Don't waste your time reading text that noone even bothered to write in the first place, but let an LLM write for them. LLMs are terrible at technology; they can make good smalltalk, but they have inherently absolutely no understanding of what they're writing about.)

  • the linuxconfig article: not perfect, but it's very nicely illustrated and someone took care to explain what they're doing there! Note how the article is about running a script, not a browser, on startup? And note how this seems to only wait for network to be available, not for graphical interface!

  • stackoverflow: that's how you found the linuxconfig article.

5
  • Tip: On Ubuntu, hit Win.key, then type Startup and you will see Startup Applications Preferences; it allows at least some things to be automated, for starting at login. Commented Nov 17, 2024 at 14:07
  • @Hannu not a Ubuntu thing, but a GNOME/Gnome Shell thing; not all Ubuntus use Gnome, though it is the default desktop environment on the default Ubuntu spin. Commented Nov 17, 2024 at 14:12
  • "Ubuntu" (exactly so) == Ubuntu with Gnome in my world, so well... ;-) Commented Nov 17, 2024 at 14:23
  • @Hannu no offense taken! I just tend to think that sometimes, being a tiny bit more precise in terminology (using word A when A is meant, instead of word B, where B is somewhat related to A) is often a very helpful thing to not confuse beginners :) Commented Nov 17, 2024 at 14:29
  • Agree with that. :-) often a single "missing" word may cause major confusion. Commented Nov 17, 2024 at 14:33

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.