正文開始
首先先將要執行的內容(例如想要跑 Python 的程式等等)寫成 Shell script 存起來,例如:
#! /bin/bash
echo "hms5232 is Good!" >> /home/pi/example.txt
然後存成 Shell script 並且加上執行的權限:
chmod +x /home/pi/example.sh
接著修改/etc/rc.local:
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
fi
# 把你要執行的 shell script 放在這邊
/home/pi/example.sh
# 切記,結尾要是 exit 0 這行
exit 0
重新開機後就會看到 example.txt 在/home/pi 底下了。