运行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 为查看有哪些定时任务