linux基础之计划任务篇

简介

作用:计划任务主要是做一些周期性的任务,目前最主要的用途是定期备份数据。

分类

一次性调度执行at
Schedule one-time tasks with at
循环调度执行cron
Schedule recurring jobs with cron

一次性调度执行at

语法格式:at

实例:
1.设置一个定时创建用户的任务

[root@localhost ~]# at now +1min   //设定一分钟后
at> useradd zhoumengmeng    //创建zhoumengmeng用户
at> <EOT>              // ctrl+d 输入完成,提交任务
job 2 at Thu Feb 27 19:44:00 2020

2.查询任务

[root@localhost ~]# atq     //查询命令
3	Thu Feb 27 19:47:00 2020 a root   //结果

3.验证结果

[root@localhost ~]# id zhoumengmeng
uid=1000(zhoumengmeng) gid=1000(zhoumengmeng)=1000(zhoumengmeng),10(wheel)

查询出结果即可

循环调度执行cron

简介

cron的概念和crontab是不可分割的。
crontab是一个命令,常见于unix和linux的操作系统中 用于设置周期性被执行的指令
该命令从标准 输入设备读取指令,并将其存放于“crontab”文件中,以供之后读取和执行。

查看进程状态
systemctl status crond.service   
ps aux | grep crond   //查看进程状态
root       1305  0.0  0.0 126288  1692 ?        Ss   19:26   0:00 /usr/sbin/crond -n
root       3406  0.0  0.0 112732   972 pts/0    S+   19:55   0:00 grep --color=auto crond

计划任务储存位置

ls /var/spool/cron/

管理方式

1.创建计划

crontab  -e Edit jobs for the current user

2.查询计划

crontab -l List the jobs for the current user

3.删除计划

crontab -r Remove all jobs for the current users
语法格式job format

.---------------- 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
| | | | |
*****command
说明:
分 时 日 月 周 命令或脚本程序

发布了4 篇原创文章 · 获赞 29 · 访问量 4323

猜你喜欢

转载自blog.csdn.net/weixin_45508789/article/details/104543246