`

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 {} \;

 

 

 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics