Linux任务计划at

一Linux任务计划介绍

Linux任务计划、周期性任务执行
at:未来的某时间点执行一次任务
batch:系统自行选择空闲时间去执行此处指定的任务
cron:周期性运行某任务

二at计划任务

执行方式:
交互式,输入重定向,at –f 文件
依赖与atd服务,需要启动才能实现at任务,at队列存放在/var/spool/at目录中

(一)安装at包

最小化安装默认是没有安装的,光盘自带的包

[root@centos72 ~]# yum  install  at  -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package at.x86_64 0:3.1.13-23.el7 will be installed
--> Finished Dependency Resolution Dependencies Resolved ========================================================================================================
Package Arch Version Repository Size
========================================================================================================
Installing:
at x86_64 3.1.13-23.el7 base 51 k Transaction Summary
========================================================================================================
Install 1 Package Total download size: 51 k
Installed size: 95 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : at-3.1.13-23.el7.x86_64 1/1
Verifying : at-3.1.13-23.el7.x86_64 1/1 Installed:
at.x86_64 0:3.1.13-23.el7 Complete!

查看包的介绍

[root@centos72 ~]# rpm  -q at
at-3.1.13-23.el7.x86_64
[root@centos72 ~]# rpm -qi at
Name : at
Version : 3.1.13
Release : 23.el7
Architecture: x86_64
Install Date: Mon 29 Jul 2019 04:42:51 PM CST
Group : System Environment/Daemons
Size : 97561
License : GPLv3+ and GPLv2+ and ISC and MIT and Public Domain
Signature : RSA/SHA256, Wed 25 Apr 2018 06:52:49 PM CST, Key ID 24c6a8a7f4a80eb5
Source RPM : at-3.1.13-23.el7.src.rpm
Build Date : Wed 11 Apr 2018 08:13:35 AM CST
Build Host : x86-01.bsys.centos.org
Relocations : (not relocatable)
Packager : CentOS BuildSystem <http://bugs.centos.org>
Vendor : CentOS
URL : http://ftp.debian.org/debian/pool/main/a/at
Summary : Job spooling tools
Description :
At and batch read commands from standard input or from a specified
file. At allows you to specify that a command will be run at a
particular time. Batch will execute commands when the system load
levels drop to a particular level. Both commands use user's shell. You should install the at package if you need a utility for
time-oriented job control. Note: If it is a recurring job that will
need to be repeated at the same time every day/week, etc. you should
use crontab instead.

6版本

[root@centos65 ~]#  rpm -q  at
at-3.1.10-48.el6.x86_64
[root@centos65 ~]# rpm -qi at
Name : at Relocations: (not relocatable)
Version : 3.1.10 Vendor: CentOS
Release : 48.el6 Build Date: Fri 20 Feb 2015 12:23:33 AM CST
Install Date: Wed 23 Jan 2019 05:30:47 PM CST Build Host: c6b8.bsys.dev.centos.org
Group : System Environment/Daemons Source RPM: at-3.1.10-48.el6.src.rpm
Size : 94221 License: GPLv2+
Signature : RSA/SHA1, Fri 20 Feb 2015 12:34:52 AM CST, Key ID 0946fca2c105b9de
Packager : CentOS BuildSystem <http://bugs.centos.org>
URL : http://ftp.debian.org/debian/pool/main/a/at
Summary : Job spooling tools
Description :
At and batch read commands from standard input or from a specified
file. At allows you to specify that a command will be run at a
particular time. Batch will execute commands when the system load
levels drop to a particular level. Both commands use user's shell. You should install the at package if you need a utility for
time-oriented job control. Note: If it is a recurring job that will
need to be repeated at the same time every day/week, etc. you should
use crontab instead.

(二)at包的组成

[root@centos72 ~]# rpm -ql  at
/etc/at.deny
/etc/pam.d/atd
/etc/sysconfig/atd
/usr/bin/at
/usr/bin/atq
/usr/bin/atrm
/usr/bin/batch
/usr/lib/systemd/system/atd.service
/usr/sbin/atd
/usr/sbin/atrun
/usr/share/doc/at-3.1.13
/usr/share/doc/at-3.1.13/ChangeLog
/usr/share/doc/at-3.1.13/Copyright
/usr/share/doc/at-3.1.13/Problems
/usr/share/doc/at-3.1.13/README
/usr/share/doc/at-3.1.13/timespec
/usr/share/man/man1/at.1.gz
/usr/share/man/man1/atq.1.gz
/usr/share/man/man1/atrm.1.gz
/usr/share/man/man1/batch.1.gz
/usr/share/man/man5/at.allow.5.gz
/usr/share/man/man5/at.deny.5.gz
/usr/share/man/man8/atd.8.gz
/usr/share/man/man8/atrun.8.gz
/var/spool/at
/var/spool/at/.SEQ
/var/spool/at/spool

服务存放位置/etc/rc.d/init.d/atd

运行的程序/usr/sbin/atd

[root@centos65 ~]#  rpm -ql  at
/etc/at.deny
/etc/pam.d/atd
/etc/rc.d/init.d/atd
/etc/sysconfig/atd
/usr/bin/at
/usr/bin/atq
/usr/bin/atrm
/usr/bin/batch
/usr/lib64/pm-utils/sleep.d/56atd
/usr/sbin/atd
/usr/sbin/atrun
/usr/share/doc/at-3.1.10
/usr/share/doc/at-3.1.10/ChangeLog
/usr/share/doc/at-3.1.10/Copyright
/usr/share/doc/at-3.1.10/Problems
/usr/share/doc/at-3.1.10/README
/usr/share/doc/at-3.1.10/timespec
/usr/share/man/man1/at.1.gz
/usr/share/man/man1/atq.1.gz
/usr/share/man/man1/atrm.1.gz
/usr/share/man/man1/batch.1.gz
/usr/share/man/man5/at.allow.5.gz
/usr/share/man/man8/atd.8.gz
/usr/share/man/man8/atrun.8.gz
/var/spool/at
/var/spool/at/.SEQ
/var/spool/at/spool

查看开机是否自启

因为是比较基础的服务,开机一般自启

[root@centos72 ~]# systemctl is-enabled  atd
enabled
[root@centos72 ~]# systemctl is-enabled atd.service
enabled
[root@centos65 ~]# chkconfig  --list  atd
atd 0:off 1:off 2:off 3:on 4:on 5:on 6:off
[root@centos65 ~]# runlevel
N

服务调用了程序/usr/sbin/atd

