linux--crontab 定时任务

运行jar 的定时任务:
运行之前要给脚本加权限:
chmod +x ana_dim_union_voice_launcher_sumday.sh
首先写一个sh脚本,脚本中如下:
如下为运行jar 的脚本:

#!/bin/bash
#set -e: if the execution result of then instruction is not equle 0 ,then exit automatically
set -e
#set -u: if the variable to be used is not be define,you will get an error message.
set -u

java -jar /home/changhong/hanya/tencent_data.jar /home/changhong/hanya/tencent

注意:要写jar 所在位置的绝对路径 后面一个为目录的绝对路径

如下为运行sql的脚本:

#!/bin/bash
#set -e: if the execution result of then instruction is not equle 0 ,then exit automatically
set -e
#set -u: if the variable to be used is not be define,you will get an error message.
set -u
source /etc/profile.d/cust_path.sh
source ${SYS_SHELL_PATH}/shell.cfg

EXEC_SQL=${COMMON_EXEC_SQL}
report_yd=`date -d "-1 day" +%Y%m%d`

sql="
insert into ana_launcher_video(mac,portal_name,poster_name,sum_count,reportdate,sum_day)
select mac,portal_name,poster_name,sum_count,reportdate,1 from tv_launcher_p
where coalesce(poster_name,'') != '' and reportdate=${report_yd} and (portal_name='点播' or  portal_name='UMAX' or portal_name='精选' or portal_name='企鹅精选' );
"
${EXEC_SQL} -e "$sql"

脚本写完后,输入crontab -e 编辑定时任务:
如下为两个定时任务:为每天执行的任务
00 04 * * * sh /hwdata/sh/hy_work/ana_dim_launcher_video.sh
00 06 * * * sh /hwdata/sh/hy_work/ana_tencent_data_movie.sh
格式为:
*  *  *  *  *  command
分 时 日 月 周 命令
第1列表示分钟1~59 每分钟用或者 /1表示
第2列表示小时1~23(0表示0点)
第3列表示日期1~31
第4列表示月份1~12
第5列标识号星期0~6(0表示星期天)
第6列要运行的命令

输入crontab -l 为查看有哪些定时任务

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值