linux--crontab 定时任务

来源:互联网 发布:淘宝虚拟宝贝的类目 编辑:程序博客网 时间:2024/06/04 19:03

运行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 automaticallyset -e#set -u: if the variable to be used is not be define,you will get an error message.set -ujava -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 automaticallyset -e#set -u: if the variable to be used is not be define,you will get an error message.set -usource /etc/profile.d/cust_path.shsource ${SYS_SHELL_PATH}/shell.cfgEXEC_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_pwhere 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 为查看有哪些定时任务

原创粉丝点击