每天一个Linux命令(43)at命令

    at命令用于在指定时间执行命令。at允许使用一套相当复杂的指定时间的方法。可以用相对时间法指定,也可以用绝对时间法指定。

    (1)用法:

    用法:  at  [选项参数]  [时间]

    (2)功能:

    功能:  在指定的时间执行命令。

    (3)选项参数:

1) -c          显示即将执行任务的细节

2) -d           用任务id号删除指定的任务

3) -l              等同于atq,用job的id号显示指定的未删除而待执行的任务

  (4)实例: 

1)[root@localhost sunjimeng]# at now + 1 minutes       用相对时间,在一分钟之后执行命令

[root@localhost sunjimeng]# at now + 2 minutes
at> echo "I'm MenAngel!,I'm study at order!"
at> <EOT>
job 11 at Wed Jun 8 17:46:00 2016

at> <EOT>

<这里输入 [ctrl] + d 就会出现 <EOF> 的字样代表结束!

当你输入下一个命令时,系统会自动提醒你,您在 /var/spool/mail/sunjimeng 中有邮件。此邮件中就包含这个命令执行的结果。

2)[root@localhost sunjimeng]# at 17:47           在一个绝对时间执行一个命令

[root@localhost sunjimeng]# at :
at> ls -l /home/sunjimeng/Documents
at> <EOT>
job at Wed Jun ::
您在 /var/spool/mail/sunjimeng 中有新邮件

这里在语句的末尾提醒你有新邮件,可以用cat命令查看文件:/var/spool/mail/sunjimeng。

3)[root@localhost sunjimeng]# atq              计划任务设定后,在没有执行之前我们可以用atq命令来查看系统没有执行工作任务           

[root@localhost sunjimeng]# atq
Wed Jun :: a root
Wed Jun :: a root
Wed Jun :: a root
Wed Jun :: a root
Sat Jun :: a root
Wed Jun :: a root

4)[root@localhost sunjimeng]# atq              删除已经设置的任务

[root@localhost sunjimeng]# atq
Wed Jun :: a root
Wed Jun :: a root
Wed Jun :: a root
Wed Jun :: a root
Sat Jun :: a root
Wed Jun :: a root
[root@localhost sunjimeng]# atrm
[root@localhost sunjimeng]# atq
Wed Jun :: a root

5)[root@localhost sunjimeng]# cat /var/spool/mail/sunjimeng      显示at命令的执行结果  

[root@localhost sunjimeng]# cat /var/spool/mail/sunjimeng
From root@localhost.localdomain Wed Jun ::
Return-Path: <root@localhost.localdomain>
X-Original-To: sunjimeng
Delivered-To: sunjimeng@localhost.localdomain
Received: by localhost.localdomain (Postfix, from userid )
id 24622632F338; Wed, Jun :: - (PDT)
Subject: Output from your job
To: sunjimeng@localhost.localdomain
Message-Id: <.24622632F338@localhost.localdomain>
Date: Wed, Jun :: - (PDT)
From: root@localhost.localdomain (root) I'm MenAngel!,I'm study at order! From root@localhost.localdomain Wed Jun ::
Return-Path: <root@localhost.localdomain>
X-Original-To: sunjimeng
Delivered-To: sunjimeng@localhost.localdomain
Received: by localhost.localdomain (Postfix, from userid )
id C83A5632F338; Wed, Jun :: - (PDT)
Subject: Output from your job
To: sunjimeng@localhost.localdomain
Message-Id: <.C83A5632F338@localhost.localdomain>
Date: Wed, Jun :: - (PDT)
From: root@localhost.localdomain (root) 总用量
drwxr-xr-x. root root 5月 : grepDir
-rw-r--r--. root root 6月 : myfile
drwxr-xr-x. root root 6月 : newWatch From root@localhost.localdomain Wed Jun ::
Return-Path: <root@localhost.localdomain>
X-Original-To: sunjimeng
Delivered-To: sunjimeng@localhost.localdomain
Received: by localhost.localdomain (Postfix, from userid )
id C9EA3632F33A; Wed, Jun :: - (PDT)
Subject: Output from your job
To: sunjimeng@localhost.localdomain
Message-Id: <.C9EA3632F33A@localhost.localdomain>
Date: Wed, Jun :: - (PDT)
From: root@localhost.localdomain (root) 总用量
drwxr-xr-x. root root 5月 : grepDir
-rw-r--r--. root root 6月 : myfile
drwxr-xr-x. root root 6月 : newWatch From root@localhost.localdomain Wed Jun ::
Return-Path: <root@localhost.localdomain>
X-Original-To: sunjimeng
Delivered-To: sunjimeng@localhost.localdomain
Received: by localhost.localdomain (Postfix, from userid )
id F3239632F338; Wed, Jun :: - (PDT)
Subject: Output from your job
To: sunjimeng@localhost.localdomain
Message-Id: <.F3239632F338@localhost.localdomain>
Date: Wed, Jun :: - (PDT)
From: root@localhost.localdomain (root) I'm MenAngel From root@localhost.localdomain Wed Jun ::
Return-Path: <root@localhost.localdomain>
X-Original-To: sunjimeng
Delivered-To: sunjimeng@localhost.localdomain
Received: by localhost.localdomain (Postfix, from userid )
id 4B264632F338; Wed, Jun :: - (PDT)
Subject: Output from your job
To: sunjimeng@localhost.localdomain
Message-Id: <.4B264632F338@localhost.localdomain>
Date: Wed, Jun :: - (PDT)
From: root@localhost.localdomain (root) 总用量
drwxr-xr-x. sunjimeng sunjimeng 5月 : Desktop
drwxrwxr-x. sunjimeng users 5月 : Document
drwxr-xr-x. root sunjimeng 6月 : Documents
drwxr-xr-x. sunjimeng sunjimeng 5月 : Downloads
drwxrwxr-x. sunjimeng sunjimeng 5月 : findTextDir
drwxr-xr-x. sunjimeng sunjimeng 5月 : Music
drwxr-xr-x. sunjimeng sunjimeng 5月 : Pictures
drwxr-xr-x. sunjimeng sunjimeng 5月 : Public
drwxr-xr-x. sunjimeng sunjimeng 5月 : Templates
drwxr-xr-x. sunjimeng sunjimeng 5月 : Videos From root@localhost.localdomain Wed Jun ::
Return-Path: <root@localhost.localdomain>
X-Original-To: sunjimeng
Delivered-To: sunjimeng@localhost.localdomain
Received: by localhost.localdomain (Postfix, from userid )
id 4E5D2632F33A; Wed, Jun :: - (PDT)
Subject: Output from your job
To: sunjimeng@localhost.localdomain
Message-Id: <.4E5D2632F33A@localhost.localdomain>
Date: Wed, Jun :: - (PDT)
From: root@localhost.localdomain (root) 总用量
drwxr-xr-x. root root 5月 : grepDir
-rw-r--r--. root root 6月 : myfile
drwxr-xr-x. root root 6月 : newWatch

