linux 定时任务 crontab

定时任务:
crontab -l
crontab -e
service crond restart 重启定时任务

0 */1 * * * cd /home/wwwroot/xxx && /usr/bin/php think xxx
每小时执行一次更新矿商等级

0 1 * * * cd /home/wwwroot/xxx && /usr/bin/php think xxx
每天1点发放收益

0 3 * * 1 cd /home/wwwroot/xxx&& /usr/bin/php think xxx
每周一凌晨3点发放区块分红

30 4 * * * find /home/wwwroot/xxx/public/upload/xxx -mtime +7 -type f -name “*.png” -exec rm -rf {} ;
每天4点半定时清理二维码图片

crontab每分钟定时执行:
*/1 * * * * service mysqld restart //每隔1分钟执行一次
*/10 * * * * service mysqld restart //每隔10分钟执行一次

crontab每小时定时执行:
0 */1 * * * service mysqld restart //每1小时执行一次
0 */2 * * * service mysqld restart //每2小时执行一次

crontab每天定时执行:
0 10 * * * service mysqld restart //每天10点执行
30 19 * * * service mysqld restart //每天19点30分执行

crontab每周定时执行:
0 10 * * 1 service mysqld restart //每周一10点执行
30 17 * * 5 service mysqld restart //每周五17点30分执行

crontab每年定时执行:
0 10 1 10 * service mysqld restart //每年的10月1日10点执行
0 20 8 8 * service mysqld restart //每年的8月8日20点执行

下面解释下这条命令的含义:

30 1 * * * find /home/senter/picRoot/StritlWeb/phones -mtime +7 -type f -name “*.jpg” -exec rm -rf {} ;

30 1 * * * 表示每天凌晨1点30分执行后面的指令,也就是执行 find /home/senter/picRoot/StritlWeb/phones -mtime +7 -type f -name “*.jpg” -exec rm -rf {} ;

这是crontab的参数,可参考https://www.cnblogs.com/aminxu/p/5993769.html

find命令是在/home/senter/picRoot/StritlWeb/phones目录下进行搜索,搜索的条件是-mtime +7 -type f -name “*.jpg”

-mtime +n 表示列出在n天之前(不含n天本身)被更改过内容的文件名,这里n等于7表示列出7天前被更改过内容的文件名,

可参考:https://www.cnblogs.com/qiaopei/p/5515189.html

-type f 是find命令的参数,表示搜索的文件类型是普通文件,

可参考:https://zhidao.baidu.com/question/459432132.html

-name *.jpg“”是find命令的参数,表示以文件名的方式搜索所有以.jpg结尾的文件

-exec 表示执行后面的命令 rm -rf {}

;是格式要求没有具体含义

可参考:https://zhidao.baidu.com/question/253134515.html https://www.cnblogs.com/fjping0606/p/5670661.html
定期删除图片文件:
这命令可以用:
find /home/wwwroot/www.tpshop.com/public/upload/qrcode -mtime +7 -type f -name “*.png” -exec rm -rf {} ;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值