非交互模式直接写入crontab -e

root@centos-mysql01:~# 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

 root@centos-mysql01:~# (crontab -l;echo "*/5 * * * * /data/sh/chkrootkit_everyday.sh > /dev/null 2>&1 ") | crontab
 root@centos-mysql01:~# 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

 root@centos-mysql01:~# crontab  -l|grep -v  "monitor"|crontab  
 root@centos-mysql01:~# 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

添加多个定时任务

 root@centos-mysql01:~#  crontab -l | grep -v "dev" | crontab #删除全部定时任务
 root@centos-mysql01:~# crontab  -l
     root@centos-mysql01:~# 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

 root@centos-mysql01:~# 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         

直接写入文件

echo '*/15 * * * *  /data/sh/chkrootkit_everyday.sh ' > /var/spool/cron/root