歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux技術

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

[b] at命令用於在指定時間執行命令。at允許使用一套相當復雜的指定時間的方法。可以用相對時間法指定,也可以用絕對時間法指定。[/b][b] (1)用法:[/b]

[b] 用法: at [選項參數] [時間][/b][b] (2)功能:[/b]

[b] 功能: 在指定的時間執行命令。[/b][b] (3)選項參數:[/b]

1) -c          顯示即將執行任務的細節 2) -d          用任務id號刪除指定的任務

3) -l          等同於atq,用job的id號顯示指定的未刪除而待執行的任務 [b] (4)實例: [/b]

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 17:47
at> ls -l /home/sunjimeng/Documents
at> <EOT>
job 13 at Wed Jun  8 17:47:00 2016
您在 /var/spool/mail/sunjimeng 中有新郵件
這裡在語句的末尾提醒你有新郵件,可以用cat命令查看文件:/var/spool/mail/sunjimeng。

3)[root@localhost sunjimeng]# atq              計劃任務設定後,在沒有執行之前我們可以用atq命令來查看系統沒有執行工作任務           

[root@localhost sunjimeng]# atq
1    Wed Jun  8 17:21:00 2016 a root
2    Wed Jun  8 17:23:00 2016 a root
3    Wed Jun  8 17:23:00 2016 a root
4    Wed Jun  8 17:26:00 2016 a root
5    Sat Jun 11 17:00:00 2016 a root
6    Wed Jun  8 17:31:00 2016 a root

4)[root@localhost sunjimeng]# atq              刪除已經設置的任務

[root@localhost sunjimeng]# atq
1    Wed Jun  8 17:21:00 2016 a root
2    Wed Jun  8 17:23:00 2016 a root
3    Wed Jun  8 17:23:00 2016 a root
4    Wed Jun  8 17:26:00 2016 a root
5    Sat Jun 11 17:00:00 2016 a root
6    Wed Jun  8 17:31:00 2016 a root

[root@localhost sunjimeng]# atrm 1 2 3 4 5

[root@localhost sunjimeng]# atq6 Wed Jun 8 17:31:00 2016 a root

5)[root@localhost sunjimeng]# cat /var/spool/mail/sunjimeng      顯示at命令的執行結果  

[root@localhost sunjimeng]# cat /var/spool/mail/sunjimeng
From [email protected]  Wed Jun  8 17:46:01 2016
Return-Path: <[email protected]>
X-Original-To: sunjimeng
Delivered-To: [email protected]
Received: by localhost.localdomain (Postfix, from userid 0)
    id 24622632F338; Wed,  8 Jun 2016 17:46:01 -0700 (PDT)
Subject: Output from your job       11
To: [email protected]
Message-Id: <[email protected]>
Date: Wed,  8 Jun 2016 17:46:01 -0700 (PDT)
From: [email protected] (root)

I'm MenAngel!,I'm study at order!

From [email protected]  Wed Jun  8 17:47:00 2016
Return-Path: <[email protected]>
X-Original-To: sunjimeng
Delivered-To: [email protected]
Received: by localhost.localdomain (Postfix, from userid 0)
    id C83A5632F338; Wed,  8 Jun 2016 17:47:00 -0700 (PDT)
Subject: Output from your job       13
To: [email protected]
Message-Id: <[email protected]>
Date: Wed,  8 Jun 2016 17:47:00 -0700 (PDT)
From: [email protected] (root)

總用量 0
drwxr-xr-x. 2 root root 72 5月  31 18:25 grepDir
-rw-r--r--. 1 root root  0 6月   7 23:34 myfile
drwxr-xr-x. 2 root root  6 6月   7 23:33 newWatch

From [email protected]  Wed Jun  8 17:47:00 2016
Return-Path: <[email protected]>
X-Original-To: sunjimeng
Delivered-To: [email protected]
Received: by localhost.localdomain (Postfix, from userid 0)
    id C9EA3632F33A; Wed,  8 Jun 2016 17:47:00 -0700 (PDT)
Subject: Output from your job       12
To: [email protected]
Message-Id: <[email protected]>
Date: Wed,  8 Jun 2016 17:47:00 -0700 (PDT)
From: [email protected] (root)

總用量 0
drwxr-xr-x. 2 root root 72 5月  31 18:25 grepDir
-rw-r--r--. 1 root root  0 6月   7 23:34 myfile
drwxr-xr-x. 2 root root  6 6月   7 23:33 newWatch

From [email protected]  Wed Jun  8 17:52:01 2016
Return-Path: <[email protected]>
X-Original-To: sunjimeng
Delivered-To: [email protected]
Received: by localhost.localdomain (Postfix, from userid 0)
    id F3239632F338; Wed,  8 Jun 2016 17:52:00 -0700 (PDT)
Subject: Output from your job       14
To: [email protected]
Message-Id: <[email protected]>
Date: Wed,  8 Jun 2016 17:52:00 -0700 (PDT)
From: [email protected] (root)

