Linux system timing tasks and delayed tasks

The maximum time unit of a scheduled task is month

1. System delay task

at 23:37 ##Set task execution time
at>rm -fr /mnt/*

Use ctrl +d to end the at interface and initiate a task action
at -l ##View task queue
at -r task number##Cancel task
at -c ## View task content
Insert picture description here
at now+1min ##Execute
echo hello westos
as the command in 1 minute When there is output, it will be sent to the current user in the form of an email.
Experimental conditions:

Need to build a software warehouse.
Download the software
postfixx.x86_64 mailfixx.x86_64 to
open the mail service
Insert picture description here
Insert picture description here
at command: all users of the system can execute it.
Restrict users who execute the at command. The
whitelist has high priority.
man 5 at.deny
Insert picture description here

Blacklist directory: /etc/at.deny
Whitelist: /etc/at.allow does not exist by default in the system.
Note: After the whitelist is created, all ordinary users cannot execute the at command, and only whitelist users can execute at

Demo:
When there is linux in the user blacklist, the
Insert picture description here
blacklist still exists.
Insert picture description here
Note: It is unrealistic to manage the permissions of the root user!

Timed tasks of the system

Experiment premise
Service name:
Insert picture description here

Experiment
min hour day mouth week
@ @ @ @ @ ##Every minute
@/2 @ @ @ @ ##Every two minutes
@/2 09-17 @ @ @ ##早7到晚5 Every two minutes
@/2 09 -17 3,5 1 5 ## The 3rd and 5th of January or the 5th every two minutes

Note: @ represents*

Storage directory: /var/spool/cron/
/user name
crontab command
-e ##Set-
l ##List tasks-
r ##Delete tasks-
u ##Specify users
Note: Only super users can initiate Specify the user.

User blacklist directory: /etc/cron.deny
User whitelist directory: /etc/cron.allow
Note: Super users are not restricted. When the
whitelist exists, the blacklist will not be read by default

Insert picture description here

Insert picture description here
2. System-level crontab
directory: /etc/cron.d/
root user to set
crontab -l (cannot view system-level crontab)

Demonstration: Ensure the purity of the experimental environment
Turn off the whitelist and blacklist

Insert picture description here
Temporary file cleaning


Insert picture description here
Temporary files of systemd-tmpfiles can be deleted after the set life cycle ends.
Insert picture description here
/lib/tmpfiles.d/westos.conf
d /mnt/westos 1777 root root 5s
/usr/lib and /lib are
Insert picture description here
deleted by a user : The deletion method is to delete the absolute path of the temporary file

Guess you like

Origin blog.csdn.net/Antonhu/article/details/113413140