Time: 2017.9.19
在服務(wù)器上部署定時(shí)任務(wù)看杭,使用crontab命令楼雹,即Cron配置文件稱為“crontab”,是“cron table”的簡(jiǎn)寫(xiě)介却。
將可執(zhí)行的jar包桂肌,復(fù)制到bin文件夾。
cp workspace/user-profile/processor/profile/target/profile-1.1.1-jar-with-dependencies.jar bin/profile-1.1.1-jar-with-dependencies.jar
顯示定時(shí)任務(wù)的文件谭跨,可編輯蛮瞄。
crontab -e
參考裕坊,示例:
20 5 * * * /usr/bin/sh /home/hadoop/scripts/cal_user_service.sh >> /home/hadoop/scripts/log/cal_user_service_daily.log 2>&1
格式:[minute] [hour] [day-of-month] [month-of-year] [day-of-week] commands
合法值:00-59 00-23 01-31 01-12 0-6 (0 is sunday)
cal_user_service.sh
腳本:
#!/bin/sh
. /etc/profile
. ~/.bash_profile
cd /home/hadoop/scripts;
/usr/bin/hadoop jar ./profile-1.1.1-jar-with-dependencies.jar me.chunyu.analysis.CyUserServicesCalculation 1
新腳本exec_user_time.sh
:
#!/bin/sh
. /etc/profile
. ~/.bash_profile
cd /home/hadoop/wangchenlong/bin/
/usr/bin/hadoop jar ./profile-1.1.1-jar-with-dependencies.jar me.chunyu.log_analysis.Main -m hv -da
在crontab -e
中周瞎,添加新定時(shí)任務(wù)酱讶,每日4點(diǎn)10分執(zhí)行一次泻肯。
10 4 * * * /usr/bin/sh /home/hadoop/scripts/exec_user_time.sh >> /home/hadoop/scripts/log/exec_user_time.log 2>&1