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
at -l #View the task queue
at -c task number#View the content of the task
at -r task number#cancel the task
at now+1min
#delay one minute at> echo hello westos #input task content
at> <EOF>
When the delayed task has output, it will be sent to the task by email Originator of
dnf search mail #Find mail installation package
dnf install postfix.x86_64 mailx.x86_64 #Install the mail service and mail viewing tool
mail #Check the mail, and enter the mail number after it, you can see the content of the mail #When the
task is executed, you can see the delayed task execution Mail sent to root user after completion
#Press q to exit mail view
mail -u root #View super user mail
> /var/spool/mail/root
#删除邮件
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
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 * * * * #每两分钟
crond.service #Timed tasks take effect when the program is started
systemctl enable --now crond.service #Open service
crontab -e #setting
crontab -l #List tasks
crontab -r
#Delete tasks ccrontab -e -u root #Initiate the task and specify the user as the super user
/var/spool/cron/root #crontab task storage location, who initiated the crontab file name is who
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
5. System-level cron (by file)
path: /etc/cron.d/
vim westos #Specify
that the user root will create /mnt/westosfile{1…5} every second
#Because it is a system-level cron, so use crontab -l can not see
6, the management of temporary files in the system
systemd-tmpfiles --cat-config
can be used to view the strategy of temporary file creation
/usr/lib/tmpfiles.d/
#temporary file path vim westos.conf #Create a temporary file, the suffix must be .conf
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
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.
systemd-tmpfiles --clean /lib/tmpfiles.d/*.conf #If
you want to clean up all temporary files in the system, you can use this command