linux中shell脚本定时,Linux上定时shell脚本

sql文件-- 创建表

create table if not exists iot_test.iot_tac

(

MSISDN string,

TAC string

)

partitioned by(day string)

row format delimited

fields terminated by '\t'

lines terminated by '\n'

stored as parquet;

--录入数据

set hive.exec.dynamic.partition.mode=nonstrict;

insert overwrite table iot_test.iot_tac

partition(day='${hivevar:day}')

select t4.MSISDN,t4.TAC

from

(select t1.MSISDN,t1.TAC from

(select MSISDN,substr(IMEI,1,8) as TAC,row_number()over(partition by MSISDN) as rn

from prestat.iot_activeuser_hour

where day='${hivevar:day}' and minute='${hivevar:minute}' and IMEI is not null) as t1

left join

(select MSISDN,TAC from iot_test.iot_tac where day='${hivevar:lmonth}') as t2

on t1.MSISDN = t2.MSISDN

where t2.MSISDN is null and t1.rn = 1

union all

select MSISDN,TAC

from iot_test.iot_tac

where day='${hivevar:lmonth}'

) as t4;${hivevar:day}

接受shell脚本传来的参数day

shell脚本#!/bin/bash

source /etc/profile

set -e

echo "**************************************************"

echo "**************************************************"

echo "*********************START************************"

echo "**************************************************"

echo "**************************************************"

day=$(date -d "today -5hours" +%Y%m%d)

minute=$(date -d "today -5hours" +%H00)

lmonth=$(date -d "last month -5hours" +%Y%m%d)

echo $day

echo $minute

echo $lmonth

kinit -kt /home/secu01/cluster_keytab/secu01.keytab secu01

#调用sql

/usr/bin/hive -hivevar cmouth=${day} -hivevar cmouth=${minute} -hivevar lmouth=${lmonth} -f /iot_tac.sql

echo "*************iot_tac.sql调用成功*************"

echo "***************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 interpretersed -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保存并退出

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值