Linux上定时shell脚本
原文链接:http://www.92coder.com/9-Linux定时shell脚本/#more
本文主要介绍在Linux系统上部署定时器,定时执行shell脚本,通过脚本执行sql文件
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 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保存并退出
Linux上定时shell脚本的更多相关文章
- linux 执行远程linux上的shell脚本或者命令以及scp 上传文件到ftp--免密码登陆
场景:在linux A 上执行Linux B上的shell脚本和命令 步骤1.设置ssh免登陆 1.SSH无密码登录 # 本地服务器执行(A机器):生成密钥对 ssh-keygen -t dsa -P ...
- Linux上使用shell脚本查看内存情况(超实用)
#!/bin/bashexport chknum=1 #shell搅拌存放目录(输出日志文件执行后也存于该目录)echo 3 > /wls/wls81/shellsyncwhile [ $chk ...
- linux上使用shell脚本查看内存使用率
如上的内存利用率 = [-/+buffers/cache:used]/[Mem:total ] = 6293404 / 16333656 对于free命令而言,有如下公式: total = used ...
- Linux下添加shell脚本使得nginx日志每天定时切割压缩
Linux下添加shell脚本使得nginx日志每天定时切割压缩一 简介 对于nginx的日志文件,特别是access日志,如果我们不做任何处理的话,最后这个文件将会变得非常庞大 这时,无论是出现异常 ...
- Linux下定时执行脚本(转自Decode360)
文章来自:http://www.blogjava.net/decode360/archive/2009/09/18/287743.html Decode360's Blog 老师(业精于勤而荒于嬉 ...
- 实用脚本 2 -- Linux下定时执行脚本
今天学习Linux下定时执行脚本,看到一篇讲解比较好的文章,特此拿来分享. 原文链接:http://www.blogjava.net/decode360/archive/2009/09/18/2877 ...
- Linux生产服务器Shell脚本分享
Linux生产服务器Shell脚本分享 2012-6-6 86市场网 linux 作为一名Linux/unix系统管理员,我经常遇到人问这个问题:shell能做什么?PHP这么强大,为什么不用PHP来 ...
- mac链接linux终端,shell脚本发布代码
项目的业务需求:从mac端直接连上linux服务终端,并发布相关的代码 一.使用ssh链接上linux服务端 1.cd ~/.ssh 2.vi config,按照下面的内容配置config文件,然后: ...
- Java代码调用服务器上的Shell脚本
Java代码调用服务器上的Shell脚本 这里主要是因为我们报表平台有用到用户手工录入的数据作为结果数据且需要纳入saiku去展示 如我们所知,saiku不会自动刷新,所以需要在数据更新接口中调用服务 ...
随机推荐
- 异步机制 - APC
APC : An asynchronous procedure call,异步过程调用,是微软提供的一种在线程上下文中执行代码的机制.当向一个线程插入一个USER APC时,如果线程进入alertab ...
- NodeJS的exports、module.exports与ES6的export、export default深入详解
前言 决定开始重新规范的学习一下node编程.但是引入模块我看到用 require的方式,再联想到咱们的ES6各种export .export default. 阿西吧,头都大了.... 头大完了,那 ...
- 第04组 Beta冲刺(1)
队名:斗地组 组长博客:地址 作业博客:Beta冲刺(1/4) 各组员情况 林涛(组长) 过去两天完成了哪些任务: 1.分配展示任务 2.收集各个组员的进度 3.写博客 展示GitHub当日代码/文档 ...
- 一篇文章搞懂Python装饰器所有用法
01. 装饰器语法糖 如果你接触 Python 有一段时间了的话,想必你对 @ 符号一定不陌生了,没错 @ 符号就是装饰器的语法糖. 它放在一个函数开始定义的地方,它就像一顶帽子一样戴在这个函数的头上 ...
- linux中read,write和recv,send的区别
linux中read,write和recv,send的区别 1.recv和send函数提供了和read和write差不多的功能.但是他们提供了第四个参数来控制读写操作. int recv(int so ...
- MongoDB作为windows服务来安装-2
首先区官网下载对应版本的安装文件,我本地的环境是win7 bit64 我下载的版本是:mongodb-win32-x86_64-2.4.6 ok, 文件下载后,开始安装,这里要说一下,如果直接启动Mo ...
- asp.net MVC AngularJS
http://www.cnblogs.com/powertoolsteam/category/834105.html
- Sql题目精选练习
1.每日经典sql 1.1.1 根据三张关系表查询雇员中工资最高的雇员的员工姓名.工资和部门号. salary(工资表) employee(员工表) department(部门表) Sql语句: SE ...
- [dart学习]第七篇:类(构造函数)
前言:楼主平时基本没有使用过异常处理,所以对异常的认知可能不够准确,这里就不翻译异常的相关内容了,大家可以去官网自行阅读介绍,地址 https://dart.dev/guides/language/l ...
- 一个可以让vsftpd启动系统用户登陆ftp的例子
编辑 /etc/vsftpd.conf 如下: listen=YES anonymous_enable=NO local_enable=YES check_shell=NO write_enable= ...