Crontab and Linux Cron Task Tool

Crontab and Linux Cron Task Tool



Crontab and Linux Cron Task Tool.Everyone will encounter regular execution of a script under linux , or start a service in the cabinet, or execute our python script, etc. This article tells you how to do it. The crontab command satisfies you because I want to execute my local script regularly every
night to run automation without manual execution, just schedule the task directly.

1. Crontab command operation guide, because I just started to enter the editing mode, I don't know what it is like to save and exit, here is a tutorial .
The operation command is as follows:
crontab -u root -e Open the crontab configuration file and edit it
Ctrl + O to write content, File name to Write . . . appears , enter Enter
Ctrl +X save and output, save is complete


Introduction to configuring scheduled task time:

Execute */1 every minute * * * *
Execute 0 */5 * * * every five hours
Execute 0 0 every day * * *
Execute weekly 0 0 * * 0
Execute 0 0 1 * * per month
Executed annually 0 0 1 1 *

The interface is as follows:

When writing a script, you must import the python environment variable, or it is not easy to not execute it. Here I am stuck for a long time and finally found out that it is the problem of the environment variable, or the problem of the script permission.
# Edit this file to introduce tasks to be run by cron .
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').
#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
twenty two 20 * * * export PATH =/ usr / bin / : $ PATH ; cd / home / array / src ; python3 run.py _ _

2. After the edited content is saved, view the command crontab -l

3. Then after the configuration is completed, determine whether the task is started, and check whether the task you perform generates a log or symbolic things

For example, after my python3 run.py is executed, a log will be generated in the report directory

4. The following is a summary of the situations that are not implemented

1. Be sure to check whether the environment variables are correct
2. Or whether the script has executable permission
3. Then manually execute it to see if it is successful
4. Write the simplest demo that executes every minute to see if it will execute
Execute */1 every minute * * * *
5. Whether to install cron service, etc.
6. Whether the service is started

Related Articles

Explore More Special Offers

  1. Short Message Service(SMS) & Mail Service

    50,000 email package starts as low as USD 1.99, 120 short messages start at only USD 1.00