6)[sunjimeng@localhost ~]$ at -c 18          根据id号查看即将要执行命令的细节

[sunjimeng@localhost ~]$ atq                      //显示结果表明没有即将要执行的任务
[sunjimeng@localhost ~]$ at now + minutes //新建一个要执行的任务
at> ls -l
at> <EOT>
job at Wed Jun ::
[sunjimeng@localhost ~]$ atq //查看
Wed Jun :: a sunjimeng
[sunjimeng@localhost ~]$ at -c 18 //根据id号查看,它的即将执行的细节
#!/bin/sh
# atrun uid= gid=
# mail sunjimeng
umask
XDG_VTNR=; export XDG_VTNR
SSH_AGENT_PID=; export SSH_AGENT_PID
XDG_SESSION_ID=; export XDG_SESSION_ID
HOSTNAME=localhost.localdomain; export HOSTNAME
IMSETTINGS_INTEGRATE_DESKTOP=yes; export IMSETTINGS_INTEGRATE_DESKTOP
GPG_AGENT_INFO=/run/user//keyring-CchymL/gpg::; export GPG_AGENT_INFO
VTE_VERSION=; export VTE_VERSION
SHELL=/bin/bash; export SHELL
XDG_MENU_PREFIX=gnome-; export XDG_MENU_PREFIX
HISTSIZE=; export HISTSIZE
GJS_DEBUG_OUTPUT=stderr; export GJS_DEBUG_OUTPUT
WINDOWID=; export WINDOWID
GNOME_KEYRING_CONTROL=/run/user//keyring-CchymL; export GNOME_KEYRING_CONTROL
GJS_DEBUG_TOPICS=JS\ ERROR\;JS\ LOG; export GJS_DEBUG_TOPICS
IMSETTINGS_MODULE=IBus; export IMSETTINGS_MODULE
USER=sunjimeng; export USER
LS_COLORS=rs=:di=\;\;:ln=\;\;:mh=\;\;\;:pi=\;\;\;:so=\;\;:do=\;\;:bd=\;\;\;\;\;:cd=\;\;\;\;\;:or=\;\;\;\;\;:mi=\;\;\;\;\;\;:su=\;\;\;\;\;:sg=\;\;\;\;\;:ca=\;\;\;\;\;:tw=\;\;\;\;\;:ow=\;\;\;\;\;:st=\;\;\;\;\;:ex=\;\;:\*.tar=\;\;:\*.tgz=\;\;:\*.arc=\;\;:\*.arj=\;\;:\*.taz=\;\;:\*.lha=\;\;:\*.lz4=\;\;:\*.lzh=\;\;:\*.lzma=\;\;:\*.tlz=\;\;:\*.txz=\;\;:\*.tzo=\;\;:\*.t7z=\;\;:\*.zip=\;\;:\*.z=\;\;:\*.Z=\;\;:\*.dz=\;\;:\*.gz=\;\;:\*.lrz=\;\;:\*.lz=\;\;:\*.lzo=\;\;:\*.xz=\;\;:\*.bz2=\;\;:\*.bz=\;\;:\*.tbz=\;\;:\*.tbz2=\;\;:\*.tz=\;\;:\*.deb=\;\;:\*.rpm=\;\;:\*.jar=\;\;:\*.war=\;\;:\*.ear=\;\;:\*.sar=\;\;:\*.rar=\;\;:\*.alz=\;\;:\*.ace=\;\;:\*.zoo=\;\;:\*.cpio=\;\;:\*.7z=\;\;:\*.rz=\;\;:\*.cab=\;\;:\*.jpg=\;\;:\*.jpeg=\;\;:\*.gif=\;\;:\*.bmp=\;\;:\*.pbm=\;\;:\*.pgm=\;\;:\*.ppm=\;\;:\*.tga=\;\;:\*.xbm=\;\;:\*.xpm=\;\;:\*.tif=\;\;:\*.tiff=\;\;:\*.png=\;\;:\*.svg=\;\;:\*.svgz=\;\;:\*.mng=\;\;:\*.pcx=\;\;:\*.mov=\;\;:\*.mpg=\;\;:\*.mpeg=\;\;:\*.m2v=\;\;:\*.mkv=\;\;:\*.webm=\;\;:\*.ogm=\;\;:\*.mp4=\;\;:\*.m4v=\;\;:\*.mp4v=\;\;:\*.vob=\;\;:\*.qt=\;\;:\*.nuv=\;\;:\*.wmv=\;\;:\*.asf=\;\;:\*.rm=\;\;:\*.rmvb=\;\;:\*.flc=\;\;:\*.avi=\;\;:\*.fli=\;\;:\*.flv=\;\;:\*.gl=\;\;:\*.dl=\;\;:\*.xcf=\;\;:\*.xwd=\;\;:\*.yuv=\;\;:\*.cgm=\;\;:\*.emf=\;\;:\*.axv=\;\;:\*.anx=\;\;:\*.ogv=\;\;:\*.ogx=\;\;:\*.aac=\;\;:\*.au=\;\;:\*.flac=\;\;:\*.mid=\;\;:\*.midi=\;\;:\*.mka=\;\;:\*.mp3=\;\;:\*.mpc=\;\;:\*.ogg=\;\;:\*.ra=\;\;:\*.wav=\;\;:\*.axa=\;\;:\*.oga=\;\;:\*.spx=\;\;:\*.xspf=\;\;:; export LS_COLORS
SSH_AUTH_SOCK=/run/user//keyring-CchymL/ssh; export SSH_AUTH_SOCK
SESSION_MANAGER=local/unix:@/tmp/.ICE-unix/,unix/unix:/tmp/.ICE-unix/; export SESSION_MANAGER
USERNAME=sunjimeng; export USERNAME
GNOME_SHELL_SESSION_MODE=classic; export GNOME_SHELL_SESSION_MODE
PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/home/sunjimeng/.local/bin:/home/sunjimeng/bin; export PATH
MAIL=/var/spool/mail/sunjimeng; export MAIL
DESKTOP_SESSION=gnome-classic; export DESKTOP_SESSION
QT_IM_MODULE=ibus; export QT_IM_MODULE
PWD=/home/sunjimeng; export PWD
XMODIFIERS=@im=ibus; export XMODIFIERS
GNOME_KEYRING_PID=; export GNOME_KEYRING_PID
LANG=zh_CN.utf8; export LANG
GDM_LANG=zh_CN.utf8; export GDM_LANG
GDMSESSION=gnome-classic; export GDMSESSION
HISTCONTROL=ignoredups; export HISTCONTROL
XDG_SEAT=seat0; export XDG_SEAT
HOME=/home/sunjimeng; export HOME
SHLVL=; export SHLVL
GNOME_DESKTOP_SESSION_ID=this-is-deprecated; export GNOME_DESKTOP_SESSION_ID
LOGNAME=sunjimeng; export LOGNAME
DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-O0naLUCbYg,guid=ad8d9a1bab9eccd8c11d0a6257493a83; export DBUS_SESSION_BUS_ADDRESS
LESSOPEN=\|\|/usr/bin/lesspipe.sh\ %s; export LESSOPEN
WINDOWPATH=; export WINDOWPATH
XDG_RUNTIME_DIR=/run/user/; export XDG_RUNTIME_DIR
COLORTERM=gnome-terminal; export COLORTERM
XAUTHORITY=/run/gdm/auth-for-sunjimeng-Bcg9Bg/database; export XAUTHORITY
cd /home/sunjimeng || {
echo 'Execution directory inaccessible' >&
exit
}
${SHELL:-/bin/sh} << 'marcinDELIMITER7e20521d'
ls -l marcinDELIMITER7e20521d
[sunjimeng@localhost ~]$

7)[sunjimeng@localhost ~]$ at -d 21        取消指向执行id号为21的任务

[sunjimeng@localhost ~]$ atq
Wed Jun :: a sunjimeng
Wed Jun :: a sunjimeng
[sunjimeng@localhost ~]$ atrm
[sunjimeng@localhost ~]$ atq
Wed Jun :: a sunjimeng
[sunjimeng@localhost ~]$ at -d
[sunjimeng@localhost ~]$ atq
上一篇:log4net--不可多得的开源日志记录组件


下一篇:字典树(Tire)模板