Reputation: 81
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!
Upvotes: 1
Views: 9104
Reputation: 81
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.
Upvotes: 1
Reputation: 23794
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.
Upvotes: 0