This is Meelo original play the Raspberry Pi series article
When it comes to Daoteng interesting Raspberry Pi projects, there are often time-bound tasks. For example, you need to check the bar every day, measuring the temperature per hour. In Linux, the crontab command is a good way to accomplish this task.
crontab command
The crontab command is commonly used in Unix-and Unix-like operating systems to set instructions that are executed periodically. The command reads the instruction from the standard input device and stores it in a "crontab" file for later reading and execution. The word derives from the Greek language Chronos (χρνο), which was originally meant to be time. Often, crontab stored instructions are activated by the daemon, Crond often run in the background, and every minute checks whether a scheduled job needs to be performed. This type of work is generally called cron jobs.
Instructions for use
Only the root user and the owner of the crontab file can edit the timed task, so if you log in as a PI user, don't forget to add it sudo
. The -e
parameter represents an edit (edit).
sudo crontab -e
After you enter the edit, you need to write the required command and repeat the time in a certain format. The format is as follows:
m h dom mon dow command
The Minutes (minute), The Hour (hour), the number of days (day of month), the month (month), the Day of the Week (Day of week), and the command.
The time can be a number that indicates execution at this time, or an asterisk (*), indicating that no restrictions are made and executed at any time.
View all scheduled tasks can use -l
parameters to indicate the meaning of list (list)
crontab -l
Examples of usage
Check-in script 0:1 every day
1 0 * * * python qiandao.py
Update the system at 7 points per Sunday
0 7 * * 1 apt-get update && sudo apt-get upgrade -y
Play Raspberry Pi-Add timed tasks