I'm MenAngel

From [email protected]  Wed Jun  8 17:54:00 2016
Return-Path: <[email protected]>
X-Original-To: sunjimeng
Delivered-To: [email protected]
Received: by localhost.localdomain (Postfix, from userid 0)
    id 4B264632F338; Wed,  8 Jun 2016 17:54:00 -0700 (PDT)
Subject: Output from your job       15
To: [email protected]
Message-Id: <[email protected]>
Date: Wed,  8 Jun 2016 17:54:00 -0700 (PDT)
From: [email protected] (root)

總用量 4
drwxr-xr-x. 2 sunjimeng sunjimeng    6 5月   1 01:23 Desktop
drwxrwxr-x. 4 sunjimeng users     4096 5月  28 00:24 Document
drwxr-xr-x. 4 root      sunjimeng   48 6月   7 23:34 Documents
drwxr-xr-x. 2 sunjimeng sunjimeng    6 5月   1 01:23 Downloads
drwxrwxr-x. 2 sunjimeng sunjimeng    6 5月  17 04:55 findTextDir
drwxr-xr-x. 2 sunjimeng sunjimeng    6 5月   1 01:23 Music
drwxr-xr-x. 2 sunjimeng sunjimeng    6 5月   1 01:23 Pictures
drwxr-xr-x. 2 sunjimeng sunjimeng    6 5月   1 01:23 Public
drwxr-xr-x. 2 sunjimeng sunjimeng    6 5月   1 01:23 Templates
drwxr-xr-x. 2 sunjimeng sunjimeng    6 5月   1 01:23 Videos

From [email protected]  Wed Jun  8 17:54:00 2016
Return-Path: <[email protected]>
X-Original-To: sunjimeng
Delivered-To: [email protected]
Received: by localhost.localdomain (Postfix, from userid 0)
    id 4E5D2632F33A; Wed,  8 Jun 2016 17:54:00 -0700 (PDT)
Subject: Output from your job       16
To: [email protected]
Message-Id: <[email protected]>
Date: Wed,  8 Jun 2016 17:54:00 -0700 (PDT)
From: [email protected] (root)

總用量 0
drwxr-xr-x. 2 root root 72 5月  31 18:25 grepDir
-rw-r--r--. 1 root root  0 6月   7 23:34 myfile
drwxr-xr-x. 2 root root  6 6月   7 23:33 newWatch

6)[sunjimeng@localhost ~]$ at -c 18          根據id號查看即將要執行命令的細節

