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.www58058.com/91067