Raspberry Pi-Cron, Crontab (scheduled task), croncrontab
Cron is a tool for configuring scheduled tasks in Unix systems. It is used to execute commands or scripts on a regular basis or at a certain interval; the task scope can be to automatically back up the user's home folder every night, or to record CPU information logs every hour.
The crontab (cron table) command is used to edit the list of scheduled tasks in execution. The operation is based on each user, and each user (including the root user) has its own crontab.
Editing crontab (edit crontab)
Run crontab and-e to edit the cron table:
crontab -e
Select an ediror (select an editor)
The first time you run the crontab command, you will be prompted to select an editor. If you are not sure which one to use, you can press enter to select the default nano editor.
Each cron object contains six parts: minute, hour, day of the month, and day of the week, and scheduled command.
# M h dom mon dow command # ***** command to execute # Too many commands available # │ #│ │ # │ ── ─ the day of the week (0-7) (from 0 to 6 indicates Sunday to Saturday. 7 indicates Sunday, equivalent to 0) # │ └ ── ─ month (1-12) # │ └ ── ─ day in the month (1-31) # │ ── ─ hour (0-23) # └ ── ─ minute (0-59)
For example:
0 0 * * * /home/pi/backup.sh
The cron instance will execute the backup. sh script at midnight every day.
Address: http://www.raspberrypi.org/documentation/linux/usage/cron.md
Why is the cron scheduled task not executed in linux?
Can you tell me where to view cron logs? I haven't found it for a long time before, but I can't write redirection in crontab to save some information.
Later, it was not easy to store logs directly in the script.
By the way, pay attention to the following permissions and the script path.
5. Schedule Tasks: crontab
<Developer:/home/developer/UPGW/pub/bin> crontab-l
*/2 *****/home/developer/UPGW/pub/bin/angel
00 02 ***/home/developer/UPGW/pub/bin/genhkfile. sh
00 04 ***/home/developer/UPGW/pub/bin/logsave. sh
00 03 ***/home/developer/UPGW/pub/bin/databackup. sh
30 09 ***/home/developer/UPGW/pub/bin/loadfujiian. sh
00 05 ***/home/developer/UPGW/pub/bin/movetohistory. sh
20 08 ***/home/developer/UPGW/pub/bin/putbilltozb. sh
<Developer:/home/developer/UPGW/pub/bin>
The above is the instance on my machine. Generally, we need to compile it. Input crontab-e and press the one I wrote above to enter the time when the task is executed, as well as the scripts and programs to be run, after that, input (: q) to save the settings like vi.
Use the following command to enable or stop crontab and load crontab.
/Sbin/service crond start
/Sbin/service crond stop
/Sbin/service crond restart the service
/Sbin/service crond reload re-load configuration