How to customize at and cron scheduled tasks in Linux

How to customize at and cron scheduled tasks in Linux

There are two types of scheduled tasks in Linux system, one is the at scheduled task which will only be executed once, and the other is the cron scheduled task which can be executed periodically.

at One-time scheduled tasks

describe

Execute a specific command (single time) at a specified time, also called a delayed action task.

usage

at time [Enter]

parameter

at -l #List single scheduled tasks at -r task id ##Delete the task with this id at -d task id ##Delete the task with this id at -m #Make the command without output generate email at -M #Make the command with output generate email at -c task id ##View the action of the task with this id at -f file ##Use the commands recorded in the file as the execution commands of the delayed task

Examples

First check the system time

[root@test ~]# date
Thu May 17 18:40:11 CST 2018

Specify a single scheduled task (delayed action)

[root@test ~]# at 18:45 ##Plan executed at 18:45 on the same day (18:45 2018-05-17)
at> date ##Scheduled task content at> shutdown -h now ##Scheduled task content at> <EOT> ##Command input ends, press Ctrl+D to exit job 10 at Thu May 17 18:45:00 2018 ##The system prompts that there is a scheduled task numbered 10

Cron periodic scheduled tasks

To use cron to schedule tasks, you need to ensure that the crond service is enabled and starts automatically at boot.

# systemctl start crond
# systemctl enable crond

describe

Maintain a periodic cron job file for each user.

usage

crontab [ -u user ] [ -l|-r|-e ]

Options

parameter usage
-u Specify the user for the scheduled task. If -u is not specified, the current user is used by default.
-l View scheduled tasks
-r Deleting a scheduled task
-e Editing a scheduled task
-i When deleting a scheduled task using -r, the user is asked to confirm the deletion

corn plan task format

Item 1 Item 2 Item 3 Item 4 Item 5 Item 6
point hour day moon week Order
00~59 00~23 1~31 1~12 1~7 action

If you need to specify a time period, you can use a hyphen (-) to indicate a continuous period of time, a comma (,) to indicate several discontinuous periods of time, an asterisk (*) to indicate all periods of time, and a division sign (/) to indicate intervals of time.

Example

[root@test ~]# crontab -e
: : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : :

Cron scheduled task permissions

To prevent users from arbitrarily defining their own scheduled tasks, administrators can implement ACL access control. The control files for the at scheduled tasks are /etc/at.allow and /etc/at.deny. By default, at.llow does not exist. The control files for cron scheduled tasks are /etc/cron.allow and /etc/cron.deny. By default, cron.allow does not exist.

The above article on how Linux users can customize at and cron scheduled task execution is all I have to share with you. I hope it can give you a reference, and I also hope that you will support 123WORDPRESS.COM.

You may also be interested in:
  • Detailed explanation of using the at command for one-time scheduled tasks in Linux
  • Detailed explanation of how to use cron scheduled tasks in Linux
  • Brief discussion: Summary of commonly used symbols for Linux cron scheduled tasks
  • Introduction to scheduled tasks in Linux system

<<:  Simple writing of MYSQL stored procedures and functions

>>:  WeChat applet realizes taking photos and selecting pictures from albums

Recommend

Vue mobile terminal determines the direction of finger sliding on the screen

The vue mobile terminal determines the direction ...

Detailed installation process of mysql5.7.21 under win10

This article shares the installation of MySQL 5.7...

MySQL full-text search Chinese solution and example code

MySQL full text search Chinese solution Recently,...

Simple implementation of vue drag and drop

This article mainly introduces the simple impleme...

jQuery realizes the shuttle box function

This article example shares the specific code of ...

How to insert weather forecast into your website

We hope to insert the weather forecast into the w...

Detailed explanation of character sets and validation rules in MySQL

1Several common character sets In MySQL, the most...

HTML code that can make IE freeze

We simply need to open any text editor, copy the f...

Linux IO multiplexing epoll network programming

Preface This chapter uses basic Linux functions a...

Detailed steps for installing Tomcat, MySQL and Redis with Docker

Table of contents Install Tomcat with Docker Use ...

Detailed explanation of this pointing in JS arrow function

Arrow function is a new feature in ES6. It does n...

About MariaDB database in Linux

Table of contents About MariaDB database in Linux...

CSS imitates Apple's smooth switch button effect

Table of contents 1. Code analysis 2. Source code...