Linux system timing tasks and delayed tasks

1. System delay task
at 09:20 #Set task execution time
at> rm -fr /mnt/* #Enter task content
at> <EOF> #When writing is completed, press ctrl+d to end the at interface and initiate the task
#Note, the <EOF> here is not hand-typed, but automatically generated after ctrl+d
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

at -l #View the task queue
Insert picture description here
at -c task number#View the content of the task
Insert picture description here
Insert picture description here

at -r task number#cancel the task
Insert picture description here
at now+1min
#delay one minute at> echo hello westos #input task content
at> <EOF>
Insert picture description here
When the delayed task has output, it will be sent to the task by email Originator of

dnf search mail #Find mail installation package
Insert picture description here

dnf install postfix.x86_64 mailx.x86_64 #Install the mail service and mail viewing tool
Insert picture description here
Insert picture description here
mail #Check the mail, and enter the mail number after it, you can see the content of the mail #When the
Insert picture description here
task is executed, you can see the delayed task execution Mail sent to root user after completion
#Press q to exit mail view
Insert picture description here

mail -u root #View super user mail

 > /var/spool/mail/root
#删除邮件

Insert picture description here

2. Black and white list of at command

Everyone can use the at command

/etc/at.deny #Blacklist, added users cannot use the at command
/etc/at.allow #Whitelist, all ordinary users in the system cannot execute the at command after the whitelist is created, only users in the whitelist are Allowed
#Attention, super users are not restricted by the whitelist
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
3. System timing tasks

crontab time representation

分钟  小时        日      月 星期
*/2    09-17     3,5     1    5          

#3rd and 5th of January, and every Friday, from 9:00 to 17:00, every two minutes

  *   *    *   *   *   #每分钟
*/2   *    *   *   *  #每两分钟

Insert picture description here
Insert picture description here
crond.service #Timed tasks take effect when the program is started
systemctl enable --now crond.service #Open service
Insert picture description here
crontab -e #setting
Insert picture description here
Insert picture description here
Insert picture description here

crontab -l #List tasks
crontab -r
Insert picture description here
#Delete tasks ccrontab -e -u root #Initiate the task and specify the user as the super user
Insert picture description here
Insert picture description here
/var/spool/cron/root #crontab task storage location, who initiated the crontab file name is who
Insert picture description here
4. Black and white list of crontab command

/etc/cron.deny #Blacklist, added users cannot use the crontab command
/etc/cron.allow #Whitelist, after the whitelist is created, all ordinary users in the system cannot execute the crontab command, only the users in the whitelist are Allowed
#Attention, super users are not restricted by the whitelist
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

5. System-level cron (by file)
Insert picture description here
Insert picture description here
path: /etc/cron.d/
vim westos #Specify
Insert picture description here
Insert picture description here
that the user root will create /mnt/westosfile{1…5} every second
Insert picture description here
Insert picture description here

#Because it is a system-level cron, so use crontab -l can not see
Insert picture description here
6, the management of temporary files in the system

systemd-tmpfiles --cat-config
can be used to view the strategy of temporary file creation
Insert picture description here
/usr/lib/tmpfiles.d/
#temporary file path vim westos.conf #Create a temporary file, the suffix must be .conf
Insert picture description here
Insert picture description here
d /mnt/westos 1777 root root 5s
#d file type is directory; /mnt/westos is file path and name; 1777 is file permission, root file user, root file user group; 5s is file life cycle under /mnt/westos/

systemd-tmpfiles --create /lib/tmpfiles.d/westos.conf #Make
the written temporary files take effect
Insert picture description here
systemd-tmpfiles --clean /lib/tmpfiles.d/westos.conf #Clean
up temporary files, but only when temporary files arrive The life cycle can only be deleted, otherwise it can’t be deleted.
# Like here, after 5s, the westosfile1 file created in /mnt/westos/ is cleared, not the /mnt/westos/ directory itself.
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

systemd-tmpfiles --clean /lib/tmpfiles.d/*.conf #If
you want to clean up all temporary files in the system, you can use this command

Guess you like

Origin blog.csdn.net/shanshuyue/article/details/113438920