Linux计划任务服务学习

Linux计划任务服务学习

我们可能有些事需要定时操作,比如备份、重启等等,我们将其做成任务计划,让系统到点自动执行

命令

  1. at
  2. crontab

1.1 at 在23:30分执行重启http服务

[root@linuxprobe ~]# at 23:30
at > systemctl restart httpd
at > 此处请同时按下Ctrl+d来结束编写计划任务
job 3 at Mon Apr 27 23:30:00 2015
[root@linuxprobe ~]# at -l     # 查看任务列表
3 Mon Apr 27 23:30:00 2016 a root

1.2. 利用管道符设置任务

[root@linuxprobe ~]# echo "systemctl restart httpd" | at 23:30
job 4 at Mon Apr 27 23:30:00 2015
[root@linuxprobe ~]# at -l
3 Mon Apr 27 23:30:00 2016 a root
4 Mon Apr 27 23:30:00 2016 a root

1.3 删除任务,可根据第一列的任务id去删除任务列表

[root@linuxprobe ~]# atrm 3
[root@linuxprobe ~]# at -l
4 Mon Apr 27 23:30:00 2016 a root

2.1 crontab -e 进入任务列表编辑,跟普通文本文件编辑一样,格式是分时日月星期任务,下面这个例子就是每天16点19分打包/root

19 16 * * * /usr/bin/tar -czvf test.tar.gz /root

Linux计划任务服务学习_第1张图片

你可能感兴趣的:(Linux,Linux计划任务服务设置)