准备工作
#本地源
[root@localhost yum.repos.d]# cat base.repo
[base]
name=base
baseurl=file:///mnt/BaseOS
gpgcheck=0
[app]
name=appstream
baseurl=file:///mnt/AppStream
gpgcheck=0
[root@localhost yum.repos.d]# mount /dev/sr0 /mnt
[root@localhost yum.repos.d]# ll /mnt/AppStream/
total 986
dr-xr-xr-x. 2 root root 1005568 Apr 4 2020 Packages
dr-xr-xr-x. 2 root root 4096 Apr 4 2020 repodata
[root@localhost yum.repos.d]# ll /mnt/BaseOS/
total 296
dr-xr-xr-x. 2 root root 301056 Apr 4 2020 Packages
dr-xr-xr-x. 2 root root 2048 Apr 4 2020 repodata
第一部分 网络服务
第一章 例行性工作
1、单一执行的例行性工作
单一执行的例行性工作:仅处理执行一次就结束了
1.1 at命令的工作过程
/etc/at.allow,写在该文件的人可以使用at命令
/etc/at.deny,黑名单
两个文件如果都不存在,只有root能使用
#at工作调度对应的系统服务
[root@localhost ~]# systemctl status atd
#at的工作文件存放目录
[root@localhost ~]# ll /var/spool/at
#at工作的日志文件
[root@localhost ~]# ll /var/log/cron
1.2 at命令详解
命令格式: at [参数] [时间]
参数:
-m 当任务完成之后,即使没有标准输出,将给用户发送邮件
-l atq的别名,可列出目前系统上面的所有该用户的at调度
-d atrm的别名,可以取消一个在at调度中的工作
-v 使用较明显的时间格式,列出at调度中的任务列表
-c 可以列出后面接的该项工作的实际命令内容
-f 从文件中读取作作业
时间格式:
HH:MM 在今天的HH小时MM分钟执行,如果今天的这个时间点已经过了,则明
天执行
HH:MM YYYY-MM-DD 强制规定在某年某月的某一天的特殊时刻进行该工作
now + 2 minutes 从现在开始几分钟minutes, hours, days, or weeks
#定义三分钟之后显示hello
[root@server ~]# at now + 3 minutes
2、循环执行的例行性工作
循环执行的例行性工作:每隔一定的周期就需要执行一次
2.1 crontab的工作过程
/etc/cron.allow,写在该文件的人可以使用crontab命令
/etc/cron.deny,黑名单
两个文件如果都不存在,只有root能使用
#crontab工作调度对应的系统服务
[root@localhost ~]# systemctl status crond
#crontab工作的日志文件
[root@localhost ~]# ll /var/log/cron
#用户定义计划任务的文件所在目录
[root@localhost ~]# ll /var/spool/cron/
2.2 crontab命令详解
[root@localhost ~]# crontab --help
crontab: invalid option -- '-'
crontab: usage error: unrecognized option
Usage:
crontab [options] file
crontab [options]
crontab -n [hostname]
Options:
-u <user> define user
-e edit user's crontab
-l list user's crontab
-r delete user's crontab
-i prompt before deleting
-n <host> set host in cluster to run users' crontabs
-c get host in cluster to run users' crontabs
-s selinux context
-V print version and exit
-x <mask> enable debugging
2.3 系统的计划任务
[root@localhost ~]# cat /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR
sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed