今天练习下任务计划
* * * * *
分别代表:分钟,时,日,月,周
------------------------------------------------------------------------------------------------------
1.root用户的任务计划
[root@CentOS-5 ~]# crontab -e --默认是root用户
*/1 * * * * echo "hello girl" --echo的内容会在mail里输出
*/1 * * * * . /root/test.sh
"/tmp/crontab.XXXXqf1ZtY" 2L, 58C written
crontab: installing new crontab
[root@CentOS-5 ~]# pwd
/root
[root@CentOS-5 ~]# vim test.sh
echo "This is xiaobudian's test file!"
[root@CentOS-5 ~]# service crond restart
[root@CentOS-5 ~]# chmod a+x test.sh
[root@CentOS-5 ~]# mail
Mail version 8.1 6/6/93. Type ? for help.
"/var/spool/mail/root": 14 messages 12 new 14 unread
U 1
[email protected] Thu May 17 05:18 24/852 "Cron <root@CentOS-5> echo "hello girl""
U 2
[email protected] Thu May 17 05:19 24/852 "Cron <root@CentOS-5> echo "hello girl""
>N 3
[email protected] Thu May 17 05:20 23/842 "Cron <root@CentOS-5> echo "hello girl""
N 4
[email protected] Thu May 17 05:21 23/842 "Cron <root@CentOS-5> echo "hello girl""
& 5
Message 5:
Date: Thu, 17 May 2012 05:22:01 +0800
Subject: Cron <root@CentOS-5> . /root/test.sh
Content-Type: text/plain; charset=ANSI_X3.4-1968
Auto-Submitted: auto-generated
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>
X-Cron-Env: <USER=root>
This is xiaobudian's test file!
&
------------------------------------------------------------------------------------------------------
2.指定用户的任务计划
[root@CentOS-5 ~]# crontab -e -u user1
no crontab for user1 - using an empty one
*/1 * * * * echo "this is user1's crontab."
[root@CentOS-5 ~]# service crond restart
[root@CentOS-5 ~]# su - user1
[user1@CentOS-5 ~]$ mail
Mail version 8.1 6/6/93. Type ? for help.
"/var/spool/mail/user1": 2 messages 2 new
>N 1
[email protected] Thu May 17 05:32 23/884 "Cron <user1@CentOS-5> echo "this is user1's crontab.""
N 2
[email protected] Thu May 17 05:33 23/884 "Cron <user1@CentOS-5> echo "this is user1's crontab.""
&
------------------------------------------------------------------------------------------------------
3.取消用户制定的任务计划
[root@CentOS-5 ~]# vim /etc/cron.deny
user1
[root@CentOS-5 ~]# su - user1
[user1@CentOS-5 ~]$ crontab -e
You (user1) are not allowed to use this program (crontab)
See crontab(1) for more information
[user1@CentOS-5 ~]$
------------------------------------------------------------------------------------------------------