crontab

编写定时任务

crontab -e

 

# Example of job definition:

# .---------------- minute (0 - 59)

# | .------------- hour (0 - 23)

# | | .---------- day of month (1 - 31)

# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...

# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat

# | | | | |

# * * * * * user-name command to be executed

 

每小时的第1分钟执行该脚本

1 * * * * sh /home/hadoop/test.sh

 

每1分钟执行该脚本

*/1 * * * * sh /home/hadoop/test.sh

 

每天的1点执行该脚本

0 1 * * * sh /home/hadoop/test.sh

 

每周日的1点1分执行该脚本

1 1 * * 0 sh /home/hadoop/test.sh

 

每月第1天的1点1分进行脚本的执行

1 1 1 * * sh /home/hadoop/test.sh

 

每个周一到周三的早上10点执行该脚本

0 10 * * 1-3 sh /home/hadoop/test.sh

 

每周的周一、周三、周五的早上10点执行该脚本

0 10 * * 1,3,5 sh /home/hadoop/test.sh

test.sh

#!/bin/sh
dateformat=`date +"%Y%m%d%H%M%S"`
echo "Hello World" >> /home/hadoop/test/log/test_${dateformat}.log

 

每天定时清理7天前的日志

10 1 * * * sh /home/hadoop/test/auto_del_7_days_ago_log.sh
auto_del_7_days_ago_log.sh
#!/bin/sh
find /home/hadoop/test/log -mtime +7 -name "test_*.log" -exec rm -rf {} \;

 

 

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值