Score:0

Ubuntu - run bash script on startup with visible terminal

cn flag

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!

Liso avatar
sd flag
By terminal visible, did you mean the terminal will open and execute your script inside it. for your example would be `echo`-ing `hello` ?
lnee avatar
td flag
konsole -e runs comands
pa4080 avatar
cn flag
Does this answer your question? [How can I show notify-send messages triggered by crontab?](https://askubuntu.com/questions/978382/how-can-i-show-notify-send-messages-triggered-by-crontab)
Black Solis avatar
cn flag
@Liso yes, I want the .sh script to run in a visible GUI terminal window.
Score:0
cn flag

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.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.