First, the system delay task
1.at delayed tasks are temporary and non-repetitive
After the delayed task is executed, the result will not be displayed in the shell, but will be sent to the executor in the form of an email
2. Check the mail mail
The file where the mail is located /var/spool/mail/root
Enter the email number to view the email details
Enter q to exit
Empty Mail > /var/spool/mail/root
3. Set up delayed tasks
at 21:18 ##Task delay timeat> date ##Executed tasks
at> <EOT> ##crtl+d, execute delayed task
at now+1min ##now+1min: Execute the task after 1min
Note: The task delay time is a whole min
at -l ##View the list of delayed tasks
at -c 3 ##Show delayed task details
atrm 3 ##Cancel the delayed task
4. Delayed task blacklist
Note: The blacklist is not for superusers
blacklist /etc/at.deny
For example: after adding the student user to the blacklist:
other users
5. Delay task whitelist /etc/at.allow ##default does not exist
Note: Whitelisting is not for superusers
Note: When the whitelist is established, the system will add all users to the blacklist by default
Second, timed tasks
1. Timed task service crond.service
The crond task starts automatically after booting, it will check the unexecuted crontab and execute it immediately
2. View the usage of crontab
man 5 crontab
hour day month week ##* means all
* * * * * ##every 1 minute
*/2 * * * * ##every 2 minutes
* */2 * * * ##every Execute once every 2 hours
* * 1, 4 * * ## Execute once every 1 minute on the
1st and 4th of each month * * * 1-4 * ## Execute once every 1 minute in 1, April
* * * * 4 ## every 1 minute every week 4
3.crontab -e ##Directly edit crontab tasks
crontab -l ##Display crontab task content
Indicates: on the 5th of every month, the /mnt directory is emptied every 3 minutes
crontab -r ##Delete all crontab tasks of the current user
crontab -e -u student ##Specify the student user to create crontab timed tasks
4. The file where crontab is located
/var/spool/cron/username
For example: /var/spool/cron/student
You can directly edit the file and execute crontab ##Deleting the file is the same as the crontab -r command
5. crontab blacklist for scheduled tasks
Note: The blacklist is not for superusers
Blacklist users /etc/cron.deny
other users
Note: Super user can specify student (blacklist) to execute crontab
6. crontab whitelist for scheduled tasks
/etc/cron.allow ##Default does not exist
Note: Whitelisting is not for superusers
Note: After establishing the whitelist, all users will be added to the blacklist by default
6. User-level crontab
/var/spool/cron/student ##Ordinary user
/var/spool/cron/root ##Superuser
7. System-level crontab ##Can only be edited by superusers
/etc/cron.d/ ##User-defined execution mode
/etc/cron.daily/ ##Execute once a day
/etc/cron.hourly/ ##Execute once per hour
/etc/cron.monthly/ ##Execute once a month
/etc/cron.weekly/ ##Execute once a week
When creating a custom crontab, you need to specify a user
例:vim /etc/cron.d/test
Note: System-level scheduled tasks will not be displayed in user-level files
8. Non-interactive editing of timed tasks
echo " ** * * * student date " >> /etc/cron.d/student
3. Temporary file management
1. Find temporary files
which systemd-tmpfiles ##Where is the query file
rpm -qf /usr/lib/tmpfiles.d/systemd-tmpfiles ##Query which package the file belongs to
rpm -ql systemd-208-11.el7.x86_64 ##Query the files generated by the package
2. Edit temporary files to generate directory information
vim /usr/lib/tmpfiles.d/hello.conf
Indicates: temporary files are stored in the /mnt/tmp directory, the permission is 1777, the root time of the user root group is 8s
3. Create temporary files
systemd-tmpfiles --create /usr/lib/tmpfiles.d/*
4. Clean up temporary files
systemd-tmpfiles --clean /usr/lib/tmpfiles.d/*