1

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!

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

This answer worked well, instead I gave path/to/bash.sh as command and it still worked.
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.

3 Comments

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.
You should report a bug, if Gnome does not work as expected.
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.