Linux Cron Scheduled Tasks

Source: Internet
Author: User

$ crontab-e

Example: Execute at two o ' clock every day

0 2 */1 * */usr/bin/python/www/tbktsh/sendms.py &>/dev/null

* * * * * Root run-parts/etc/cron.hourly # every hour to execute scripts within/etc/cron.hourly, "run-parts" This parameter refers to the execution of all files under the folder, do not add this parameter need to give explicit execution script file.

$ Service Crond Restart Or/etc/init.d/crond Restart # restart scheduled task

Note Set executable permissions for script files Oh, otherwise it might not work.

The first column represents the minute (0-59)

The second column represents the Hour (0-23)

The third column represents the day (1-31)

The fourth column represents the month (1-12)

The fifth column represents the week (0-6) 0 for Sunday

"*" represents all numbers within the range of values. "*" is equivalent to "*/1" if used directly

"/" stands for every meaning

"*/5″ means every 5 units

"-" represents a number to a number

"," scattered figures

# Example of Job definition:

#. —————-minute (0–59)

# | . ————-Hour (0–23)

# |  | . ———-Day of Month (1–31)

# |  |  | . ——-month (1–12) OR jan,feb,mar,apr ...

# |  |  |  | .--Day of Week (0–6) (sunday=0 or 7) or Sun,mon,tue,wed,thu,fri,sat

# |  |  |  | |

# * * * * * command to be executed

Using CRONTAB-E as root directly is equivalent to editing the/var/spool/cron/root file, which is a user-level scheduled task.

If you set the system level Schedule task, edit the/etc/crontab.

Cron periodically scans all files in the/var/spool/cron/folder every minute (each user will have a timed task file named after the user name) and the/etc/crontab file.

The difference between a user-scheduled task and a system-scheduled task is to send a task message to a different person, and the system schedules the task to be sent to the system administrator, and the user's scheduled task is to send the task message to the current user.

1. Edit directly with crontab command

The Cron service provides the crontab command to set the Cron service, and here are some of the parameters and instructions for this command:

Crontab-u//Set a user's Cron service, which is usually required by the root user when executing this command

CRONTAB-L//list details of a user cron service

Crontab-r//Delete a cron service with no users

CRONTAB-E//Edit a user's cron service

For example, root to view your cron settings: Crontab-u root-l

Again, for example, Root wants to delete Fred's cron settings: Crontab-u fred-r

Schedule Log Related

The/var/log/cron file is the execution record for all scheduled tasks

/var/log/cron.1/var/log/cron.2/var/log/cron.3/var/log/cron.4 These files are archived files

When Crond performs a task failure, it sends a message to the user, and if Crond fails, it can be viewed through the mail log and can be viewed using tail-f/var/spool/mail/root to see the specific error message.

The task in crontab adds its own log, which makes it easier to see why the error output and the standard output are output to MyLog.log after an error.

0 6 * * */www/shservice/task.sh >>/tmp/mylog.log 2>&1

Supplemental knowledge: Anacron can wake up work tasks during shutdown

Linux Cron Scheduled Tasks

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.