[sunjimeng@localhost ~]$ atq                      //顯示結果表明沒有即將要執行的任務
[sunjimeng@localhost ~]$ at now + 1 minutes       //新建一個要執行的任務
at> ls -l
at> <EOT>
job 18 at Wed Jun  8 18:09:00 2016
[sunjimeng@localhost ~]$ atq                      //查看
18    Wed Jun  8 18:09:00 2016 a sunjimeng
[sunjimeng@localhost ~]$ at -c 18                //根據id號查看,它的即將執行的細節
#!/bin/sh
# atrun uid=1000 gid=1000
# mail sunjimeng 0
umask 2
XDG_VTNR=1; export XDG_VTNR
SSH_AGENT_PID=3132; export SSH_AGENT_PID
XDG_SESSION_ID=2; export XDG_SESSION_ID
HOSTNAME=localhost.localdomain; export HOSTNAME
IMSETTINGS_INTEGRATE_DESKTOP=yes; export IMSETTINGS_INTEGRATE_DESKTOP
GPG_AGENT_INFO=/run/user/1000/keyring-CchymL/gpg:0:1; export GPG_AGENT_INFO
VTE_VERSION=3406; export VTE_VERSION
SHELL=/bin/bash; export SHELL
XDG_MENU_PREFIX=gnome-; export XDG_MENU_PREFIX
HISTSIZE=1000; export HISTSIZE
GJS_DEBUG_OUTPUT=stderr; export GJS_DEBUG_OUTPUT
WINDOWID=25197065; export WINDOWID
GNOME_KEYRING_CONTROL=/run/user/1000/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=0:di=38\;5\;27:ln=38\;5\;51:mh=44\;38\;5\;15:pi=40\;38\;5\;11:so=38\;5\;13:do=38\;5\;5:bd=48\;5\;232\;38\;5\;11:cd=48\;5\;232\;38\;5\;3:or=48\;5\;232\;38\;5\;9:mi=05\;48\;5\;232\;38\;5\;15:su=48\;5\;196\;38\;5\;15:sg=48\;5\;11\;38\;5\;16:ca=48\;5\;196\;38\;5\;226:tw=48\;5\;10\;38\;5\;16:ow=48\;5\;10\;38\;5\;21:st=48\;5\;21\;38\;5\;15:ex=38\;5\;34:\*.tar=38\;5\;9:\*.tgz=38\;5\;9:\*.arc=38\;5\;9:\*.arj=38\;5\;9:\*.taz=38\;5\;9:\*.lha=38\;5\;9:\*.lz4=38\;5\;9:\*.lzh=38\;5\;9:\*.lzma=38\;5\;9:\*.tlz=38\;5\;9:\*.txz=38\;5\;9:\*.tzo=38\;5\;9:\*.t7z=38\;5\;9:\*.zip=38\;5\;9:\*.z=38\;5\;9:\*.Z=38\;5\;9:\*.dz=38\;5\;9:\*.gz=38\;5\;9:\*.lrz=38\;5\;9:\*.lz=38\;5\;9:\*.lzo=38\;5\;9:\*.xz=38\;5\;9:\*.bz2=38\;5\;9:\*.bz=38\;5\;9:\*.tbz=38\;5\;9:\*.tbz2=38\;5\;9:\*.tz=38\;5\;9:\*.deb=38\;5\;9:\*.rpm=38\;5\;9:\*.jar=38\;5\;9:\*.war=38\;5\;9:\*.ear=38\;5\;9:\*.sar=38\;5\;9:\*.rar=38\;5\;9:\*.alz=38\;5\;9:\*.ace=38\;5\;9:\*.zoo=38\;5\;9:\*.cpio=38\;5\;9:\*.7z=38\;5\;9:\*.rz=38\;5\;9:\*.cab=38\;5\;9:\*.jpg=38\;5\;13:\*.jpeg=38\;5\;13:\*.gif=38\;5\;13:\*.bmp=38\;5\;13:\*.pbm=38\;5\;13:\*.pgm=38\;5\;13:\*.ppm=38\;5\;13:\*.tga=38\;5\;13:\*.xbm=38\;5\;13:\*.xpm=38\;5\;13:\*.tif=38\;5\;13:\*.tiff=38\;5\;13:\*.png=38\;5\;13:\*.svg=38\;5\;13:\*.svgz=38\;5\;13:\*.mng=38\;5\;13:\*.pcx=38\;5\;13:\*.mov=38\;5\;13:\*.mpg=38\;5\;13:\*.mpeg=38\;5\;13:\*.m2v=38\;5\;13:\*.mkv=38\;5\;13:\*.webm=38\;5\;13:\*.ogm=38\;5\;13:\*.mp4=38\;5\;13:\*.m4v=38\;5\;13:\*.mp4v=38\;5\;13:\*.vob=38\;5\;13:\*.qt=38\;5\;13:\*.nuv=38\;5\;13:\*.wmv=38\;5\;13:\*.asf=38\;5\;13:\*.rm=38\;5\;13:\*.rmvb=38\;5\;13:\*.flc=38\;5\;13:\*.avi=38\;5\;13:\*.fli=38\;5\;13:\*.flv=38\;5\;13:\*.gl=38\;5\;13:\*.dl=38\;5\;13:\*.xcf=38\;5\;13:\*.xwd=38\;5\;13:\*.yuv=38\;5\;13:\*.cgm=38\;5\;13:\*.emf=38\;5\;13:\*.axv=38\;5\;13:\*.anx=38\;5\;13:\*.ogv=38\;5\;13:\*.ogx=38\;5\;13:\*.aac=38\;5\;45:\*.au=38\;5\;45:\*.flac=38\;5\;45:\*.mid=38\;5\;45:\*.midi=38\;5\;45:\*.mka=38\;5\;45:\*.mp3=38\;5\;45:\*.mpc=38\;5\;45:\*.ogg=38\;5\;45:\*.ra=38\;5\;45:\*.wav=38\;5\;45:\*.axa=38\;5\;45:\*.oga=38\;5\;45:\*.spx=38\;5\;45:\*.xspf=38\;5\;45:; export LS_COLORS
SSH_AUTH_SOCK=/run/user/1000/keyring-CchymL/ssh; export SSH_AUTH_SOCK
SESSION_MANAGER=local/unix:@/tmp/.ICE-unix/2990,unix/unix:/tmp/.ICE-unix/2990; 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=2967; 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=2; 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=1; export WINDOWPATH
XDG_RUNTIME_DIR=/run/user/1000; 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' >&2
     exit 1
}
${SHELL:-/bin/sh} << 'marcinDELIMITER7e20521d'
ls -l

marcinDELIMITER7e20521d
[sunjimeng@localhost ~]$

7)[sunjimeng@localhost ~]$ at -d 21        取消指向執行id號為21的任務

[sunjimeng@localhost ~]$ atq
20    Wed Jun  8 18:15:00 2016 a sunjimeng
21    Wed Jun  8 18:16:00 2016 a sunjimeng
[sunjimeng@localhost ~]$ atrm 20
[sunjimeng@localhost ~]$ atq
21    Wed Jun  8 18:16:00 2016 a sunjimeng
[sunjimeng@localhost ~]$ at -d 21
[sunjimeng@localhost ~]$ atq

Copyright © Linux教程網 All Rights Reserved