Raspberry Pi boot automatically run a shell script - record boot time

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/qq_25908839/article/details/87894445

table of Contents

1. Purpose

2. Ideas

3. Implementation steps

 

1. Purpose: Raspberry Pi is performed automatically when turned on some scripts, do not manually set, reduce trouble.

2. The idea: Create a new script record_time.sh time record, and then add the command to execute /etc/rc.local file

3. Implementation steps

(1) Create a bash shell script

$ touch /home/pi/autoExec/record_time.sh 

(2) add the following script to 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) to give the script and execute permissions record_time.sh, get time.log, see time.log

$ chmod 777 record_time.sh
$ bash ./record_time.sh
$ cat time.log
2019年 02月 23日 星期六 20:00:05 CST

(4) add execute script commands in /etc/rc.local file

# 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

bash ./home/pi/autoExec/record_time.sh  #添加这条命令,路径是绝对路径

exit 0

(5) View time.log too

2019年 02月 23日 星期六 20:00:05 CST

2019年 02月 23日 星期六 20:06:17 CST

Conclusion: The results show that the recording restart time success

 

Guess you like

Origin blog.csdn.net/qq_25908839/article/details/87894445