Linux基本操作(11)-任务计划

一、一次性调度执行:at

1、示例:
5分钟后:[root@localhost tengine-2.2.0]# at now +5min
四天后的中午:[root@localhost tengine-2.2.0]# at noon +4 days
在2021.2.1的4点[root@localhost tengine-2.2.0]# at 4;00 2021-2-1
2、例子
1)设置一个定时创建任务useradd uuuu和touch uuuu
2)chtl + D退出

[root@localhost ~]# at now +2min
at> useradd uuuu
at> touch uuuu<EOT>
job 2 at Mon Mar 29 11:42:00 2021
[root@localhost ~]# 

3)查询任务

[root@localhost ~]# atq
2	Mon Mar 29 11:42:00 2021 a root
[root@localhost ~]# 

4)验证

[root@localhost ~]# id uuuu
uid=1005(uuuu) gid=1007(uuuu) 组=1007(uuuu)
[root@localhost ~]# ls | grep uuuu
uuuu
[root@localhost ~]# 

5)报错
在这里插入图片描述

二、循环调度执行crontab

# .---------------- 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

1、创建计划:[root@localhost ~]# crontab -e
2、查询计划:[root@localhost ~]# crontab -l
3、删除计划:[root@localhost ~]# crontab -r
4、查看任务:[root@localhost ~]# ls /var/spool/cron/
5、示例:每分钟创建一次文件
1)准备脚本:

[root@localhost ~]# vim /root/1.sh
[root@localhost ~]# cat /root/1.sh
/usr/bin/touch  /root/`date +%F-%H-%M-%S`.txt
[root@localhost ~]# chmod +x /root/1.sh

2)编写任务书:

[root@localhost ~]# crontab -e
no crontab for root - using an empty one
crontab: installing new crontab
[root@localhost ~]# 

【注】任务写:* * * * * /root/1.sh**
3)查看结果:

[root@localhost ~]# ls -l /root | grep *.txt
-rw-r--r--.  1 root  root        0 3月  29 15:09 2021-03-29-15-09-01.txt
[root@localhost ~]# 
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值