deepin 定时任务(crontab)

6 篇文章 0 订阅
2 篇文章 0 订阅
说明
  • Crontab 是 deepin 中周期性的执行任务的一个守护进程。

常用命令

sudo systemctl status cron			# 查看 crontab 服务状态
sudo systemctl start cron			# 启动
sudo systemctl stop cron			# 关闭
sudo systemctl restart cron			# 重启
cron.service 服务配置
$ cat /lib/systemd/system/cron.service
[Unit]
Description=Regular background program processing daemon
Documentation=man:cron(8)
After=remote-fs.target nss-user-lookup.target

[Service]
EnvironmentFile=-/etc/default/cron
ExecStart=/usr/sbin/cron -f $EXTRA_OPTS
IgnoreSIGPIPE=false
KillMode=process
Restart=on-failure

[Install]
WantedBy=multi-user.target
crontab 任务配置
  • 自带的默认配置(/etc/crontab
    $ cat /etc/crontab
    # /etc/crontab: system-wide crontab
    # Unlike any other crontab you don't have to run the `crontab'
    # command to install the new version when you edit this file
    # and files in /etc/cron.d. These files also have username fields,
    # that none of the other crontabs do.
    
    SHELL=/bin/sh
    PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
    
    # Example of job definition:
    # .---------------- minute (0 - 59)
    # |  .------------- hour (0 - 23)
    # |  |  .---------- day of month (1 - 31)
    # |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
    # |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
    # |  |  |  |  |
    # *  *  *  *  * user-name command to be executed
    17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
    25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
    47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
    52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
    
  • crontab 配置的语法及含义
    (0-59)  小时(0-23)(1-31)(1-12) 星期(0-6) 用户	命令 	   说明
        17         * 	   * 	   * 	   * 	  root	[cmd] 	每小时的第 17 分钟以 root 用户权限执行一次 [cmd]
        25         6 	   * 	   * 	   * 	  root	[cmd] 	每天的 6:25 执行 [cmd]
        47         6 	   * 	   * 	   7 	  root	[cmd] 	每星期日的 6:47 执行 [cmd] (星期天用 07 来表示)
        52         6 	   1 	   * 	   *	  root	[cmd] 	每月1号的 6:52 执行 [cmd]
        */5        * 	   * 	   * 	   * 	  test   ls5 分钟以 test 用户权限执行 ls 命令
        30         3	  10,20 	 * 	   0 	  test   ls 	每月 10 号及 20 号的 3:30 执行 ls 命令
    15,30,45,59    * 	   * 	   * 	   * 	  test   ls 	每隔 15 分钟执行一次 ls
    
实例
  • 每小时执行 curl xxx 请求
    $ sudo vim /etc/crontab
    ......
    0 0 * * * root curl --connect-timeout 1 --max-time 1  --ignore-content-length --no-buffer  -s -G https://blog.csdn.net/javaldk/article/details/122631211
    
  • 每天 8~11 点的第05分钟执行一次 python 脚本命令
    $ sudo vim /etc/crontab
    ......
    05 8-11 * * * python /usr/local/bin/python3   /home/www/test.py
    
  • 每 10 分钟以 www 用户权限执行 php 脚本命令
    $ sudo vim /etc/crontab
    ......
    */10 * * * * www /usr/local/bin/php   /home/www/script.php
    
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值