[英]Ubuntu - run bash script on startup with visible terminal
我想在 Ubuntu 20.04 啟動時運行 bash 腳本,終端可見。 test.sh 文件位於 /usr/bin/test.sh。 我可以讓 test.sh 文件在啟動時運行,但不能在可見終端 window 中運行。
test.sh 的內容:
#! /bin/bash
echo "hello";
我無法讓它工作,我已經嘗試過(個人):
Crontab(帶和不帶 '&' 和帶/不帶“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" &
啟動應用程序命令
sudo bash /usr/bin/test.sh
bash /usr/bin/test.sh
/usr/bin/test.sh
在 /etc/systemd/system/testService.service 創建服務
[Unit]
Description = Test Service
[Service]
WorkingDirectory= /usr/bin
ExecStart= /usr/bin/test.sh
[Install]
WantedBy=multi-user.target
並啟動,啟用和檢查狀態..
systemctl start testService.service
systemctl enable testService.service
systemctl status testService.service
但未能啟動。
任何幫助/指向更好的方向將不勝感激!
要在運行腳本時顯示 GUI 終端 window:
添加到“啟動應用程序”(在命令下):
bash test.sh
test.sh 的內容:
#! /bin/bash
DISPLAY=:0.0 xterm -hold -e bash helloWorld.sh
helloWorld.sh 的內容:
#! /bin/bash
echo "hello";
對我來說,這在登錄時打開了一個 XTerm 終端 window 並運行 helloWorld.sh 腳本。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.