iT邦幫忙

0

怎麼讓 raspberry pi開機執行sh腳本

mahir 2018-02-13 22:09:4812476 瀏覽
  • 分享至 

  • xImage

我想讓 raspberry pi
開機後自動執行Network UPS Tools

這兩種方法我都弄了沒反應
/etc/xdg/lxsession/LXDE/autostart
[內容]==================
@lxpanel --profile LXDE
@pcmanfm --desktop --profile LXDE
@xscreensaver -no-splash
@sh /home/pi/run.sh

/etc/rc.local
[內容]==================
#autostart
/home/pi/run.sh

run.sh (權限777)
[內容]==================
sudo systemctl start nut-server
sudo systemctl status nut-server

不知道是哪裡弄錯了
還是有別種方法可以達成?
另外我開小黑窗直接執行run.sh是有成功的

看更多先前的討論...收起先前的討論...
froce iT邦大師 1 級 ‧ 2018-02-13 22:25:12 檢舉
你這兩個都是開x-window才會執行吧?
你都用了systemctl,請用 sudo systemctl enable nut-server,這樣開機應該就會自動執行。
mahir iT邦新手 4 級 ‧ 2018-02-13 22:31:18 檢舉
enable
沒辦法
會顯示
The unit files have no installation config (WantedBy, RequiredBy, Also, Alias
settings in the [Install] section, and DefaultInstance for template units).
This means they are not meant to be enabled using systemctl.
mahir iT邦新手 4 級 ‧ 2018-02-13 22:43:32 檢舉
Loaded: loaded (/lib/systemd/system/nut-driver.service; static; vendor preset: enabled)
看到關鍵字了... 「static」enable不能用...
froce iT邦大師 1 級 ‧ 2018-02-13 23:03:57 檢舉
那就用老方法,rc.local 試試看。

https://www.dexterindustries.com/howto/run-a-program-on-your-raspberry-pi-at-startup/
froce iT邦大師 1 級 ‧ 2018-02-13 23:26:43 檢舉
後來又查了一下。
https://bbs.archlinux.org/viewtopic.php?id=147964

Static units are those which cannot be enabled/disabled, but it doesn't mean they are always executed. They will only if another unit depends on them, or if they are manually started.

Actually, static units are simply those without an [Install] section. As enabling units means just creating a symlink to wherever [Install] mandates, those units without [Install] section cannot be enabled, as systemctl doesn't know where to place the symlink.

Of course, you can still manually create a symlink from a static unit to (for instance) /etc/systemd/system/multi-user.target.wants/, and it will be executed as any other enabled unit. But I suppose static units are not intended to be enabled in that way, and most probably you shouldn't need to do it

http://linux.vbird.org/linux_basic/0560daemons.php
看起來應該可以自己修改。讓他可以enable。
mahir iT邦新手 4 級 ‧ 2018-02-14 09:57:58 檢舉
在底下加了這行
[Install]
WantedBy=multi-user.target

enable 是可以了
但一樣沒執行
家誠 iT邦新手 2 級 ‧ 2019-02-11 15:01:58 檢舉
放錯地方了, 不能放在rc.local. 要放在rc.local.bak 就會動了. 不然就是自己寫個service 也可以
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答