目录
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/bash
path="/home/pi/autoExec"
time=$date
touch $path/time.log #新建记录时间的日志 time.log
chmod 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
2019年 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 "