1. 程式人生 > >非互動模式寫入crontab -e

非互動模式寫入crontab -e

非互動模式直接寫入crontab -e

[email protected]:~# crontab  -l
*/5 * * * *  chkrootkit_everyday.sh > dev/null 2>&1
*/20 * * * * /usr/sbin/ntpdate pool.ntp.org > /dev/null 2>&1
* * * * * /usr/bin/php /data/monitor/artisan schedule:run > /dev/null 2>&1

新增一個/5 * /data/sh/chkrootkit_everyday.sh > /dev/null 2>&1

 [email protected]:~# (crontab -l;echo "*/5 * * * * /data/sh/chkrootkit_everyday.sh > /dev/null 2>&1 ") | crontab
 [email protected]:~# crontab  -l
      */5 * * * *  chkrootkit_everyday.sh > dev/null 2>&1
      */20 * * * * /usr/sbin/ntpdate pool.ntp.org > /dev/null 2>&1
      * * * * * /usr/bin/php /data/monitor/artisan schedule:run > /dev/null 2>&1
      */5 * * * * /data/sh/chkrootkit_everyday.sh > /dev/null 2>&1 

刪除一個crontab

 [email protected]:~# crontab  -l|grep -v  "monitor"|crontab  
 [email protected]:~# crontab  -l
    */5 * * * *  chkrootkit_everyday.sh > dev/null 2>&1
    */20 * * * * /usr/sbin/ntpdate pool.ntp.org > /dev/null 2>&1
    */5 * * * * /data/sh/chkrootkit_everyday.sh > /dev/null 2>&1

新增多個定時任務

 [email protected]:~#  crontab -l | grep -v "dev" | crontab #刪除全部定時任務
 [email protected]:~# crontab  -l
     [email protected]:~# crontab -l;echo "*/5 * * * * /data/sh/chkrootkit_everyday.sh > /dev/null 2>&1
      > */20 * * * * /usr/sbin/ntpdate pool.ntp.org > /dev/null 2>&1
      > */5 * * * * /data/sh/chkrootkit_everyday.sh > /dev/null 2>&1"|crontab

 [email protected]:~# crontab  -l
     */5 * * * * /data/sh/chkrootkit_everyday.sh > /dev/null 2>&1
     */20 * * * * /usr/sbin/ntpdate pool.ntp.org > /dev/null 2>&1
     */5 * * * * /data/sh/chkrootkit_everyday.sh > /dev/null 2>&1