标签:
使用at和cron做计划任务
at执行一次
[root@sky ~]# atq [root@sky ~]# at 00:25 at> cal >> /tmp/test-at.txt at> date /tmp/test-at.txt at> <EOT> job 10 at Sun Nov 29 00:25:00 2015 [root@sky ~]# atq 10 Sun Nov 29 00:25:00 2015 a root [root@sky ~]# at -c 10 | tail -6 } ${SHELL:-/bin/sh} << ‘marcinDELIMITER25c3ebf4‘ cal >> /tmp/test-at.txt date /tmp/test-at.txt marcinDELIMITER25c3ebf4 [root@sky ~]# [root@sky ~]# at -q g teatime tomorrow at> cal >> /tmp/test-at.txt at> <EOT> job 11 at Mon Nov 30 16:00:00 2015 [root@sky ~]# at -q g 17:00 tomorrow at> cal >> /tmp/test-at.txt at> <EOT> job 12 at Mon Nov 30 17:00:00 2015 [root@sky ~]# at -q b 17:00 tomorrow at> cal >> /tmp/test-at.txt at> <EOT> job 13 at Mon Nov 30 17:00:00 2015 [root@sky ~]# atq 10 Sun Nov 29 00:25:00 2015 a root 11 Mon Nov 30 16:00:00 2015 g root 12 Mon Nov 30 17:00:00 2015 g root 13 Mon Nov 30 17:00:00 2015 b root [root@sky ~]# atrm 12 您在 /var/spool/mail/root 中有新邮件 [root@sky ~]# atq 10 Sun Nov 29 00:25:00 2015 a root
11 Mon Nov 30 16:00:00 2015 g root 13 Mon Nov 30 17:00:00 2015 b root [root@sky ~]#
[root@sky /]# echo "cal >> /tmp/test-at.txt" | at 01:38
job 14 at Sun Nov 29 01:38:00 2015
[root@sky /]# atq
11 Mon Nov 30 16:00:00 2015 g root
13 Mon Nov 30 17:00:00 2015 b root
14 Sun Nov 29 01:38:00 2015 a root
[root@sky /]#
使用cron安排可循环的计划任务
[root@sky /]# which tar
/bin/tar
[root@sky /]# which bash
/bin/bash
[root@sky /]# cat 1.sh
#!/bin/bash
a=`date +%Y%m%d`
/bin/tar -zPcf /$a.tar.gz /var/log/*
[root@sky /]# crontab -l
35 00 29 11 * /bin/date >> /time.txt (11月29日0点35分执行)
35 00 1-5 11 * /bin/date >> /time.txt (11月1号到5号0点35分执行)
*/1 * * * * /bin/date >> /time.txt (每隔一分钟执行一次)
27 01 * * 1,3,5 /bin/bash /1.sh (每周1、3、5的1点27分执行一次1.sh脚本)
[root@sky/]#
标签:
原文地址:http://www.cnblogs.com/skyfly0772/p/5003929.html