
我想我開始發瘋了。到目前為止我已經嘗試了幾件事,但沒有任何效果。
這是 Ubuntu 22.04 LTS 桌面版本。
我嘗試了這個指南: https://www.baeldung.com/linux/run-script-on-startup
我的腳本檔案非常簡單,使用此 IP/頁面以 kiosk 模式啟動 chromium 瀏覽器。
chromium-browser -kiosk -incognito https://google.com
將此檔案儲存為 /usr/local/ 中的tiles.sh 然後我 chmod +xtiles.sh
我嘗試過的第一個選項: crontab -e |我在其中添加了:
@reboot root /usr/local/tiles.sh
我嘗試的第二件事是將其添加到到底行主資料夾中的 .profile 中。沒有什麼...
sh /usr/local/tiles.sh
然後我嘗試使用 Ubuntu 內建的“啟動應用程式首選項”,同樣什麼也沒有... https://itsfoss.com/manage-startup-applications-ubuntu/
Name; Tiles, Path: /usr/local/tiles.sh, I didn't add any comments.
第四件事是將tiles.service加入systemctl中
[Unit]
description=Tiles
[Service]
Type=simple
ExecStart=/bin/bash /usr/local/tiles.sh
[Install]
WantedBy=multi-user.target
chmod 644 /etc/systemd/system/tiles.service
systemctl 啟用tiles.service
systemctl啟動tiles.service
重啟
那麼,有人可以告訴我我在這裡做錯了什麼嗎?
編輯:
所以我修復了缺少 / 的複製貼上錯誤,因此路徑看起來不完整
評論表明“crontab -e”僅適用於“啟動時”的內容,因此這是行不通的。
答案1
克朗有它自己的路徑,它被硬編碼並設定為:
/usr/bin:/bin
這意味著只有安裝在這兩個目錄中的程式才能透過 cron 按名稱啟動。 Firefox 安裝在/usr/bin/firefox
,因此firefox
足以讓 cron 找到它,但 chromium 是作為 snap 套件安裝的,並且很可能安裝在/snap/bin/chromium
。這意味著您的腳本無法找到它,chromium
而是需要完整路徑。如果您將腳本更改為:
/snap/bin/chromium-browser -kiosk -incognito https://google.com
一般來說,您可以運行type command
來尋找命令的路徑。因此type chromium-browser
將為您提供可執行檔的路徑。
答案2
修復方法是sudo apt purge chromium-browser -y
切換到 Firefox