Linux上定时shell脚本

原文链接:http://www.92coder.com/9-Linux%E5%AE%9A%E6%97%B6shell%E8%84%9A%E6%9C%AC/#more

本文主要介绍在Linux系统上部署定时器,定时执行shell脚本,通过脚本执行sql文件

sql文件

1-- 创建表 2create table if not exists iot_test.iot_tac 3( 4MSISDN string, 5TAC string 6) 7partitioned by(day string) 8row format delimited 9fields terminated by '\t' 10lines terminated by '\n' 11stored as parquet; 12 13--录入数据 14set hive.exec.dynamic.partition.mode=nonstrict; 15insert overwrite table iot_test.iot_tac 16partition(day='${hivevar:day}') 17select t4.MSISDN,t4.TAC 18from 19(select t1.MSISDN,t1.TAC from 20(select MSISDN,substr(IMEI,1,8) as TAC,row_number()over(partition by MSISDN) as rn 21from prestat.iot_activeuser_hour 22where day='${hivevar:day}' and minute='${hivevar:minute}' and IMEI is not null) as t1 23left join 24(select MSISDN,TAC from iot_test.iot_tac where day='${hivevar:lmonth}') as t2 25on t1.MSISDN = t2.MSISDN 26where t2.MSISDN is null and t1.rn = 1 27union all 28select MSISDN,TAC 29from iot_test.iot_tac 30where day='${hivevar:lmonth}' 31) as t4;
  • ${hivevar:day} 接受shell脚本传来的参数day

shell脚本

1#!/bin/bash 2source /etc/profile 3set -e 4echo "**************************************************" 5echo "**************************************************" 6echo "*********************START************************" 7echo "**************************************************" 8echo "**************************************************" 9day=$(date -d "today -5hours" +%Y%m%d) 10minute=$(date -d "today -5hours" +%H00) 11lmonth=$(date -d "last month -5hours" +%Y%m%d) 12echo $day 13echo $minute 14echo $lmonth 15 16kinit -kt /home/secu01/cluster_keytab/secu01.keytab secu01 17 18#调用sql 19/usr/bin/hive -hivevar cmouth=${day} -hivevar cmouth=${minute} -hivevar lmouth=${lmonth} -f /iot_tac.sql 20 21echo "*************iot_tac.sql调用成功*************" 22echo "***************all success****************"
  • #!/bin/bash 指此脚本使用/bin/bash来解释执行
  • day、minute、lmonth 定义的参数,传递给sql文件

部署定时

  • 第一步:将shell脚本和sql文件上传到Linux系统中,shell文件名:iot_tac.sh;sql文件名:iot_tac.sql

  • 第二步:更改shell脚本的权限

    chmod u+x iot_tac.sh

  • 第三步:如果sql文件报错:/bin/bash^M: bad interpreter

    sed -i "s/\r//" iot_tac.sql

  • 第四步:设置定时器 (1)增加一个cron定时任务

    crontab -e

(2)按insert键进入编辑模式

00 * * * * /home/zhangs/iot_tac.sh >/home/zhangs/log/iot_tac.log

表示每小时执行一次shell脚本,并生成日志文件 minute: 区间为 0 – 59 hour: 区间为0 – 23 day-of-month: 区间为0 – 31 month: 区间为1 – 12. 1 是1月. 12是12月. Day-of-week: 区间为0 – 7. 周日可以是0或7. (3)按esc键退出编辑模式,再按shift+:输入:wq保存并退出

点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )