
我希望我的樹莓派上有一個腳本在系統啟動時運行。這就是為什麼我在 /etc/init.d 中建立了一個腳本,該腳本連結在 /etc/rc2.d 中
這是 init.d 中的腳本:
#! /bin/sh
### BEGIN INIT INFO
# Provides: Scriptname
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Kurze Beschreibung
# Description: Bechreibung
### END INIT INFO
#Switch case fuer den ersten Parameter
case "$1" in
start)
#Aktion wenn start aufgerufen wird
/home/thomas/applications/autostart/autostart.sh
;;
stop)
#Aktion wenn stop aufgerufen wird
echo "nope"
;;
restart)
#Aktion wenn restart aufgerufen wird
echo "nope"
;;
*)
#Default Aktion wenn start|stop|restart nicht passen
echo "(start|stop|restart)"
;;
esac
exit 0
這是以下內容/home/thomas/applications/autostart/autostart.sh
:
#! /bin/sh
touch /home/thomas/kater
當我將 /etc/init.d 中腳本內的啟動命令更改為以下行時,將執行 touch 命令:
start)
#Aktion wenn start aufgerufen wird
touch /home/thomas/kater
;;
那麼為什麼它不執行單獨的腳本呢?
先謝,麥克法蘭
答案1
假設您所顯示的內容與您擁有的內容完全相同,則該腳本將無法運作,因為您有格式錯誤。shebang 行之間!#
和裡面不應有空格:/bin/sh
#!/bin/sh
touch /home/thomas/kater