2022-11-18小白笔记0

目录

Cron 管理周期性重复执行的作业任务调度
anacron
at
配置at
atq 查询任务
atrm 删除任务

Cron 管理周期性重复执行的作业任务调度

默认开机自启动
etc/crontab配置文件

bash
root@momen-PC:~# 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:
# .---------------- 分钟 (0 - 59)
# |  .------------- 小时 (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- 月份 (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 )
#
*/5 * * * * root flock -xn "/var/log/oneav/cron.lock" -c '/opt/threatbook/OneAV/oneav/script/install/oneav_service_monitor.sh'

通配符 * :表示取值范围中的任意值
连字符 - :表示数值区间
逗号 , :分割多个字符
斜线 /:代表每,*/3表示每3个月 ,0-59/5表示每5分钟
例:
2 * * * 每小时的2分钟
30 7 * * * 每天7:30
30 20 * * 2 每周二下午8:30
30 7 3-6 * * 每个月3-6号 7:30
30 7 3,6 * * 每个月3号6号 7:30

cron.d/
cron.daily/
cron.hourly/
cron.monthly/
cron.weekly/
脚本不能包含后缀
-----没写完----

anacron

at

使用at在指定时间内调度一次性任务。

配置at

at [时间参数]

bash
root@momen-PC:~# at now+1 minutes
warning: commands will be executed using /bin/sh
at> date > ~/date.log
at> ~tcp.sh
at> <EOT>
job 1 at Fri Dec  2 10:29:00 2022

atq 查询任务

bash
root@momen-PC:~# atq
1       Fri Dec  2 10:29:00 2022 a root

atrm 删除任务

atrm [atq号]

batch

本文作者:墨洺的文档

本文链接:

版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!