服务器部署定时任务 Crontab

Time: 2017.9.19

在服务器上部署定时任务,使用crontab命令,即Cron配置文件称为“crontab”,是“cron table”的简写。

Crontab

将可执行的jar包,复制到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

显示定时任务的文件,可编辑。

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中,添加新定时任务,每日4点10分执行一次。

10 4 * * *  /usr/bin/sh /home/hadoop/scripts/exec_user_time.sh >> /home/hadoop/scripts/log/exec_user_time.log 2>&1
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Linux定时任务Crontab命令详解 linux 系统则是由 cron (crond) 这个系统服务来控制的。...
    孙燕超阅读 5,805评论 0 4
  • Linux定时任务Crontab命令详解linux 系统则是由 cron (crond) 这个系统服务来控制的。L...
    时待吾阅读 3,089评论 0 0
  • 前一天学习了 at 命令是针对仅运行一次的任务,循环运行的例行性计划任务,linux系统则是由 cron (cro...
    Zcclucky阅读 3,669评论 0 0
  • Linux 系统提供了使用者控制计划任务的命令 :crontab 命令。 一、crond简介 crond是linu...
    happeace阅读 5,774评论 0 53
  • 今天听广播,易效能叶武斌说他儿子2岁就可以认2000个汉字,得意于她妻子是搞教育的,每天给他做纸卡识字!没件事重复...
    天上人间续阅读 1,477评论 0 0

友情链接更多精彩内容