一、定義:
定時執行任務
二、格式
1. 使用 student,檢查自己的週期性計畫任務,現在是空的
[student@desktop1 ~]$ crontab -l2. 使用crontab-e,編輯student自己的週期進化任務 ,每分鐘向/home/student/cron 中追加 date 命令的輸出結果no crontab
for student
[student@desktop1 ~]$ crontab -e* * * * * echo $(date) >> /home/student/cron.txt
no crontab3. 用 crontab -l 確認計畫任務的配置for student - using
an empty one
crontab: installing
new crontab
[student@desktop1 ~]$ crontab -l4. 用 tail -f 命令,觀察/home/student/cron.txt,確認計畫任務是正常工作的* * * * * echo $(date) >> /home/student/cron.txt
[student@desktop1 ~]$ tail -f /home/student/cron.txt5. 用 crontab -e,編輯 student 自己的計畫任務,每 2 分鐘,向/home/student/cron.txt 追加 hello 字串thu nov
316:36:01 cst 2016
thu nov
316:37:01 cst 2016
thu nov
316:38:01 cst 2016
thu nov
316:39:01 cst 2016
...
[student@desktop1 ~]$ crontab -e6. student 使用者,將 crontab -l 的輸出結果重定向到/homt/student/mycrontab.cfg 文 件中*/2 * * * * echo hello >> /home/student/cron.txt
[student@desktop1 ~]$ crontab -l >> ~/mycrontab.cfg7.student 刪除自己的所有週期性計畫任務
[student@desktop1 ~]$ crontab -r8. student 使用者用~/mycrontab.cfg 檔案中的配置資訊重新建立自己的計畫任務[student@desktop1 ~]$ crontab -l
no crontab
forstudent
[student@desktop1 ~]$
[student@desktop1 ~]$ crontab ~/mycrontab.cfg
[student@desktop1 ~]$ crontab -l
* * * * * echo $(date) >> /home/student/cron.txt
*/2 * * * * echo hello >> /home/student/cron.txt
9. 切換到 root 使用者,觀察/var/spool/cron/student,會看到 student 的計畫任務
[root@desktop1 desktop]# cat /var/spool/cron/student10. root 使用者編輯自己的計畫任務,每月 1 日、11 日、21 日、31 日或者星期日,每分鐘向 /root/cron.txt 追加一次 date 命令的輸出結果* * * * * echo $(date) >> /home/student/cron.txt
*/2 * * * * echo hello >> /home/student/cron.txt
[root@desktop1 desktop]# crontab -e* * 1,11,21,31 * 0 date >> /root/cron.txt
no crontab11. 觀察/var/spool/cron/root ,看到 root 使用者的計畫任務for root - using
an empty one
crontab: installing
new crontab
[root@desktop1 desktop]# cat /var/spool/cron/root12. 用root使用者刪除student使用者的所有週期性計畫任務,並確認* * 1,11,21,31 * 0 date >> /root/cron.txt
[root@desktop1 desktop]# crontab -r -u student另外每天晚上八點,以student身份,更新/home/student/time這個檔案的 時間戳[root@desktop1 desktop]# crontab -l -u student
no crontab
forstudent
[root@desktop1 desktop]#
[root@desktop1 desktop]# vim /etc/crontabshell=/bin/bash
path=/sbin:/bin:/usr/sbin:/usr/bin
mailto=root
# for details see man
4crontabs
# example of job definition:
# .---------------- 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
# | | | | |# * * * * * user-name command to be executed
5923 * * * root rm -rf /tmp
* 20 * * * student touch /home/student/time
配置週期性計畫任務
一 定義 定時執行任務 二 格式 1.使用 student,檢查自己的週期性計畫任務,現在是空的 student desktop1 crontab l no crontab for student 2.使用crontab e,編輯student自己的週期進化任務 每分鐘向 home student ...
週期性計畫任務
週期性計畫任務 軟體 cronie crontabs crond 日誌檔案 var log cron 分 時 日 月 周 任意命令 絕對路徑 30 8 每天8 30 30 23 5 每週五23 30 任意範圍 分割多個不連續的時間點 1,3,5 指定連續的時間範圍 1 5 n 指定時間頻率,每n.2...
週期性計畫任務 cron
檢視 crontab l u 使用者名稱 清除 crontab r u 使用者名稱 執行週期 配置說明 分鐘從0到59之間的整數 小時從0到23之間的整數 日期從1到31之間的整數 月份從1到12之間的整數 星期0 7之間的整數,0或7代表星期日 符號 含義 匹配範圍內任意時間 分割多個不連續的時間...