Linux配置定時,使用 crontab,linux配置crontab

來源:互聯網
上載者:User

Linux配置定時,使用 crontab,linux配置crontab


Linux配置定時任務,大家都知道使用crontab這個系統功能,但有時候我們需要區分使用者執行,下面就直接說一下2種方法的區別:

方法1:

使用命令 crontab -e 然後直接編輯定時指令碼。

這樣執行以後,屬於使用者自訂的,會被寫到 /var/spool/cron 目錄下,產生一個和使用者名稱一致的檔案,檔案內容就是我們編輯的定時指令碼。

如:

[root@localhost cron.d]# cd /var/spool/cron[root@localhost cron]# ll總用量 4-rw-------. 1 root root 52 12月  9 10:58 root[root@localhost cron]# pwd/var/spool/cron[root@localhost cron]# cat root 30 03 * * * /root/automysqlbackup.sh

方法2:

使用命令 vi /etc/crontab 編輯定時指令碼。

如:

[root@localhost ~]# cat /etc/crontab                                                                                                                                                                      SHELL=/bin/bash                                                                                                                                                                                           PATH=/sbin:/bin:/usr/sbin:/usr/bin                                                                                                                                                                        MAILTO=root                                                                                                                                                                                               HOME=/                                                                                                                                                                                                                                                                                                                                                                                                              # run-parts                                                                                                                                                                                               30 * * * * root /usr/sbin/ntpdate 210.72.145.44                                                                                                                                                           #30 8 * * * root /usr/sbin/ntpdate 132.228.90.101                                                                                                                                                         01 * * * * root run-parts /etc/cron.hourly                                                                                                                                                                02 4 * * * root run-parts /etc/cron.daily                                                                                                                                                                 22 4 * * 0 root run-parts /etc/cron.weekly                                                                                                                                                                42 4 1 * * root run-parts /etc/cron.monthly                                                                                                                                                               */1 * * * * root run-parts /opt/openoffice.org3/program/start.sh                                                                                                                                          ############################################                                                                                                                                                                                                                                                                                                                                                                        30 4 * * * root /usr/bin/rsync -vzrtopg --progress --delete root@192.168.231.35::resource /hyy/bak/resource 30 4 * * * root /usr/bin/rsync -vzrtopg --progress --delete root@192.168.231.35::log /hyy/bak/log############################################[root@localhost ~]# 


(系統級的)做系統級配置我們會直接配置 /etc/crontab

(使用者級的)一般還是建議大家使用 crontab -e ,這樣系統也會幫著檢查我們配置的指令碼文法。




聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.