Play Raspberry Pi-Add timed tasks

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.