0

I am wanting to run a bash script on startup in Ubuntu 20.04 with the terminal visible. The test.sh file is located at /usr/bin/test.sh. I can get the test.sh file to run at startup but not in a visible terminal window.

Contents of test.sh:

#! /bin/bash
echo "hello";

I can not get it to work, I have tried (individually):

Crontab (with and without the '&' and with/without "sudo")

@reboot bash test.sh &

@reboot /usr/bin/test.sh &

@reboot DISPLAY=:0 xterm -hold -e bash -c "bash test.sh" &

@reboot DISPLAY=:0 xterm -hold -e bash -c "bash /usr/bin/test.sh" &

Startup Applications Command

sudo bash /usr/bin/test.sh
bash /usr/bin/test.sh
/usr/bin/test.sh

Creating a Service at /etc/systemd/system/testService.service

[Unit]
Description = Test Service

[Service]
WorkingDirectory= /usr/bin
ExecStart= /usr/bin/test.sh

[Install]
WantedBy=multi-user.target

And start, enable and checked status..

systemctl start testService.service
systemctl enable testService.service
systemctl status testService.service

But failed to start.

Any help / pointing in a better direction would be appreciated!

Black Solis
  • 71
  • 1
  • 11

2 Answers2

1

To get a GUI terminal window to appear when you run your script:

Add to "Startup Applications" (under command):

bash test.sh

Contents of test.sh:

#! /bin/bash
    DISPLAY=:0.0 xterm -hold -e bash helloWorld.sh

Contents of helloWorld.sh:

#! /bin/bash
echo "hello";

For me, this opened an XTerm terminal window upon login and ran the helloWorld.sh script.

Black Solis
  • 71
  • 1
  • 11
0

When you start a Unix, the X server gets started at the end of the startup. And starting X clients makes only sense, when someone has logged in. So your aim "start X client when computer starts" makes no sense, because there is no X server running when you try to start the X client.

You can start X clients after login. If you use a classical installation, use .xinitrc for this. If you use a different desktop environment, use whatever this desktop environment provides you.

ceving
  • 21,900
  • 13
  • 104
  • 178
  • I use Gnome, the 'tweaks tool' simply adds a 'Startup Application', which I have already done as noted in my question but it does not run. – Black Solis Feb 03 '22 at 22:16
  • You should [report a bug](https://gitlab.gnome.org/GNOME), if Gnome does not work as expected. – ceving Feb 04 '22 at 08:41
  • Many, many Unix installations do not start up X11 automatically at any time. It is a common arrangement for modern desktop systems (and even then, an optional feature which you can turn off, or choose to not install in the first place), but by no means a feature of Unix itself. – tripleee Jul 27 '22 at 05:33