[root@centos72 ~]# systemctl status  atd.service
● atd.service - Job spooling tools
Loaded: loaded (/usr/lib/systemd/system/atd.service; enabled; vendor preset: enabled)
Active: inactive (dead)
[root@centos72 ~]# systemctl start atd.service
[root@centos72 ~]# systemctl status atd.service
● atd.service - Job spooling tools
Loaded: loaded (/usr/lib/systemd/system/atd.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2019-05-21 09:28:49 CST; 1s ago
Main PID: 2710 (atd)
CGroup: /system.slice/atd.service
└─2710 /usr/sbin/atd -f May 21 09:28:49 centos72.huawei.com systemd[1]: Started Job spooling tools.
May 21 09:28:49 centos72.huawei.com systemd[1]: Starting Job spooling tools...

进程编号是2710

[root@centos72 ~]# ps aux  | grep  2710
root 2710 0.0 0.0 25904 936 ? Ss 09:28 0:00 /usr/sbin/atd -f
root 2719 0.0 0.0 112704 972 pts/0 S+ 09:30 0:00 grep --color=auto

(三)常用选项

-V 显示版本信息:
-l: 列出指定队列中等待运行的作业;相当于atq
-d: 删除指定的作业;相当于atrm
-c: 查看具体作业任务
-f /path/from/somefile:从指定的文件中读取任务
-m:当任务被完成之后,将给用户发送邮件,即使没有标准输出
注意:作业执行命令的结果中的标准输出和错误以邮件通知给相关用户

(四)at时间格式

HH:MM 02:00
在今日的 HH:MM 进行,若该时刻已过,则明天此时执行任务
HH:MM YYYY-MM-DD 02:00 2018-01-08
规定在某年某月的某一天的特殊时刻进行该项任务
HH:MM[am|pm] [Month] [Date]
04pm March 17
17:20 tomorrow
HH:MM[am|pm] + number [minutes|hours|days|weeks]
在某个时间点再加几个时间后才进行该项任务
now + 5 minutes
02pm + 3 days

三创建at计划任务广播时间

(一)前期准备

1时间同步,虚拟机的时间和宿主机的时间、网络时间要一致

2关闭防火墙

3关闭selinux

(二)创建at计划任务

按ctrl+d保存

[root@centos72 ~]# at  10:00
at> wall 10:00 clock
at> <EOT>
job 1 at Tue May 21 10:00:00 2019
[root@centos72 ~]# at -l
1 Tue May 21 10:00:00 2019 = root
[root@centos72 ~]#
Broadcast message from root@centos72.huawei.com (Tue May 21 10:00:01 2019): 10:00 clock

在创建计划任务完成之后就会写到文件里面了

[root@centos72 ~]# at  10:10
at> wall 10:10 clock
at> <EOT>
job 2 at Tue May 21 10:10:00 2019
[root@centos72 ~]# at -l
2 Tue May 21 10:10:00 2019 a root
[root@centos72 ~]# ls /var/spool/at -l
total 4
-rwx------. 1 root root 2806 May 21 10:04 a00002018c52a2
drwx------. 2 root root 6 May 21 10:00 spool

执行完了任务就会把相应的文件删除了

[root@centos72 ~]# cat /var/spool/at/a00002018c52a2
#!/bin/sh
# atrun uid=0 gid=0
# mail root 0
umask 22
XDG_SESSION_ID=79; export XDG_SESSION_ID
HOSTNAME=centos72.huawei.com; export HOSTNAME
SELINUX_ROLE_REQUESTED=; export SELINUX_ROLE_REQUESTED
SHELL=/bin/bash; export SHELL
HISTSIZE=1000; export HISTSIZE
SSH_CLIENT=192.168.137.1\ 49197\ 22; export SSH_CLIENT
SELINUX_USE_CURRENT_RANGE=; export SELINUX_USE_CURRENT_RANGE
SSH_TTY=/dev/pts/0; export SSH_TTY
USER=root; export USER
LS_COLORS=rs=0:di=01\;34:ln=01\;36:mh=00:pi=40\;33:so=01\;35:do=01\;35:bd=40\;33\;01:cd=40\;33\;01:or=40\;31\;01:mi=01\;05\;37\;41:su=37\;41:sg=30\;43:ca=30\;41:tw=30\;42:ow=34\;42:st=37\;44:ex=01\;32:\*.tar=01\;31:\*.tgz=01\;31:\*.arc=01\;31:\*.arj=01\;31:\*.taz=01\;31:\*.lha=01\;31:\*.lz4=01\;31:\*.lzh=01\;31:\*.lzma=01\;31:\*.tlz=01\;31:\*.txz=01\;31:\*.tzo=01\;31:\*.t7z=01\;31:\*.zip=01\;31:\*.z=01\;31:\*.Z=01\;31:\*.dz=01\;31:\*.gz=01\;31:\*.lrz=01\;31:\*.lz=01\;31:\*.lzo=01\;31:\*.xz=01\;31:\*.bz2=01\;31:\*.bz=01\;31:\*.tbz=01\;31:\*.tbz2=01\;31:\*.tz=01\;31:\*.deb=01\;31:\*.rpm=01\;31:\*.jar=01\;31:\*.war=01\;31:\*.ear=01\;31:\*.sar=01\;31:\*.rar=01\;31:\*.alz=01\;31:\*.ace=01\;31:\*.zoo=01\;31:\*.cpio=01\;31:\*.7z=01\;31:\*.rz=01\;31:\*.cab=01\;31:\*.jpg=01\;35:\*.jpeg=01\;35:\*.gif=01\;35:\*.bmp=01\;35:\*.pbm=01\;35:\*.pgm=01\;35:\*.ppm=01\;35:\*.tga=01\;35:\*.xbm=01\;35:\*.xpm=01\;35:\*.tif=01\;35:\*.tiff=01\;35:\*.png=01\;35:\*.svg=01\;35:\*.svgz=01\;35:\*.mng=01\;35:\*.pcx=01\;35:\*.mov=01\;35:\*.mpg=01\;35:\*.mpeg=01\;35:\*.m2v=01\;35:\*.mkv=01\;35:\*.webm=01\;35:\*.ogm=01\;35:\*.mp4=01\;35:\*.m4v=01\;35:\*.mp4v=01\;35:\*.vob=01\;35:\*.qt=01\;35:\*.nuv=01\;35:\*.wmv=01\;35:\*.asf=01\;35:\*.rm=01\;35:\*.rmvb=01\;35:\*.flc=01\;35:\*.avi=01\;35:\*.fli=01\;35:\*.flv=01\;35:\*.gl=01\;35:\*.dl=01\;35:\*.xcf=01\;35:\*.xwd=01\;35:\*.yuv=01\;35:\*.cgm=01\;35:\*.emf=01\;35:\*.axv=01\;35:\*.anx=01\;35:\*.ogv=01\;35:\*.ogx=01\;35:\*.aac=01\;36:\*.au=01\;36:\*.flac=01\;36:\*.mid=01\;36:\*.midi=01\;36:\*.mka=01\;36:\*.mp3=01\;36:\*.mpc=01\;36:\*.ogg=01\;36:\*.ra=01\;36:\*.wav=01\;36:\*.axa=01\;36:\*.oga=01\;36:\*.spx=01\;36:\*.xspf=01\;36:; export LS_COLORS
MAIL=/var/spool/mail/root; export MAIL
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin; export PATH
PWD=/root; export PWD
LANG=en_US.UTF-8; export LANG
SELINUX_LEVEL_REQUESTED=; export SELINUX_LEVEL_REQUESTED
HISTCONTROL=ignoredups; export HISTCONTROL
SHLVL=1; export SHLVL
HOME=/root; export HOME
LOGNAME=root; export LOGNAME
SSH_CONNECTION=192.168.137.1\ 49197\ 192.168.137.72\ 22; export SSH_CONNECTION
LESSOPEN=\|\|/usr/bin/lesspipe.sh\ %s; export LESSOPEN
XDG_RUNTIME_DIR=/run/user/0; export XDG_RUNTIME_DIR
cd /root || {
echo 'Execution directory inaccessible' >&2
exit 1
}
${SHELL:-/bin/sh} << 'marcinDELIMITER0a4474a2'
wall 10:10 clock marcinDELIMITER0a4474a2

注意在计划任务里面,所有的标准输出不会在屏幕上显示,而是放到了邮件里面

如果是广播就会在所有的终端都显示

[root@centos72 ~]#
Broadcast message from root@centos72.huawei.com (Tue May 21 10:10:00 2019): 10:10 clock

四at选项示例

(一)-l: 列出指定队列中等待运行的作业;相当于atq

定义计划任务,并且是打印标准输出的

[root@centos72 ~]# at  10:15
at> hostname
at> ls
at> pwd
at> who
at> <EOT>
job 3 at Tue May 21 10:15:00

安装邮件服务

[root@centos72 ~]# yum -y install mailx
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
file:///mnt/repodata/repomd.xml: [Errno 14] curl#37 - "Couldn't open file /mnt/repodata/repomd.xml"
Trying other mirror.
Resolving Dependencies
--> Running transaction check
---> Package mailx.x86_64 0:12.5-19.el7 will be installed
--> Finished Dependency Resolution Dependencies Resolved ========================================================================================================
Package Arch Version Repository Size
========================================================================================================
Installing:
mailx x86_64 12.5-19.el7 ali-centos 245 k Transaction Summary
========================================================================================================
Install 1 Package Total download size: 245 k
Installed size: 466 k
Downloading packages:
mailx-12.5-19.el7.x86_64.rpm | 245 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : mailx-12.5-19.el7.x86_64 1/1
Verifying : mailx-12.5-19.el7.x86_64 1/1 Installed:
mailx.x86_64 0:12.5-19.el7 Complete!

在邮件里面显示了计划任务的内容

[root@centos72 ~]# mail
No mail for root
[root@centos72 ~]# mail
Heirloom Mail version 12.5 7/5/10. Type ? for help.
"/var/spool/mail/root": 1 message 1 new
>N 1 root Tue May 21 10:15 35/727 "Output from your job 3"
& 1
Message 1:
From root@centos72.huawei.com Tue May 21 10:15:00 2019
Return-Path: <root@centos72.huawei.com>
X-Original-To: root
Delivered-To: root@centos72.huawei.com
Subject: Output from your job 3
To: root@centos72.huawei.com
Date: Tue, 21 May 2019 10:15:00 +0800 (CST)
From: root@centos72.huawei.com (root)
Status: R centos72.huawei.com
1.txt
2.txt
3.txt
4.txt
5.txt
aaa
aa.txt
access_log
anaconda-ks.cfg
aux.txt
f1
f2
f3
f4
f5
grep
nohup.out
x.txt
/root
root pts/0 2019-05-21 08:42 (192.168.137.1)
root pts/1 2019-05-21 09:59 (192.168.137.1) &
At EOF
&
At EOF
&

(二)-c: 查看具体作业任务

如果脚本是在计划任务里面执行最好把标准输出关闭

删除计划任务

[root@centos72 ~]# at  10:30
at> pwd<EOT>
job 4 at Tue May 21 10:30:00 2019
[root@centos72 ~]# at-l
-bash: at-l: command not found
[root@centos72 ~]# at -l
4 Tue May 21 10:30:00 2019 a root
[root@centos72 ~]# at -c 4
#!/bin/sh
# atrun uid=0 gid=0
# mail root 0
umask 22
XDG_SESSION_ID=79; export XDG_SESSION_ID
HOSTNAME=centos72.huawei.com; export HOSTNAME
SELINUX_ROLE_REQUESTED=; export SELINUX_ROLE_REQUESTED
SHELL=/bin/bash; export SHELL
HISTSIZE=1000; export HISTSIZE
SSH_CLIENT=192.168.137.1\ 49197\ 22; export SSH_CLIENT
SELINUX_USE_CURRENT_RANGE=; export SELINUX_USE_CURRENT_RANGE
SSH_TTY=/dev/pts/0; export SSH_TTY
USER=root; export USER
LS_COLORS=rs=0:di=01\;34:ln=01\;36:mh=00:pi=40\;33:so=01\;35:do=01\;35:bd=40\;33\;01:cd=40\;33\;01:or=40\;31\;01:mi=01\;05\;37\;41:su=37\;41:sg=30\;43:ca=30\;41:tw=30\;42:ow=34\;42:st=37\;44:ex=01\;32:\*.tar=01\;31:\*.tgz=01\;31:\*.arc=01\;31:\*.arj=01\;31:\*.taz=01\;31:\*.lha=01\;31:\*.lz4=01\;31:\*.lzh=01\;31:\*.lzma=01\;31:\*.tlz=01\;31:\*.txz=01\;31:\*.tzo=01\;31:\*.t7z=01\;31:\*.zip=01\;31:\*.z=01\;31:\*.Z=01\;31:\*.dz=01\;31:\*.gz=01\;31:\*.lrz=01\;31:\*.lz=01\;31:\*.lzo=01\;31:\*.xz=01\;31:\*.bz2=01\;31:\*.bz=01\;31:\*.tbz=01\;31:\*.tbz2=01\;31:\*.tz=01\;31:\*.deb=01\;31:\*.rpm=01\;31:\*.jar=01\;31:\*.war=01\;31:\*.ear=01\;31:\*.sar=01\;31:\*.rar=01\;31:\*.alz=01\;31:\*.ace=01\;31:\*.zoo=01\;31:\*.cpio=01\;31:\*.7z=01\;31:\*.rz=01\;31:\*.cab=01\;31:\*.jpg=01\;35:\*.jpeg=01\;35:\*.gif=01\;35:\*.bmp=01\;35:\*.pbm=01\;35:\*.pgm=01\;35:\*.ppm=01\;35:\*.tga=01\;35:\*.xbm=01\;35:\*.xpm=01\;35:\*.tif=01\;35:\*.tiff=01\;35:\*.png=01\;35:\*.svg=01\;35:\*.svgz=01\;35:\*.mng=01\;35:\*.pcx=01\;35:\*.mov=01\;35:\*.mpg=01\;35:\*.mpeg=01\;35:\*.m2v=01\;35:\*.mkv=01\;35:\*.webm=01\;35:\*.ogm=01\;35:\*.mp4=01\;35:\*.m4v=01\;35:\*.mp4v=01\;35:\*.vob=01\;35:\*.qt=01\;35:\*.nuv=01\;35:\*.wmv=01\;35:\*.asf=01\;35:\*.rm=01\;35:\*.rmvb=01\;35:\*.flc=01\;35:\*.avi=01\;35:\*.fli=01\;35:\*.flv=01\;35:\*.gl=01\;35:\*.dl=01\;35:\*.xcf=01\;35:\*.xwd=01\;35:\*.yuv=01\;35:\*.cgm=01\;35:\*.emf=01\;35:\*.axv=01\;35:\*.anx=01\;35:\*.ogv=01\;35:\*.ogx=01\;35:\*.aac=01\;36:\*.au=01\;36:\*.flac=01\;36:\*.mid=01\;36:\*.midi=01\;36:\*.mka=01\;36:\*.mp3=01\;36:\*.mpc=01\;36:\*.ogg=01\;36:\*.ra=01\;36:\*.wav=01\;36:\*.axa=01\;36:\*.oga=01\;36:\*.spx=01\;36:\*.xspf=01\;36:; export LS_COLORS
MAIL=/var/spool/mail/root; export MAIL
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin; export PATH
PWD=/root; export PWD
LANG=en_US.UTF-8; export LANG
SELINUX_LEVEL_REQUESTED=; export SELINUX_LEVEL_REQUESTED
HISTCONTROL=ignoredups; export HISTCONTROL
SHLVL=1; export SHLVL
HOME=/root; export HOME
LOGNAME=root; export LOGNAME
SSH_CONNECTION=192.168.137.1\ 49197\ 192.168.137.72\ 22; export SSH_CONNECTION
LESSOPEN=\|\|/usr/bin/lesspipe.sh\ %s; export LESSOPEN
XDG_RUNTIME_DIR=/run/user/0; export XDG_RUNTIME_DIR
cd /root || {
echo 'Execution directory inaccessible' >&2
exit 1
}
${SHELL:-/bin/sh} << 'marcinDELIMITER615fc239'
pwd
marcinDELIMITER615fc239

(三)-d: 删除指定的作业;相当于atrm

文件也被删除了

[root@centos72 ~]# atrm   4
[root@centos72 ~]# at -l
[root@centos72 ~]# at -c 4
Cannot find jobid 4
[root@centos72 ~]# ls /var/spool/at
spool
[root@centos72 ~]# ls /var/spool/at -l
total 0
drwx------. 2 root root 6 May 21 10:15 spool
[root@centos72 ~]#

(四)-V 显示版本信息

显示版本信息,小版本不同,没有多大区别

[root@centos72 ~]# at -V
at version 3.1.13
[root@centos65 ~]# at -V
at version 3.1.

使用重定向创建脚本

[root@centos65 ~]# at  11:00  <<EOF
> wall noon
> EOF
job 2 at 2019-05-21 11:00
[root@centos65 ~]# at -l
2 2019-05-21 11:00 a root
[root@centos65 ~]# at -c 4
Cannot find jobid 4
[root@centos65 ~]# at -c 2
#!/bin/sh
# atrun uid=0 gid=0
# mail root 0
umask 22
HOSTNAME=centos65.jd.com; export HOSTNAME
SELINUX_ROLE_REQUESTED=; export SELINUX_ROLE_REQUESTED
SHELL=/bin/bash; export SHELL
HISTSIZE=1000; export HISTSIZE
SSH_CLIENT=192.168.137.1\ 56213\ 22; export SSH_CLIENT
SELINUX_USE_CURRENT_RANGE=; export SELINUX_USE_CURRENT_RANGE
SSH_TTY=/dev/pts/1; export SSH_TTY
USER=root; export USER
LS_COLORS=rs=0:di=01\;34:ln=01\;36:mh=00:pi=40\;33:so=01\;35:do=01\;35:bd=40\;33\;01:cd=40\;33\;01:or=40\;31\;01:mi=01\;05\;37\;41:su=37\;41:sg=30\;43:ca=30\;41:tw=30\;42:ow=34\;42:st=37\;44:ex=01\;32:\*.tar=01\;31:\*.tgz=01\;31:\*.arj=01\;31:\*.taz=01\;31:\*.lzh=01\;31:\*.lzma=01\;31:\*.tlz=01\;31:\*.txz=01\;31:\*.zip=01\;31:\*.z=01\;31:\*.Z=01\;31:\*.dz=01\;31:\*.gz=01\;31:\*.lz=01\;31:\*.xz=01\;31:\*.bz2=01\;31:\*.tbz=01\;31:\*.tbz2=01\;31:\*.bz=01\;31:\*.tz=01\;31:\*.deb=01\;31:\*.rpm=01\;31:\*.jar=01\;31:\*.rar=01\;31:\*.ace=01\;31:\*.zoo=01\;31:\*.cpio=01\;31:\*.7z=01\;31:\*.rz=01\;31:\*.jpg=01\;35:\*.jpeg=01\;35:\*.gif=01\;35:\*.bmp=01\;35:\*.pbm=01\;35:\*.pgm=01\;35:\*.ppm=01\;35:\*.tga=01\;35:\*.xbm=01\;35:\*.xpm=01\;35:\*.tif=01\;35:\*.tiff=01\;35:\*.png=01\;35:\*.svg=01\;35:\*.svgz=01\;35:\*.mng=01\;35:\*.pcx=01\;35:\*.mov=01\;35:\*.mpg=01\;35:\*.mpeg=01\;35:\*.m2v=01\;35:\*.mkv=01\;35:\*.ogm=01\;35:\*.mp4=01\;35:\*.m4v=01\;35:\*.mp4v=01\;35:\*.vob=01\;35:\*.qt=01\;35:\*.nuv=01\;35:\*.wmv=01\;35:\*.asf=01\;35:\*.rm=01\;35:\*.rmvb=01\;35:\*.flc=01\;35:\*.avi=01\;35:\*.fli=01\;35:\*.flv=01\;35:\*.gl=01\;35:\*.dl=01\;35:\*.xcf=01\;35:\*.xwd=01\;35:\*.yuv=01\;35:\*.cgm=01\;35:\*.emf=01\;35:\*.axv=01\;35:\*.anx=01\;35:\*.ogv=01\;35:\*.ogx=01\;35:\*.aac=01\;36:\*.au=01\;36:\*.flac=01\;36:\*.mid=01\;36:\*.midi=01\;36:\*.mka=01\;36:\*.mp3=01\;36:\*.mpc=01\;36:\*.ogg=01\;36:\*.ra=01\;36:\*.wav=01\;36:\*.axa=01\;36:\*.oga=01\;36:\*.spx=01\;36:\*.xspf=01\;36:; export LS_COLORS
MAIL=/var/spool/mail/root; export MAIL
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin; export PATH
PWD=/root; export PWD
LANG=en_US.UTF-8; export LANG
SELINUX_LEVEL_REQUESTED=; export SELINUX_LEVEL_REQUESTED
HISTCONTROL=ignoredups; export HISTCONTROL
SHLVL=1; export SHLVL
HOME=/root; export HOME
LOGNAME=root; export LOGNAME
CVS_RSH=ssh; export CVS_RSH
SSH_CONNECTION=192.168.137.1\ 56213\ 192.168.137.65\ 22; export SSH_CONNECTION
LESSOPEN=\|\|/usr/bin/lesspipe.sh\ %s; export LESSOPEN
G_BROKEN_FILENAMES=1; export G_BROKEN_FILENAMES
cd /root || {
echo 'Execution directory inaccessible' >&2
exit 1
}
${SHELL:-/bin/sh} << 'marcinDELIMITER6e38cb04'
wall noon marcinDELIMITER6e38cb04

at是读取键盘输入,echo是打印标准输出

管道的作用就是把前面的标准输出作为后面的标准输入

[root@centos65 ~]# echo   "wall  at jobs"  |  at  11:00
job 3 at 2019-05-21 11:00
[root@centos65 ~]# at -l
2 2019-05-21 11:00 a root
3 2019-05-21 11:00 a root

多条命令放到计划任务里面

添加换行即可

[root@centos65 ~]# echo  -e  "wall at jobs1\nwall^Ct jobs2\nwall at jobs3"  | at  11:00
[root@centos65 ~]# at -l
4 2019-05-21 11:00 a root
2 2019-05-21 11:00 a root
5 2019-05-21 11:00 a root
3 2019-05-21 11:00 a root
[root@centos65 ~]# at -c 4
#!/bin/sh
# atrun uid=0 gid=0
# mail root 0
umask 22
HOSTNAME=centos65.jd.com; export HOSTNAME
SELINUX_ROLE_REQUESTED=; export SELINUX_ROLE_REQUESTED
SHELL=/bin/bash; export SHELL
HISTSIZE=1000; export HISTSIZE
SSH_CLIENT=192.168.137.1\ 56213\ 22; export SSH_CLIENT
SELINUX_USE_CURRENT_RANGE=; export SELINUX_USE_CURRENT_RANGE
SSH_TTY=/dev/pts/1; export SSH_TTY
USER=root; export USER
LS_COLORS=rs=0:di=01\;34:ln=01\;36:mh=00:pi=40\;33:so=01\;35:do=01\;35:bd=40\;33\;01:cd=40\;33\;01:or=40\;31\;01:mi=01\;05\;37\;41:su=37\;41:sg=30\;43:ca=30\;41:tw=30\;42:ow=34\;42:st=37\;44:ex=01\;32:\*.tar=01\;31:\*.tgz=01\;31:\*.arj=01\;31:\*.taz=01\;31:\*.lzh=01\;31:\*.lzma=01\;31:\*.tlz=01\;31:\*.txz=01\;31:\*.zip=01\;31:\*.z=01\;31:\*.Z=01\;31:\*.dz=01\;31:\*.gz=01\;31:\*.lz=01\;31:\*.xz=01\;31:\*.bz2=01\;31:\*.tbz=01\;31:\*.tbz2=01\;31:\*.bz=01\;31:\*.tz=01\;31:\*.deb=01\;31:\*.rpm=01\;31:\*.jar=01\;31:\*.rar=01\;31:\*.ace=01\;31:\*.zoo=01\;31:\*.cpio=01\;31:\*.7z=01\;31:\*.rz=01\;31:\*.jpg=01\;35:\*.jpeg=01\;35:\*.gif=01\;35:\*.bmp=01\;35:\*.pbm=01\;35:\*.pgm=01\;35:\*.ppm=01\;35:\*.tga=01\;35:\*.xbm=01\;35:\*.xpm=01\;35:\*.tif=01\;35:\*.tiff=01\;35:\*.png=01\;35:\*.svg=01\;35:\*.svgz=01\;35:\*.mng=01\;35:\*.pcx=01\;35:\*.mov=01\;35:\*.mpg=01\;35:\*.mpeg=01\;35:\*.m2v=01\;35:\*.mkv=01\;35:\*.ogm=01\;35:\*.mp4=01\;35:\*.m4v=01\;35:\*.mp4v=01\;35:\*.vob=01\;35:\*.qt=01\;35:\*.nuv=01\;35:\*.wmv=01\;35:\*.asf=01\;35:\*.rm=01\;35:\*.rmvb=01\;35:\*.flc=01\;35:\*.avi=01\;35:\*.fli=01\;35:\*.flv=01\;35:\*.gl=01\;35:\*.dl=01\;35:\*.xcf=01\;35:\*.xwd=01\;35:\*.yuv=01\;35:\*.cgm=01\;35:\*.emf=01\;35:\*.axv=01\;35:\*.anx=01\;35:\*.ogv=01\;35:\*.ogx=01\;35:\*.aac=01\;36:\*.au=01\;36:\*.flac=01\;36:\*.mid=01\;36:\*.midi=01\;36:\*.mka=01\;36:\*.mp3=01\;36:\*.mpc=01\;36:\*.ogg=01\;36:\*.ra=01\;36:\*.wav=01\;36:\*.axa=01\;36:\*.oga=01\;36:\*.spx=01\;36:\*.xspf=01\;36:; export LS_COLORS
MAIL=/var/spool/mail/root; export MAIL
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin; export PATH
PWD=/root; export PWD
LANG=en_US.UTF-8; export LANG
SELINUX_LEVEL_REQUESTED=; export SELINUX_LEVEL_REQUESTED
HISTCONTROL=ignoredups; export HISTCONTROL
SHLVL=1; export SHLVL
HOME=/root; export HOME
LOGNAME=root; export LOGNAME
CVS_RSH=ssh; export CVS_RSH
SSH_CONNECTION=192.168.137.1\ 56213\ 192.168.137.65\ 22; export SSH_CONNECTION
LESSOPEN=\|\|/usr/bin/lesspipe.sh\ %s; export LESSOPEN
G_BROKEN_FILENAMES=1; export G_BROKEN_FILENAMES
cd /root || {
echo 'Execution directory inaccessible' >&2
exit 1
}
${SHELL:-/bin/sh} << 'marcinDELIMITER0e859fa1'
wall at jobs1
wall at jobs2
wall at jobs3 marcinDELIMITER0e859fa1

(五)-f /path/from/somefile:从指定的文件中读取任务

[root@centos65 ~]# cat  >  atjobs.sh
wall jobs1
wall jobs2
[root@centos65 ~]# cat atjobs.sh
wall jobs1
wall jobs2
[root@centos65 ~]# at 11:10 < atjobs.sh
job 6 at 2019-05-21 11:10
[root@centos65 ~]# at -l
4 2019-05-21 11:00 a root
2 2019-05-21 11:00 a root
6 2019-05-21 11:10 a root
5 2019-05-21 11:00 a root
3 2019-05-21 11:00 a root
[root@centos65 ~]# at  -c 6
#!/bin/sh
# atrun uid=0 gid=0
# mail root 0
umask 22
HOSTNAME=centos65.jd.com; export HOSTNAME
SELINUX_ROLE_REQUESTED=; export SELINUX_ROLE_REQUESTED
SHELL=/bin/bash; export SHELL
HISTSIZE=1000; export HISTSIZE
SSH_CLIENT=192.168.137.1\ 56213\ 22; export SSH_CLIENT
SELINUX_USE_CURRENT_RANGE=; export SELINUX_USE_CURRENT_RANGE
SSH_TTY=/dev/pts/1; export SSH_TTY
USER=root; export USER
LS_COLORS=rs=0:di=01\;34:ln=01\;36:mh=00:pi=40\;33:so=01\;35:do=01\;35:bd=40\;33\;01:cd=40\;33\;01:or=40\;31\;01:mi=01\;05\;37\;41:su=37\;41:sg=30\;43:ca=30\;41:tw=30\;42:ow=34\;42:st=37\;44:ex=01\;32:\*.tar=01\;31:\*.tgz=01\;31:\*.arj=01\;31:\*.taz=01\;31:\*.lzh=01\;31:\*.lzma=01\;31:\*.tlz=01\;31:\*.txz=01\;31:\*.zip=01\;31:\*.z=01\;31:\*.Z=01\;31:\*.dz=01\;31:\*.gz=01\;31:\*.lz=01\;31:\*.xz=01\;31:\*.bz2=01\;31:\*.tbz=01\;31:\*.tbz2=01\;31:\*.bz=01\;31:\*.tz=01\;31:\*.deb=01\;31:\*.rpm=01\;31:\*.jar=01\;31:\*.rar=01\;31:\*.ace=01\;31:\*.zoo=01\;31:\*.cpio=01\;31:\*.7z=01\;31:\*.rz=01\;31:\*.jpg=01\;35:\*.jpeg=01\;35:\*.gif=01\;35:\*.bmp=01\;35:\*.pbm=01\;35:\*.pgm=01\;35:\*.ppm=01\;35:\*.tga=01\;35:\*.xbm=01\;35:\*.xpm=01\;35:\*.tif=01\;35:\*.tiff=01\;35:\*.png=01\;35:\*.svg=01\;35:\*.svgz=01\;35:\*.mng=01\;35:\*.pcx=01\;35:\*.mov=01\;35:\*.mpg=01\;35:\*.mpeg=01\;35:\*.m2v=01\;35:\*.mkv=01\;35:\*.ogm=01\;35:\*.mp4=01\;35:\*.m4v=01\;35:\*.mp4v=01\;35:\*.vob=01\;35:\*.qt=01\;35:\*.nuv=01\;35:\*.wmv=01\;35:\*.asf=01\;35:\*.rm=01\;35:\*.rmvb=01\;35:\*.flc=01\;35:\*.avi=01\;35:\*.fli=01\;35:\*.flv=01\;35:\*.gl=01\;35:\*.dl=01\;35:\*.xcf=01\;35:\*.xwd=01\;35:\*.yuv=01\;35:\*.cgm=01\;35:\*.emf=01\;35:\*.axv=01\;35:\*.anx=01\;35:\*.ogv=01\;35:\*.ogx=01\;35:\*.aac=01\;36:\*.au=01\;36:\*.flac=01\;36:\*.mid=01\;36:\*.midi=01\;36:\*.mka=01\;36:\*.mp3=01\;36:\*.mpc=01\;36:\*.ogg=01\;36:\*.ra=01\;36:\*.wav=01\;36:\*.axa=01\;36:\*.oga=01\;36:\*.spx=01\;36:\*.xspf=01\;36:; export LS_COLORS
MAIL=/var/spool/mail/root; export MAIL
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin; export PATH
PWD=/root; export PWD
LANG=en_US.UTF-8; export LANG
SELINUX_LEVEL_REQUESTED=; export SELINUX_LEVEL_REQUESTED
HISTCONTROL=ignoredups; export HISTCONTROL
SHLVL=1; export SHLVL
HOME=/root; export HOME
LOGNAME=root; export LOGNAME
CVS_RSH=ssh; export CVS_RSH
SSH_CONNECTION=192.168.137.1\ 56213\ 192.168.137.65\ 22; export SSH_CONNECTION
LESSOPEN=\|\|/usr/bin/lesspipe.sh\ %s; export LESSOPEN
G_BROKEN_FILENAMES=1; export G_BROKEN_FILENAMES
cd /root || {
echo 'Execution directory inaccessible' >&2
exit 1
}
${SHELL:-/bin/sh} << 'marcinDELIMITER1bfe0e60'
wall jobs1
wall jobs2 marcinDELIMITER1bfe0e60
[root@centos65 ~]# at  11:20  -f  atjobs.sh
job 7 at 2019-05-21 11:20
[root@centos65 ~]# at -l
4 2019-05-21 11:00 a root
7 2019-05-21 11:20 a root
2 2019-05-21 11:00 a root
6 2019-05-21 11:10 a root
5 2019-05-21 11:00 a root
3 2019-05-21 11:00 a root
[root@centos65 ~]# at -c   7
#!/bin/sh
# atrun uid=0 gid=0
# mail root 0
umask 22
HOSTNAME=centos65.jd.com; export HOSTNAME
SELINUX_ROLE_REQUESTED=; export SELINUX_ROLE_REQUESTED
SHELL=/bin/bash; export SHELL
HISTSIZE=1000; export HISTSIZE
SSH_CLIENT=192.168.137.1\ 56213\ 22; export SSH_CLIENT
SELINUX_USE_CURRENT_RANGE=; export SELINUX_USE_CURRENT_RANGE
SSH_TTY=/dev/pts/1; export SSH_TTY
USER=root; export USER
LS_COLORS=rs=0:di=01\;34:ln=01\;36:mh=00:pi=40\;33:so=01\;35:do=01\;35:bd=40\;33\;01:cd=40\;33\;01:or=40\;31\;01:mi=01\;05\;37\;41:su=37\;41:sg=30\;43:ca=30\;41:tw=30\;42:ow=34\;42:st=37\;44:ex=01\;32:\*.tar=01\;31:\*.tgz=01\;31:\*.arj=01\;31:\*.taz=01\;31:\*.lzh=01\;31:\*.lzma=01\;31:\*.tlz=01\;31:\*.txz=01\;31:\*.zip=01\;31:\*.z=01\;31:\*.Z=01\;31:\*.dz=01\;31:\*.gz=01\;31:\*.lz=01\;31:\*.xz=01\;31:\*.bz2=01\;31:\*.tbz=01\;31:\*.tbz2=01\;31:\*.bz=01\;31:\*.tz=01\;31:\*.deb=01\;31:\*.rpm=01\;31:\*.jar=01\;31:\*.rar=01\;31:\*.ace=01\;31:\*.zoo=01\;31:\*.cpio=01\;31:\*.7z=01\;31:\*.rz=01\;31:\*.jpg=01\;35:\*.jpeg=01\;35:\*.gif=01\;35:\*.bmp=01\;35:\*.pbm=01\;35:\*.pgm=01\;35:\*.ppm=01\;35:\*.tga=01\;35:\*.xbm=01\;35:\*.xpm=01\;35:\*.tif=01\;35:\*.tiff=01\;35:\*.png=01\;35:\*.svg=01\;35:\*.svgz=01\;35:\*.mng=01\;35:\*.pcx=01\;35:\*.mov=01\;35:\*.mpg=01\;35:\*.mpeg=01\;35:\*.m2v=01\;35:\*.mkv=01\;35:\*.ogm=01\;35:\*.mp4=01\;35:\*.m4v=01\;35:\*.mp4v=01\;35:\*.vob=01\;35:\*.qt=01\;35:\*.nuv=01\;35:\*.wmv=01\;35:\*.asf=01\;35:\*.rm=01\;35:\*.rmvb=01\;35:\*.flc=01\;35:\*.avi=01\;35:\*.fli=01\;35:\*.flv=01\;35:\*.gl=01\;35:\*.dl=01\;35:\*.xcf=01\;35:\*.xwd=01\;35:\*.yuv=01\;35:\*.cgm=01\;35:\*.emf=01\;35:\*.axv=01\;35:\*.anx=01\;35:\*.ogv=01\;35:\*.ogx=01\;35:\*.aac=01\;36:\*.au=01\;36:\*.flac=01\;36:\*.mid=01\;36:\*.midi=01\;36:\*.mka=01\;36:\*.mp3=01\;36:\*.mpc=01\;36:\*.ogg=01\;36:\*.ra=01\;36:\*.wav=01\;36:\*.axa=01\;36:\*.oga=01\;36:\*.spx=01\;36:\*.xspf=01\;36:; export LS_COLORS
MAIL=/var/spool/mail/root; export MAIL
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin; export PATH
PWD=/root; export PWD
LANG=en_US.UTF-8; export LANG
SELINUX_LEVEL_REQUESTED=; export SELINUX_LEVEL_REQUESTED
HISTCONTROL=ignoredups; export HISTCONTROL
SHLVL=1; export SHLVL
HOME=/root; export HOME
LOGNAME=root; export LOGNAME
CVS_RSH=ssh; export CVS_RSH
SSH_CONNECTION=192.168.137.1\ 56213\ 192.168.137.65\ 22; export SSH_CONNECTION
LESSOPEN=\|\|/usr/bin/lesspipe.sh\ %s; export LESSOPEN
G_BROKEN_FILENAMES=1; export G_BROKEN_FILENAMES
cd /root || {
echo 'Execution directory inaccessible' >&2
exit 1
}
${SHELL:-/bin/sh} << 'marcinDELIMITER7d9da0c8'
wall jobs1
wall jobs2 marcinDELIMITER7d9da0c8

(六)-m:当任务被完成之后,将给用户发送邮件,即使没有标准输出

[root@centos65 ~]# at  10:50  -m
at> true<EOT>
job 8 at 2019-05-21 10:50
[root@centos65 ~]# at -l
4 2019-05-21 11:00 a root
8 2019-05-21 10:50 a root
7 2019-05-21 11:20 a root
2 2019-05-21 11:00 a root
6 2019-05-21 11:10 a root
5 2019-05-21 11:00 a root
3 2019-05-21 11:00 a root
[root@centos65 ~]# date
Tue May 21 10:45:46 CST

按时发送了一封邮件

[root@centos65 ~]# mail
Heirloom Mail version 12.4 7/29/08. Type ? for help.
"/var/spool/mail/root": 1 message 1 new
>N 1 root Tue May 21 10:50 13/453 "Output from your job 8"
& 1
Message 1:
From root@centos65.jd.com Tue May 21 10:50:01 2019
Return-Path: <root@centos65.jd.com>
X-Original-To: root
Delivered-To: root@centos65.jd.com
Subject: Output from your job 8
To: root@centos65.jd.com
Date: Tue, 21 May 2019 10:50:00 +0800 (CST)
From: root@centos65.jd.com (root)
Status: R

五at时间格式示例

TIME:定义出什么时候进行 at 这项任务的时间
HH:MM [YYYY-mm-dd]
noon, midnight, teatime(4pm)
tomorrow
now+#{minutes,hours,days, OR weeks}

注意如果定义的计划任务时间超过了今天的时间,那么计划任务会在明天执行

比如现在是10点,定义的计划任务在9点那么最早就是明天的9点

[root@centos65 ~]# at  10:20
at> pwd
at> <EOT>
job 9 at 2019-05-22 10:20
[root@centos65 ~]# at -l
4 2019-05-21 11:00 a root
7 2019-05-21 11:20 a root
2 2019-05-21 11:00 a root
9 2019-05-22 10:20 a root
6 2019-05-21 11:10 a root
5 2019-05-21 11:00 a root
3 2019-05-21 11:00 a root

修改现在的时间

[root@centos65 ~]# at -l
4 2019-05-21 11:00 a root
7 2019-05-21 11:20 a root
2 2019-05-21 11:00 a root
9 2019-05-22 10:20 a root
6 2019-05-21 11:10 a root
5 2019-05-21 11:00 a root
3 2019-05-21 11:00 a root
[root@centos65 ~]# date 052210302019
Wed May 22 10:30:00 CST 2019
[root@centos65 ~]# date
Wed May 22 10:30:03 CST 2019
[root@centos65 ~]# at -l
4 2019-05-21 11:00 a root
7 2019-05-21 11:20 a root
2 2019-05-21 11:00 a root
9 2019-05-22 10:20 a root
6 2019-05-21 11:10 a root
5 2019-05-21 11:00 a root
3 2019-05-21 11:00 a root

硬件时间没变,重启之后先读取硬件时间

注意到了计划任务的时间,没有执行文件不会被删除

[root@centos65 ~]# clock
Tue 21 May 2019 10:58:15 AM CST -0.563769 seconds

(一)从现在往后推多长时间

now+#{minutes,hours,days, OR weeks}

[root@centos72 ~]# at now+20minutes
at> pwd<EOT>
job 5 at Tue May 21 11:22:00 2019
[root@centos72 ~]# at -l
5 Tue May 21 11:22:00 2019 a root
[root@centos72 ~]# date
Tue May 21 11:03:11 CST

单位可以简写,但是不能不写

[root@centos72 ~]# at now+40min
at> ls<EOT>
job 6 at Tue May 21 11:44:00 2019
[root@centos72 ~]# at -l
5 Tue May 21 11:22:00 2019 a root
6 Tue May 21 11:44:00 2019 a root

(二)/etc/at.{allow,deny}控制用户是否能执行at任务

白名单:/etc/at.allow 默认不存在,只有该文件中的用户才能执行at命令
黑名单:/etc/at.deny 默认存在,拒绝该文件中用户执行at命令,而没有在at.deny 文件中的使用者则可执行
如果两个文件都不存在,只有 root 可以执行 at 命令

普通用户默认是可以执行计划任务的

[root@centos72 ~]# su - wang
Last login: Mon May 20 22:38:25 CST 2019 on pts/1
[wang@centos72 ~]$ at 11:10
at> wall jobs1<EOT>
job 7 at Tue May 21 11:10:00 2019
[wang@centos72 ~]$ at -l
7 Tue May 21 11:10:00 2019 a wang
[wang@centos72 ~]$ date
Tue May 21 11:08:49 CST 2019
[wang@centos72 ~]$ pwd
/home/wang
[wang@centos72 ~]$
Broadcast message from wang@centos72.huawei.com (Tue May 21 11:10:00 2019): jobs1
^C

让普通用户不能执行计划任务

[wang@centos72 ~]$ exit
logout
[root@centos72 ~]# ll /etc/at.deny
-rw-r--r--. 1 root root 1 Oct 31 2018 /etc/at.deny
[root@centos72 ~]# cat /etc/at.deny [root@centos72 ~]# echo wang > /etc/at.deny
[root@centos72 ~]# cat /etc/at.deny
wang
[root@centos72 ~]# su - wang
Last login: Tue May 21 11:08:19 CST 2019 on pts/0
[wang@centos72 ~]$ at -l
You do not have permission to use at.
[wang@centos72 ~]$ at 11:20
You do not have permission to use at.
[wang@centos72 ~]$ pwd
/home/wang
[wang@centos72 ~]$

白名单:/etc/at.allow 默认不存在,只有该文件中的用户才能执行at命令

注意如果黑名单白名单都有的用户那么白名单优先生效,但是不在白名单里面的用户就会被拒绝

如果没有白名单文件,那么在黑名单之外的其他用户会被允许

[root@centos72 ~]# cat /etc/at.allow
cat: /etc/at.allow: No such file or directory
[root@centos72 ~]# echo wang > /etc/at.allow
[root@centos72 ~]# cat /etc/at.allow
wang
[root@centos72 ~]# ll /etc/at.allow
-rw-r--r--. 1 root root 5 May 21 11:15 /etc/at.allow
[root@centos72 ~]# su - wang
Last login: Tue May 21 11:12:27 CST 2019 on pts/0
[wang@centos72 ~]$ at -l
[wang@centos72 ~]$ at 11:20
at> ls<EOT>
job 8 at Tue May 21 11:20:00 2019
[wang@centos72 ~]$ at -l
8 Tue May 21 11:20:00 2019 a wang
[wang@centos72 ~]$

目前只有wang才可以创建计划任务

[root@centos72 ~]# cat /etc/at.allow
wang
[root@centos72 ~]# cat /etc/at.deny
wang
[root@centos72 ~]# cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
polkitd:x:999:998:User for polkitd:/:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
wang:x:1000:1000:wang:/home/wang:/bin/bash
apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin
rooter:x:1001:1001::/home/rooter:/bin/bash
123:x:1002:1002::/home/123:/bin/bash
[root@centos72 ~]# su - rooter
[rooter@centos72 ~]$ pwd
/home/rooter
[rooter@centos72 ~]$ at -l
You do not have permission to use at.
[rooter@centos72 ~]$ at 11:20
You do not have permission to use at.
[rooter@centos72 ~]$ exit
logout

如果两个文件都不存在,只有 root 可以执行 at 命令

[root@centos72 ~]# rm -f  /etc/at.*
[root@centos72 ~]# cat /etc/at.deny
cat: /etc/at.deny: No such file or directory
[root@centos72 ~]# cat /etc/at.allow
cat: /etc/at.allow: No such file or directory
[root@centos72 ~]# su - wang
Last login: Tue May 21 11:15:48 CST 2019 on pts/0
[wang@centos72 ~]$ at -l
You do not have permission to use at.

at具有特殊权限

[root@centos72 ~]# which at
/usr/bin/at
[root@centos72 ~]# ll /usr/bin/at
-rwsr-xr-x. 1 root root 53048 Oct 31 2018 /usr/bin/at

无法控制管理员

[root@centos72 ~]# echo  root  >  /etc/at.deny
[root@centos72 ~]# cat /etc/at.deny
root
[root@centos72 ~]# at -l
6 Tue May 21 11:44:00 2019 a root
[root@centos72 ~]# at 11:30
at> pwd
at> <EOT>
job 9 at Tue May 21 11:30:00 2019
[root@centos72 ~]# at -l
6 Tue May 21 11:44:00 2019 a root
9 Tue May 21 11:30:00 2019 a root

at使用的不多

一次性删除多个计划任务,直接删除文件即可

[root@centos72 ~]# at -l
6 Tue May 21 11:44:00 2019 a root
9 Tue May 21 11:30:00 2019 a root
[root@centos72 ~]# ls /var/spool/at/
a00006018c5300 spool
You have new mail in /var/spool/mail/root
[root@centos72 ~]# rm -f /var/spool/at/a00006018c5300
[root@centos72 ~]# ls /var/spool/at/
spool
[root@centos72 ~]# at -l

Linux任务计划at的更多相关文章

  1. Linux任务计划

    Linux任务计划: 一次性任务执行(at.batch): at:定时任务,指定一个时间执行一个任务,只能执行一次. at使用方式: 交互式:让用户在at>提示符输入多个要执行的命令: 批处理: ...

  2. 配置Linux任务计划

    Linux有三种计划任务: at:指定一个时间执行一个任务 (适用一个或多个任务,执行一次后就不用) cron:根据一个时间表自动执行任务 (使用一个或多个任务,周期性执行) 系统级别的计划任务及其扩 ...

  3. Linux操作系统计划任务

    ++++++++++++++++++++++++++++++++++++++++++++++++标题:Linux操作系统的计划任务内容:计划任务分为单次任务和周期性任务,周期任务分为系统级计划任务和用 ...

  4. Linux中计划任务、周期性任务设置

    Linux中计划任务.周期性任务设置 计划任务:指在未来的特定时间里,执行一次某一特定任务.当然,如果同一任务需要在不同时间点执行执行两次.三次或多次,可以视为多个一次看待. 周期性任务:指某一任务需 ...

  5. Linux定时任务计划

    Linux定时任务计划 在使用Linux系统时,我们有时会需要让系统在某个时间去执行特定的任务,这时就需要去了解Linux提供的定时任务功能 种类 Linux的定时任务分为两种:单一型和循环型 单一型 ...

  6. linux 的计划任务 定时任务

    linux的计划任务,也叫做定时任务 https://www.cnblogs.com/mingforyou/p/3930636.html 名字是crond 查看linux本机的定时任务 crontab ...

  7. linux任务计划 chkconfig工具 systemd管理服务 unit介绍 target介绍

    linux任务计划 任务计划:特定时间备份数据,重启服务,shell脚本,单独的命令等等. 任务计划配置文件:cat /etc/crontab [root@centos7 ~]# cat /etc/c ...

  8. linux任务计划cron

    linux任务计划cron 1.crontab命令任务计划配置文件 [root@bogon ~]# cat /etc/crontab SHELL=/bin/bash PATH=/sbin:/bin:/ ...

  9. Linux任务计划、周期性任务执行

    Linux任务计划.周期性任务执行 周期性任务执行: cron 守护进程(crond):服务,不间断地运行于后台 # service crond {start|stop|status|restart} ...

  10. linux下计划任务学习记录

    0x01 计划任务简介 linux 中计划任务主要分为”循环执行”和”只执行一次”两种,分别对应的时 crond 服务 和 atd 服务: 0x02 只执行一次的计划任务 0x02.1 atd 服务说 ...

随机推荐

  1. HTML中<input>和<textarea>的区别

    在HTML中有两种方式表达文本框 一个是<input>元素的单行文本框 一种是<textarea>的多行文本框. <input>元素: 1.一定要指定type的值为 ...

  2. 用flask写一个简单的接口

    用falsk写一个简单的接口,这个接口的数据本来是爬虫爬取的数据,但是今天只写一个flask接口,数据就用测试数据好了. import random import re import time imp ...

  3. 麦子lavarel---16、日志

    麦子lavarel---16.日志 一.总结 一句话总结: 一定要养成打印日志查看日志的好习惯,非常节约时间和便于查错 1.console.Log(“获取类别数据:"):console.Lo ...

  4. win10半夜自动开机的问题分析

    win10半夜自动开机的系统日志: 解决方法一: 1.根据日志判断自动唤醒后,windows更新了时间和代理 服务管理器中,关闭windows update, 但是半夜还会自动开 再关闭服务管理器的w ...

  5. 【CDN+】 CDN项目的两大核心--缓存与回源

    前言 项目中碰到CDN专用名词: 回源, 然后不知道什么意思,反过来查询了一下CDN相关的一些基本术语,特做记录 CDN基础概念 CDN (Content Delivery Network,即内容分发 ...

  6. WPF样式统一之DevExpress设置窗体,控件为Office风格

    DevExpress相信不少人用过,虽然人家不是免费的,但是用过的应该都知道,确实是花了心血的C#插件,下面来介绍下在DevExpress下如何统一设置自己的WPF程序为经典Windows风格. 窗体 ...

  7. Java中的I/O

    1.Java中的I/O分类 I/O分类: 输入流,输出流,或者字节流,字符流 I/O中的四个抽象基类: InputStream,OutputStream:两者属于字节流,前者输入,后者输出.一般后缀名 ...

  8. Android应用程序开发中碰到的错误和获得的小经验

    1,Installation error: INSTALL_FAILED_INSUFFICIENT_STORAGE Description:这表示手机内存不足,对内存较小的手机经常会出现这样的问题,从 ...

  9. NGUI的拖拽和放下功能的制作,简易背包系统功能(drag and drop item)

    一我们添加sprite,给sprite添加背景图片和添加box collider,但是drag and drop item在attach中是找不到的只能在add component中查找添加,如下图: ...

  10. Hibernate4教程二:基本配置(2)

    <hibernate-mapping>元素 这个元素是xxx.hbm.xml配置的根元素,定义如下: java代码: <hibernate-mapping schema=" ...