• 每天一个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 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]# atq
    6    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 root@localhost.localdomain  Wed Jun  8 17:46:01 2016
    Return-Path: <root@localhost.localdomain>
    X-Original-To: sunjimeng
    Delivered-To: sunjimeng@localhost.localdomain
    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: sunjimeng@localhost.localdomain
    Message-Id: <20160609004601.24622632F338@localhost.localdomain>
    Date: Wed,  8 Jun 2016 17:46:01 -0700 (PDT)
    From: root@localhost.localdomain (root)
    
    I'm MenAngel!,I'm study at order!
    
    From root@localhost.localdomain  Wed Jun  8 17:47:00 2016
    Return-Path: <root@localhost.localdomain>
    X-Original-To: sunjimeng
    Delivered-To: sunjimeng@localhost.localdomain
    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: sunjimeng@localhost.localdomain
    Message-Id: <20160609004700.C83A5632F338@localhost.localdomain>
    Date: Wed,  8 Jun 2016 17:47:00 -0700 (PDT)
    From: root@localhost.localdomain (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 root@localhost.localdomain  Wed Jun  8 17:47:00 2016
    Return-Path: <root@localhost.localdomain>
    X-Original-To: sunjimeng
    Delivered-To: sunjimeng@localhost.localdomain
    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: sunjimeng@localhost.localdomain
    Message-Id: <20160609004700.C9EA3632F33A@localhost.localdomain>
    Date: Wed,  8 Jun 2016 17:47:00 -0700 (PDT)
    From: root@localhost.localdomain (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 root@localhost.localdomain  Wed Jun  8 17:52:01 2016
    Return-Path: <root@localhost.localdomain>
    X-Original-To: sunjimeng
    Delivered-To: sunjimeng@localhost.localdomain
    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: sunjimeng@localhost.localdomain
    Message-Id: <20160609005200.F3239632F338@localhost.localdomain>
    Date: Wed,  8 Jun 2016 17:52:00 -0700 (PDT)
    From: root@localhost.localdomain (root)
    
    I'm MenAngel
    
    From root@localhost.localdomain  Wed Jun  8 17:54:00 2016
    Return-Path: <root@localhost.localdomain>
    X-Original-To: sunjimeng
    Delivered-To: sunjimeng@localhost.localdomain
    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: sunjimeng@localhost.localdomain
    Message-Id: <20160609005400.4B264632F338@localhost.localdomain>
    Date: Wed,  8 Jun 2016 17:54:00 -0700 (PDT)
    From: root@localhost.localdomain (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 root@localhost.localdomain  Wed Jun  8 17:54:00 2016
    Return-Path: <root@localhost.localdomain>
    X-Original-To: sunjimeng
    Delivered-To: sunjimeng@localhost.localdomain
    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: sunjimeng@localhost.localdomain
    Message-Id: <20160609005400.4E5D2632F33A@localhost.localdomain>
    Date: Wed,  8 Jun 2016 17:54:00 -0700 (PDT)
    From: root@localhost.localdomain (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
  • 相关阅读:
    git warning: LF will be replaced by CRLF in 解决办法
    今天买了个pro,开始ios开发
    基于pyspark的mapreduce实现
    正则表达式中全部符号作用及解释
    CNN
    tensorboard使用及tensorflow各层权重系数输出
    DeepFM tensorflow实现
    FM详解
    sklearn计算auc需要注意的点
    矩阵压缩存储(可用于FM算法中的稀疏矩阵存储)
  • 原文地址:https://www.cnblogs.com/MenAngel/p/5571967.html
Copyright © 2020-2023  润新知