Linux timed tasks Execute Python script

Source: Internet
Author: User
Tags python script rsyslog

Enterprise application-On duty, 135 messages a week to the students to clean the health. The script takes advantage of Linux's timed task crontab to run once a day.

1. Turn on the crontab log.

Crontab does not turn on the log by default, so start the log of the scheduled task first to view

Modify the Rsyslog service to delete the #cron. * before the/etc/rsyslog.d/50-default.conf file; Restart the Rsyslog service with service Rsyslog restart:

2. Write timed Tasks

Crontab-e

Start the user's scheduled task, that is, to create a user name as the file name of the scheduled task file, location in/var/spool/cron/crontabs/.

The Schedule Task statement format is: Execution period + command, the period has 5 fields, respectively is

Minutes, hours, days (day of month), months (month of year), weeks (days of week).

Each domain does not limit any words with *, the overall format is:

* * * * * command

Like my script is/home/xiaofeng/cleanroom.py.

Execution Environment for/usr/bin/python3

Run at 9 o ' Day

The statement is

0 9 * * */usr/bin/python3/home/xiaofeng/cleanroom.py

Restart the Cron service after you finish writing

Service Cron Restart

By the way, enclose the usual periodic format

Execute */5 every five minutes * * * * Hourly Execution 0 * * * *       daily execution        0 0 * * * Weekly execution 0 0 * *        0 monthly execution 0 0        1 * * yearly Execution 
        0 0 1 1 *    

Linux timed tasks Execute Python script

Related Article

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.