zoukankan      html  css  js  c++  java
  • 周期性计划(一个cron守护进程):

    周期性计划(一个cron守护进程):
    root@ubuntu:/etc# ps -ef | grep cron
    root        903      1  0 16:25 ?        00:00:00 /usr/sbin/cron -f
    root      16162   6459  0 22:08 pts/1    00:00:00 grep --color=auto cron
    
    cron是一个可以根据时间,日期,月份,星期的组合的周期性执行的守护进程。
    
    (可以停掉和重启)
    root@ubuntu:/etc# service cron stop
    root@ubuntu:/etc# ps -ef | grep cron
    root      16212   6459  0 22:09 pts/1    00:00:00 grep --color=auto cron
    root@ubuntu:/etc# service cron start
    root@ubuntu:/etc# ps -ef | grep cron
    root      16252      1  3 22:09 ?        00:00:00 /usr/sbin/cron -f
    root      16263   6459  0 22:09 pts/1    00:00:00 grep --color=auto cron
    
    (不同模式下是否启动)
    root@ubuntu:/# service cron status  
    ● cron.service - Regular background program processing daemon
       Loaded: loaded (/lib/systemd/system/cron.service; enabled; vendor preset: ena
       Active: active (running) since 四 2018-02-15 22:09:54 PST; 17min ago
         Docs: man:cron(8)
     Main PID: 16252 (cron)
        Tasks: 1
       Memory: 1.1M
          CPU: 30ms
       CGroup: /system.slice/cron.service
               └─16252 /usr/sbin/cron -f
    
    
    root@ubuntu:/# sysv-rc-conf --list cron
    cron         2:on    3:on    4:on    5:on

    *表示不存在这个时间(0和7表示星期天)。1月2号3点50分去执行某个程序。这个时间取自于当前操作系统。

    root@ubuntu:/# crontab -l   (查看时间计划)
    no crontab for root   (root账号没有可执行的时间计划任务)
    root@ubuntu:/# crontab -e   (调用文本编辑,编辑时间计划)
    */1 * * * * echo "yowen" >> /yw/cron.txt   (每分钟打印一个输出)
    root@ubuntu:/# crontab -l    (有一个时间计划)ls
    1 * * * * echo "yowen" >> /yw/cron.txt
    root@ubuntu:/# service cron reload   (重启守护进程cron)
     * Reloading configuration files for periodic command scheduler cron     [ OK ] 
    root@ubuntu:/yw# service cron restart
    
    (创建2个账号)
    root@ubuntu:/yw# useradd zhangsan
    root@ubuntu:/yw# useradd lisi
    root@ubuntu:/yw# passwd zhangsan
    Enter new UNIX password: 
    Retype new UNIX password: 
    passwd: password updated successfully
    root@ubuntu:/yw# passwd lisi
    Enter new UNIX password: 
    Retype new UNIX password: 
    passwd: password updated successfully
    
    root@ubuntu:/# crontab -r  (删除任务)
    root@ubuntu:/yw# service cron restart (删除任务,也要重启)
    
    root@ubuntu:/etc# vim cron.deny   (账号zhangsan就不能使用cron定时任务)
    zhangsan
    yw1989@ubuntu:~$ su - zhangsan
    Password: 
    No directory, logging in with HOME=/
    $ crontab
    You (zhangsan) are not allowed to use this program (crontab)
    See crontab(1) fo

    cron主要在于时间的设置和用户级别的控制。

  • 相关阅读:
    3.10 Go Map哈希表
    3.9 Go Slice切片
    3.8 Go Array数组
    3.7 Go指针
    3.6 Go String型
    3.5 Go布尔型
    3.4 Go字符型
    3.3 Go浮点型
    3.2 Go整数类型
    3.1Go变量
  • 原文地址:https://www.cnblogs.com/yaowen/p/8450255.html
Copyright © 2011-2022 走看看