目录
1.目的
2.思路
3.实现步骤
1.目的:树莓派开机时自动执行某些脚本,不用手动设置,减少麻烦。
2.思路:新建一个记录时间的脚本 record_time.sh,然后添加执行命令到 /etc/rc.local文件中
3.实现步骤
(1) 新建一个 bash shell 脚本
$ touch /home/pi/autoExec/record_time.sh
(2) 往 record_time.sh 脚本添加如下内容
#!/bin/bashpath="/home/pi/autoExec"time=$datetouch $path/time.log #新建记录时间的日志 time.logchmod 777 $path/time.log #给 time.log 添加权限echo $time >> $pwd/time.log #往 time.log 输入时间
(3) 给予脚本 record_time.sh 权限并执行,得到 time.log,查看time.log
$ chmod 777 record_time.sh$ bash ./record_time.sh$ cat time.log 02月 23日 星期六 20:00:05 CST
(4) 在 /etc/rc.local 文件中添加执行脚本命令
# 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) || trueif [ "$_IP" ]; thenprintf "My IP address is %s\n" "$_IP"fibash ./home/pi/autoExec/record_time.sh #添加这条命令,路径是绝对路径exit 0
(5) 查看time.log得
02月 23日 星期六 20:00:05 CST 02月 23日 星期六 20:06:17 CST
结论:结果表明,记录重启时间成功