linux定时任务crond服务
ps:本人亲测,阿里云2核4G5M的服务器性价比很高,新用户一块多一天,老用户三块多一天,最高可以买三年,感兴趣的可以戳一下:阿里云折扣服务器
1、crontab -e //编辑某个用户的cron服务
2、crontab -l //列出某个用户cron服务的详细内容
3、crontab -r //删除每个用户的cron服务
4、crontab定时任务格式:
分 小时 日 月 星期 命令
* * * * * *
0-59 0-23 1-31 1-12 0-6 command
例子:
(1)*/1 * * * * php /data/www/cron.php 意思是每分钟执行cron.php
(2)50 7 * * * /sbin/service sshd start 意思是每天7:50开启ssh服务
5、直接在linux中执行一个php程序:/usr/bin/php cron.php
6、crontab的最小执行单位是分钟,那么如何精确到毫秒级的定时任务呢?:用php的sleep来实现
1、在编辑cron服务时,编辑的内容有一些格式和约定,输入:crontab -u root -e 进入vi编辑模式,编辑的内容一定要符合下面的格式:
*/1 * * * * ls >> /tmp/ls.txt
2、cron的系统级配置文件位于/etc/crontab。
01 * * * * root run-parts /etc/cron.hourly //每小时执行/etc/cron.hourly内的脚本
3、定时脚本里有curl时候,curl要带参数,则URL需要用双引号引起来,或者使用curl -d "a=1&b=2" "http://www.baidu.com" 的形式形如:
*/10 * * * * curl "http://crontab.rantonet.com/index.php?act=hs_activity_status&op=getHsCouponState" >> /data/logs/crontab/getHsCouponState.log
# 执行频率:每天凌晨2点
10 2 * * * curl "http://crontab.rantonet.com/index.php?act=hs_activity_status&op=getReHsCoupon" >> /data/logs/crontab/getReHsCoupon.log