非交互模式直接写入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
转载于:https://blog.51cto.com/9025736/2334457