树莓派开机自动运行shell脚本——记录开机时间

目录

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 "
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值