zoukankan      html  css  js  c++  java
  • linux计划任务(一)

    一次性计划任务 at /etc/init.d/atd

    [root@localhost ~]# at 22:18
    at> /bin/ls /etc |wc -l > /tmp/yimiao_demo.txt #ctrl+d提交计划任务,执行的命令用绝对路径,避免产生错误,可用which查看
    at> <EOT>
    job 1 at 2014-08-17 22:18
    [root@localhost ~]# ls /var/spool/at
    a000010166253a  spool
    [root@localhost ~]# atq #一次性计划任务的查询和删除 act -c 5:具体查看某个计划任务内容
    5       2014-08-17 22:30 a root
    [root@localhost ~]# atrm 5
    [root@localhost ~]# atq

     创建完的at任务会在/var/spool/at/下面产生一个job文件

    周期性计划任务 crontab /etc/init.d/crond  

    执行周期  

    *  *   *  *  *

    分  时  天  月  周【0-7代表周一到周日,0或7代表周日】

    【,表示不连续的时间;-表示连续的时间;*匹配任意时间;/n表示频率,每n】

    执行示例

      -  0 17 * * 1-5  周一到周围每天的17点

      -  30 8 * * 1,3,5  每周1/3/5的8点30分

      -  0 8-18/2 * * *  8点-18点每2小时

      -  0 * */3 * *  每3天

      

     实验【计划任务设置shhd服务开启关闭】

    1.检查sshd,crond是系统服务还是临时服务,检查crond服务目前是否开启

    [root@localhost /]# chkconfig --list sshd
    sshd            0:关闭  1:关闭  2:启用  3:启用  4:启用  5:启用  6:关闭
    [root@localhost /]# chkconfig --list crond
    crond           0:关闭  1:关闭  2:启用  3:启用  4:启用  5:启用  6:关闭
    [root@localhost /]# /etc/init.d/crond status
    crond (pid  3202) 正在运行...
    [root@localhost /]# crontab -e #[-u 用户,默认是当前用户]

    2.查看创建的计划任务

    crontab: installing new crontab
    [root@localhost /]# crontab -l
    30 07 * * * /etc/init.d/sshd start
    30 23 * * * /etc/init.d/sshd stop
    [root@localhost /]# cat /var/spool/cron/root
    30 07 * * * /etc/init.d/sshd start
    30 23 * * * /etc/init.d/sshd stop

    3.删除创建的计划任务

    [root@localhost /]# crontab -r #如果只是删除一个,crontab -e 进入删除对应行
    [root@localhost /]# crontab -l
    no crontab for root

     【实验二:打包rpm包】

    [root@localhost ~]# tar -zcvf rpmlib$(date +%Y%m%d).tar.gz /var/lib/rpm/ #$(命令)获得命令执行后的屏幕输出
  • 相关阅读:
    买房的贷款时间是否是越长越好?https://www.zhihu.com/question/20842791
    asp.net cookie and session
    leelazero and google colab
    download file by python in google colab
    physical processor, core, logical processor
    通过powershell操作eventlog
    openxml in sql server
    get the page name from url
    How to Execute Page_Load() in Page's Base Class?
    Difference between HttpContext.Request and Request
  • 原文地址:https://www.cnblogs.com/yimiao/p/3917717.html
Copyright © 2011-2022 走看看