Execute scripts using crontab timer under Linux

Source: Internet
Author: User
Tags centos server

Many times we need a server to run a command at a certain time, such as executing a script.

Then we can install "crontabs" this software.

It is installed by default on my CentOS server and is not installed to run:

Yum Install vixie-cronyum install Crontabs

Vixie-cron package is the main program of Cron;
The Crontabs package is a program used to install, uninstall, or list tables used to drive the cron daemon.

The commands for starting the service, shutting down the service, restarting the service, and re-loading the configuration are as follows:

// Start the service // Close Service // Restart Service // Reload Configuration

View the current service status for Crontab: Service Crond Status

After you start the Crontabs service, you can add the same tasks with CRONTAB-E.

Of course also can edit/etc/crontab this file also line.

The format written under the file is: * * * * * ' task '

such as the following:

The first ' * ' is a minute. (0-59)

The second ' * ' is an hour. (0-23)

The third ' * ' is the day. (1-31)

The fourth ' * ' is the month. (1-12)

The fifth ' * ' is a week. (0-6 of course 0 and 7 can represent Sunday)

Here are a few examples.

* * * * * ls//execute the LS command once every minute7* * * * ls//The LS command is executed 7 minutes per hour*/7* * * * ls//execute a LS command every 7 minutes7     7* * * ls//7 points per day, 7 minutes. Execute the LS command7     7     7* * ls//every month, 7th, 7, 7. Execute the LS command once7     7     7     7/8* ls//every year, July and August, 7th, 7, 7, execute the LS command .7     7*     *0Ls//every Sunday, 7 points, 7 minutes. Execute the LS command

At first I used this to execute the PYTHON3 program, but found that the. py suffix is not an executable file, what should I do?

Find a method on the Internet, you can write a shell script to run the Python3 program, so you can schedule to execute the PYTHON3 program.

As shown below:

That's perfect.

Execute scripts using crontab timer under Linux

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.