1.at命令简述
at命令的功能:在未来某一时刻执行某个任务
命令格式:at [OPTION…] TIME
此处的TIME表示指定的时间点,常用的格式如下所示:
HH:MM [YYYY-mm-dd]
noon,midnight,teatime
tomorrow
now + count time-units 此处的units表示单位,如:minutes,hours,days,weeks
常用的选项有:
-l:显示所有任务,相当于atq命令
-f FILE:从指定的文件中读取任务
-d #:删除指定的任务,相当于atrm #
-c #:查看指定的作业内容
2.cron:周期性的任务计划
cronie作为crond服务的主程序包,为其提供守护进程和相关辅助程序
要是用cron,首先要确保crond的守护进程处于运行状态
在CentOS 6 中,使用service crond status查询运行状态
在CentOS 7 中,使用systemctl status crond.service查询运行状态
向crond服务提交任务的方式不同于at,需要使用专用的配置文件,而且文件有固定的格式;不建议直接使用文本编辑器直接编辑该文件,而是使用crontab命令
crond的任务分为两类:系统crond任务、用户crond任务
系统crond任务:主要用于实现系统自身的维护,实现方式为手动编辑/etc/crontab文件
用户crond任务:实现用户指定的任务计划,实现方式为使用crontab命令
系统crond任务的配置文件:/etc/crontab
[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
该文件的每一行定义一个周期性任务
此处的环境变量PATH不同于用户登陆后获得的环境变量PATH,因此建议使用命令时使用绝对路径,或者自定义PATH环境变量
执行结果以邮件的方式发送给用户
用户crond任务的配置文件:/var/spool/cron/USERNAME
该文件的格式与系统crond任务的格式相同;同样的,执行的结果也会以邮件的方式发送给制定此任务的用户
任务的书写格式:* * * * * command to be executed
其中五个*的含义分别为:
每小时的第几分钟
每天的几点
每月的第几天
每年的几月
每周几
时间的表示方法有下面几种形式:
⑴特定值
示例:
⑵离散取值:在时间点上用逗号隔开的多个值
示例:
⑶连续取值:在时间点之间用“-”连接开头和结尾
示例:
注意:
警告:zsh-5.0.2-7.el7.x86_64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEY
准备中… ################################# [100%]
正在升级/安装…
1:zsh-5.0.2-7.el7 ################################# [100%]
警告:zsh-5.0.2-7.el7.x86_64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEY
准备中… ################################# [100%]
[root@localhost Packages]# rpm -q zsh
未安装软件包 zsh
准备中… ################################# [100%]
正在升级/安装…
1:zsh-5.0.2-7.el7 ################################# [100%]
yum-3.4.3-125.el7.centos.noarch
setup-2.8.71-5.el7.noarch
yum-3.4.3-125.el7.centos.noarch
[root@localhost Packages]# rpm -q –changelog yum | less
* 四 3月 05 2015 CentOS Sources <bugs@centos.org> – 3.4.3-125.el7.centos
– CentOS yum config
– use the CentOS bug tracker url
– retain installonly limit of 5
– ensure distrover is always from centos-release
– Make yum require yum-plugin-fastestmirror
* 一 1月 12 2015 Valentina Mukhamedzhanova <vmukhame@redhat.com> – 3.4.3-125
– Roll back the broken lvm patch.
– Related: bug#1047793
查询未安装的程序包文件
[root@localhost Packages]# rpm -q -p zsh-5.0.2-7.el7.x86_64.rpm –changelog | less
警告:zsh-5.0.2-7.el7.x86_64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEY
* 二 1月 28 2014 James Antill <james@fedoraproject.org> – 5.0.2-7
– Remove unneeded build require on tetex.
– Resolves: rhbz#1037828
– Depend on hostname package instead of /bin/hostname.
* 五 1月 24 2014 Daniel Mach <dmach@redhat.com> – 5.0.2-6
– Mass rebuild 2014-01-24
* 五 12月 27 2013 Daniel Mach <dmach@redhat.com> – 5.0.2-5
– Mass rebuild 2013-12-27
/etc
/etc/bash_completion.d
/etc/bash_completion.d/yum
/etc/bash_completion.d/yummain.py
/etc/cron.daily
/etc/cron.daily/0yum-daily.cron
/etc/cron.hourly
警告:zsh-5.0.2-7.el7.x86_64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEY
/bin/zsh
/etc/skel/.zshrc
/etc/zlogin
/etc/zlogout
/etc/zprofile
/etc/zshenv
/etc/zshrc
/usr/lib64/zsh
/usr/lib64/zsh/5.0.2
config(yum) = 3.4.3-125.el7.centos
yum = 3.4.3-125.el7.centos
yum-allow-downgrade = 1.1.20-0.yum
yum-basearchonly = 1.1.9.yum
yum-plugin-allow-downgrade = 1.1.22-0.yum
yum-plugin-basearchonly = 1.1.9.yum
yum-plugin-downloadonly = 3.4.3-44.yum
yum-plugin-protect-packages = 1.1.27-0.yum
yum-plugin-security = 3.4.3-84.yum
yum-presto = 3.4.3-66.yum
yum-protect-packages = 1.1.27-0.yum
yum-skip-broken = 1.1.18.yum
/bin/bash
/usr/bin/python
config(yum) = 3.4.3-125.el7.centos
cpio
diffutils
pygpgme
pyliblzma
python >= 2.4
python(abi) = 2.7
python-iniparse
python-sqlite
python-urlgrabber >= 3.9.0-8
pyxattr
rpm >= 0:4.4.2
rpm-python
rpmlib(CompressedFileNames) <= 3.0.4-1
rpmlib(FileDigests) <= 4.6.0-1
rpmlib(PayloadFilesHavePrefix) <= 4.0-1
yum-metadata-parser >= 1.1.0
yum-plugin-fastestmirror
rpmlib(PayloadIsXz) <= 5.2-1
S.5….T. c /etc/zlogin
警告:zsh-5.0.2-7.el7.x86_64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEY
准备中… ################################# [100%],
准备中… ################################# [100%]
zsh-5.0.2-7.el7.x86_64.rpm: rsa sha1 (md5) pgp md5 确定
[base]
name=CentOS 7.1 base rpm
baseurl=file:///media
gpgcheck=0
enable=1
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
源标识 源名称 状态
base CentOS 7.1 base rpm 9,591
repolist: 9,591
zip.x86_64 3.0-10.el7 @anaconda
zlib.x86_64 1.2.7-13.el7 @anaconda
可安装的软件包
389-ds-base.x86_64 1.3.6.1-16.el7 base
389-ds-base-devel.x86_64 1.3.6.1-16.el7 base
389-ds-base-libs.x86_64 1.3.6.1-16.el7 base
其中@anaconda表示已经安装的软件包,base表示在仓库bash中可以安装的软件包
[root@localhost yum.repos.d]# yum check-update firefox gdm
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
firefox.x86_64 52.2.0-2.el7.centos base
gdm.x86_64 1:3.22.3-11.el7 base
取代的软件包
firefox.x86_64 52.2.0-2.el7.centos base
firefox.x86_64 31.4.0-1.el7.centos @anaconda
gdm.x86_64 1:3.22.3-11.el7 base
gdm-libs.x86_64 1:3.8.4-32.el7 @anaconda
卸载程序包
remove | erase PACKAGE1 PACKAGE2 …
[root@localhost yum.repos.d]# yum provides /etc/yum.conf
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
yum-3.4.3-154.el7.centos.noarch : RPM package installer/updater/manager
源 :base
匹配来源:
文件名 :/etc/yum.conf
yum-3.4.3-125.el7.centos.noarch : RPM package installer/updater/manager
源 :@anaconda
匹配来源:
文件名 :/etc/yum.conf
清理本地yum缓存
[root@localhost yum.repos.d]# yum search zsh
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
=============================================================== N/S matched: zsh ===============================================================
zsh-html.x86_64 : Zsh shell manual in html format
zsh.x86_64 : Powerful interactive shell
名称和简介匹配 only,使用“search all”试试。
查询指定的程序包所依赖的程序包
deplist PACKAGE1 PACKAGE2 …
[root@localhost yum.repos.d]# yum deplist zsh
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
软件包:zsh.x86_64 5.0.2-28.el7
依赖:/bin/sh
provider: bash.x86_64 4.2.46-28.el7
依赖:/sbin/install-info
provider: info.x86_64 5.1-4.el7
依赖:coreutils
provider: coreutils.x86_64 8.22-18.el7
依赖:grep
provider: grep.x86_64 2.20-3.el7
依赖:libc.so.6(GLIBC_2.15)(64bit)
provider: glibc.x86_64 2.17-196.el7
依赖:libdl.so.2()(64bit)
provider: glibc.x86_64 2.17-196.el7
依赖:libdl.so.2(GLIBC_2.2.5)(64bit)
provider: glibc.x86_64 2.17-196.el7
依赖:libm.so.6()(64bit)
provider: glibc.x86_64 2.17-196.el7
依赖:libm.so.6(GLIBC_2.2.5)(64bit)
provider: glibc.x86_64 2.17-196.el7
依赖:libncursesw.so.5()(64bit)
provider: ncurses-libs.x86_64 5.9-13.20130511.el7
依赖:librt.so.1()(64bit)
provider: glibc.x86_64 2.17-196.el7
依赖:librt.so.1(GLIBC_2.2.5)(64bit)
provider: glibc.x86_64 2.17-196.el7
依赖:libtinfo.so.5()(64bit)
provider: ncurses-libs.x86_64 5.9-13.20130511.el7
依赖:rtld(GNU_HASH)
provider: glibc.x86_64 2.17-196.el7
provider: glibc.i686 2.17-196.el7
查看yum事务历史
history [info|list|packages-list|packages-info|summary|addon-info|redo|undo|rollback|new|sync|stats]
[root@localhost yum.repos.d]# yum history list
已加载插件:fastestmirror, langpacks
ID | 登录用户 | 日期和时间 | 操作 | 变更数
——————————————————————————-
2 | root <root> | 2018-01-14 15:26 | Install | 1
1 | 系统 <空> | 2017-12-15 06:20 | Install | 1217
history list
查看详细信息
[root@localhost yum.repos.d]# yum history info
已加载插件:fastestmirror, langpacks
事务 ID: 2
起始时间 : Sun Jan 14 15:26:42 2018
启动 RPM 数据库 : 1217:32b8cea72dada528cae6c6f2ec938445bb6ca221
结束时间 : 15:26:45 2018 (3 秒)
结束 RPM 数据库 : 1218:68bf5357543eaaed46d8f9551eca0cd3ca80ffcb
用户 : root <root>
返回码 : 成功
命令行 : install zsh
事务完成属主:
已安装 rpm-4.11.1-25.el7.x86_64 @anaconda
已安装 yum-3.4.3-125.el7.centos.noarch @anaconda
已安装 yum-plugin-fastestmirror-1.1.31-29.el7.noarch @anaconda
已变更的包:
安装 zsh-5.0.2-7.el7.x86_64 @base
history info
已加载插件:fastestmirror, langpacks
没有安装组信息文件
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
Available environment groups:
最小安装
基础设施服务器
计算节点
文件及打印服务器
基本网页服务器
虚拟化主机
带 GUI 的服务器
GNOME 桌面
KDE Plasma Workspaces
开发及生成工作站
可用组:
传统 UNIX 兼容性
兼容性程序库
图形管理工具
安全性工具
开发工具
控制台互联网工具
智能卡支持
科学记数法支持
系统管理
系统管理工具
完成
[base]
name=CentOS 7.1 base rpm
baseurl=file:///media
gpgcheck=0
enable=1
[root@localhost yum.repos.d]# sed “/^#/p” /etc/fstab
#
#
# /etc/fstab
# /etc/fstab
# Created by anaconda on Thu Dec 14 22:20:07 2017
# Created by anaconda on Thu Dec 14 22:20:07 2017
#
#
# Accessible filesystems, by reference, are maintained under ‘/dev/disk’
# Accessible filesystems, by reference, are maintained under ‘/dev/disk’
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
#
/dev/mapper/rootvg-root / xfs defaults 0 0
UUID=a6d99a7e-4f75-4eef-acb7-930242a1a150 /boot xfs defaults 0 0
/dev/mapper/rootvg-home /home xfs defaults 0 0
/dev/mapper/rootvg-swap swap swap defaults 0 0
所以编辑命令p使用时要结合-n选项使用
[root@localhost yum.repos.d]# sed -n “/^#/p” /etc/fstab
#
# /etc/fstab
# Created by anaconda on Thu Dec 14 22:20:07 2017
#
# Accessible filesystems, by reference, are maintained under ‘/dev/disk’
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
⑷显示/etc/fstab时,在UUID开头的行后面追加新的一行
[root@localhost yum.repos.d]# sed “/^UUID/a \new line” /etc/fstab
#
# /etc/fstab
# Created by anaconda on Thu Dec 14 22:20:07 2017
#
# Accessible filesystems, by reference, are maintained under ‘/dev/disk’
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/rootvg-root / xfs defaults 0 0
UUID=a6d99a7e-4f75-4eef-acb7-930242a1a150 /boot xfs defaults 0 0
new line
/dev/mapper/rootvg-home /home xfs defaults 0 0
/dev/mapper/rootvg-swap swap swap defaults 0 0
⑸显示/etc/fstab时,在UUID开头的行前面插入新的一行
[root@localhost yum.repos.d]# sed “/^UUID/i \new line” /etc/fstab
#
# /etc/fstab
# Created by anaconda on Thu Dec 14 22:20:07 2017
#
# Accessible filesystems, by reference, are maintained under ‘/dev/disk’
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/rootvg-root / xfs defaults 0 0
new line
UUID=a6d99a7e-4f75-4eef-acb7-930242a1a150 /boot xfs defaults 0 0
/dev/mapper/rootvg-home /home xfs defaults 0 0
/dev/mapper/rootvg-swap swap swap defaults 0 0
⑹显示/etc/fstab时,将UUID开头行替换为“other line”
[root@localhost yum.repos.d]# sed “/^UUID/c \other line” /etc/fstab
#
# /etc/fstab
# Created by anaconda on Thu Dec 14 22:20:07 2017
#
# Accessible filesystems, by reference, are maintained under ‘/dev/disk’
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/rootvg-root / xfs defaults 0 0
other line
/dev/mapper/rootvg-home /home xfs defaults 0 0
/dev/mapper/rootvg-swap swap swap defaults 0 0
⑺将/etc/fstab文件中以#开头的行保存至/tmp/testfile1中
[root@localhost yum.repos.d]# sed “/^#/w /tmp/testfile1” /etc/fstab
#
# /etc/fstab
# Created by anaconda on Thu Dec 14 22:20:07 2017
#
# Accessible filesystems, by reference, are maintained under ‘/dev/disk’
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/rootvg-root / xfs defaults 0 0
UUID=a6d99a7e-4f75-4eef-acb7-930242a1a150 /boot xfs defaults 0 0
/dev/mapper/rootvg-home /home xfs defaults 0 0
/dev/mapper/rootvg-swap swap swap defaults 0 0
[root@localhost yum.repos.d]# cat /tmp/testfile1
#
# /etc/fstab
# Created by anaconda on Thu Dec 14 22:20:07 2017
#
# Accessible filesystems, by reference, are maintained under ‘/dev/disk’
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/tmp/testfile1不必事先存在,因为sed命令默认会将没有被模式空间中的模式匹配到的行输出到标准输出,所以上面的例子中会将原文输出,如果不想输出,加上-n选项
⑻将/etc/issue读取到/etc/fstab中UUID开头的行后面
[root@localhost yum.repos.d]# sed “/^UUID/r /etc/issue” /etc/fstab
#
# /etc/fstab
# Created by anaconda on Thu Dec 14 22:20:07 2017
#
# Accessible filesystems, by reference, are maintained under ‘/dev/disk’
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/rootvg-root / xfs defaults 0 0
UUID=a6d99a7e-4f75-4eef-acb7-930242a1a150 /boot xfs defaults 0 0
\S
Kernel \r on an \m
/dev/mapper/rootvg-home /home xfs defaults 0 0
/dev/mapper/rootvg-swap swap swap defaults 0 0
⑼显示/etc/fstab时,在#开头的行前添加行号
[root@localhost yum.repos.d]# sed “/^#/=” /etc/fstab
2
#
3
# /etc/fstab
4
# Created by anaconda on Thu Dec 14 22:20:07 2017
5
#
6
# Accessible filesystems, by reference, are maintained under ‘/dev/disk’
7
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
8
#
/dev/mapper/rootvg-root / xfs defaults 0 0
UUID=a6d99a7e-4f75-4eef-acb7-930242a1a150 /boot xfs defaults 0 0
/dev/mapper/rootvg-home /home xfs defaults 0 0
/dev/mapper/rootvg-swap swap swap defaults 0 0
⑽显示/etc/fstab时,删除不是#开头的行
如果script使用双引号,地址定界 ! 编辑命令之间要加空格
[root@localhost yum.repos.d]# sed “/^#/ ! d” /etc/fstab
#
# /etc/fstab
# Created by anaconda on Thu Dec 14 22:20:07 2017
#
# Accessible filesystems, by reference, are maintained under ‘/dev/disk’
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
如果使用单引号,地址定界 ! 编辑命令之间不加空格
[root@localhost yum.repos.d]# sed ‘/^#/!d’ /etc/fstab
#
# /etc/fstab
# Created by anaconda on Thu Dec 14 22:20:07 2017
#
# Accessible filesystems, by reference, are maintained under ‘/dev/disk’
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
本文来自投稿,不代表Linux运维部落立场,如若转载,请注明出处:http://www.178linux.com/91067