lsyf8 发表于 2019-2-17 12:20:15

linux cron

  计划任务主要是作一些周期性的任务,目前最主要的用途是备份数据
  # ps aux |grep cron |grep -v 'grep'
  root      30780.00.0   56321108 ?      Ss   08:44   0:00 crond
  # chkconfig crond --list
  crond         0:关闭1:关闭2:启用3:启用4:启用5:启用6:关闭
  crond进程每分钟检查一次,以运行相应的任务
  crond日志文件/var/log/cron
  ==系统级的计划任务
  更新whatis数据库,日志轮转,/tmp,/var/tmp清理
  # vim /etc/crontab
  01 * * * * root run-parts /etc/cron.hourly   //run-parts 后面是目录
  02 4 * * * root run-parts /etc/cron.daily
  22 4 * * 0 root run-parts /etc/cron.weekly
  42 4 1 * * root run-parts /etc/cron.monthly
  # ls /etc/cron.hourly/
  # ls /etc/cron.daily/   //下面都是一些脚本程序
  0anacron   cups       makewhatis.cronprelinkrpm
  0logwatchlogrotatemlocate.cron   rhsmd    tmpwatch
  # ls /etc/cron.weekly/
  0anacron99-raid-checkmakewhatis.cron
  # ls /etc/cron.monthly/
  0anacron
  =============用户级的计划任务==========
  # crontab -e//创建计划任务
  * * * * * /bin/ls
  # crontab -l//查看计划任务
  * * * * * /bin/ls
  # ls /var/spool/cron/
  root
  # cat /var/spool/cron/root
  * * * * * /bin/ls
  时间表:
  *       *   *   *   *
  分时 日 月 周
  0-590-231-311-12 1-70,7表示周日
  00 02 * * * ls//每天2:00整
  00 02 1 * * ls//每月1号2:00整
  00 02 14 2 * ls//每年2月14号2:00整
  00 02 * * 7 ls//每周日2:00整
  00 02 14 2 7 ls //每年2月14号2:00整或者每周日2:00整,这两个时间都执行
  ===============================================================
  00 02 * * * ls//每天2:00整
  * 02 * * * ls//每天2:00中的每一分钟
  * * * * * ls//每分钟执行ls
  * * 14 2 * ls//2月14号的每分钟
  ===============================================================
  */5 * * * * ls//每隔5分钟
  00 02 1,5,8 * * ls//每月1,5,8号的2:00整
  00 02 1-8 * * ls//每月1到8号的2:00整
  # tail /var/log/cron    //查看日志
  0 2 * * * touch /home/`date +%F`-file    失败的,最好把命令放到脚本中,减少出错率



页: [1]
查看完整版本: linux cron