非交互模式直接写入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
原文地址:http://blog.51cto.com/9025736/2334457
时间: 2024-11-09 03:01:40