Shell脚本中时间处理
Shell脚本中时间处理
1.脚本内容
#!/bin/bash
#环境变量
#设置环境变量和sql文件格式相符
source /etc/profile
export LD_LIBRARY_PATH="/usr/lib/oracle/12.1/client64/lib"
export NLS_LANG="AMERICAN_AMERICA.ZHS16GBK"
export LANG=en_US.UTF-8
date=`cat /home/oracle/channelMonitoring/date/trade_zf`
sysdate=`date +"%s"`
date2=`date +"%s" -d "${date}"`
x=`expr \${date2} - \${sysdate}`
if [ $x -lt 1800 ]; then
#初始变量
CHECKORAHOST=172.16.219.101
FILEDIR="/home/oracle/channelMonitoring"
SQLDIR="${FILEDIR}/sql/trade_zf.sql"
DATADIR="${FILEDIR}/data/trade_zf.txt"
DATEFLAG="/home/oracle/channelMonitoring/date/trade_zf"
cat /dev/null > ${SQLDIR}
cat /dev/null > $DATADIR
echo -n "select ('trade_zf'||',trade_code='||tr.trade_code||',status='||tr.status||',merchant='||m.merchant_code||',channel='||tr.bank_code||',bank='||tr.fld3||' value='||(case when tr.status=2 then 1 else 0 end)||' '||ceil((tr.trade_end_time - to_date('1970-01-01','yyyy-mm-dd'))*86400 - TO_NUMBER(SUBSTR(TZ_OFFSET(sessiontimezone),1,3))*3600)||round(dbms_random.value(100000000,999999999)) ) as \"插入语句\" from tvpay2.trade_record tr
join tvpay2.merchant m on tr.provider_id = m.id
where (tr.trade_code like 'ZF%' or tr.trade_code = 'DK0003' or tr.trade_code = 'DK0026' ) and ((to_date('$date', 'yyyy-mm-dd hh24:mi:ss')-to_date('1970-01-01','yyyy-mm-dd hh24:mi:ss'))*86400 - (tr.trade_end_time-to_date('1970-01-01','yyyy-mm-dd hh24:mi:ss'))*86400) between 0 and 1800 and tr.status in (2,3);
" >> $SQLDIR
sqlplus -s user/password@x.x.x.x:1521/orcl<<EOF
set echo off;
set feedback off;
set head off;
set pagesize 0;
set linesize 433;
set termout off;
define fi1= '${DATADIR}'
prompt *** Spooling to &fi1
spool &fi1
@${SQLDIR};
spool off;
exit;
EOF
sed -i 's/[ \t]*\$//g' ${DATADIR}
curl -i -XPOST 'http://x.x.x.x:8086/write?db=monitor' --data-binary @${DATADIR}
date2=`date +"%s" -d "${date}"`
date3=1800
nextdate=`expr \$date2 + \$date3`
echo $nextdate
nextdate=`date -d @${nextdate} "+%Y-%m-%d %H:%M:%S"`
cat /dev/null > ${DATEFLAG}
echo \${nextdate} >> ${DATEFLAG}
else
echo "已经执行过了,请过30分钟之后在执行。"
fi
2.注意事项
2.1清空文件
cat /dev/null > 目标文件 ###echo "" > 目标文件有空行
2.2shell调用sql文
汉字以及双引号需要使用转义字符\字符
2.3sql文调用shell变量
‘${date}’ 需要加单引号
2.4算法使用
expr 以及if语句中的判断使用lt
###备注
export LD_LIBRARY_PATH="/usr/lib/oracle/12.1/client64/lib"
在定时任务中,没有这行,可能执行会报错
###备注
export NLS_LANG="AMERICAN_AMERICA.UTF8"
放在配置文件中,防止中文乱码
start_seconds=\$(date --date="\$starttime" +%s)
如何将一个时间格式的变量变换成秒
Shell脚本中时间处理的更多相关文章
- shell脚本中>/dev/null的含义
shell脚本中>/dev/null的含义 shell脚本中有段使用sqlplus的部分: sqlplus ${user_id} <<! >/dev/null spool sp ...
- Shell脚本中的并发(转)
转自http://blog.csdn.net/wangtaoking1/article/details/9838571 主要记录一下Shell脚本中的命令的并发和串行执行. 默认的情况下,Shell脚 ...
- linux,shell脚本中获取脚本的名字,使用脚本的名字。
需求描述: 写shell脚本的过程中,有时会需要获取脚本的名字,比如,有的时候,脚本 中会有usage()这种函数,可能就会用到脚本的名字. 实现方法: shell脚本中,通过使用$0就可以获取到脚本 ...
- 转 在shell脚本中使用expect实现scp传输问题
1.安装expect expect用于shell脚本中自动交互,其是基于tcl编程语言的工具.所以安装expect首先安装tcl.本文中使用的是expect5.45和tcl8.6.6. 安装tcl [ ...
- shell脚本介绍、shell脚本结构和执行、date命令用法、shell脚本中的变量
7月11日任务 20.1 shell脚本介绍20.2 shell脚本结构和执行20.3 date命令用法20.4 shell脚本中的变量 20.1 shell脚本介绍 1.shell脚本语言是linu ...
- Linux centosVMware shell脚本介绍、shell脚本结构和执行、date命令用法、shell脚本中的变量
一. shell脚本介绍 shell是一种脚本语言 aming_linux blog.lishiming.net 可以使用逻辑判断.循环等语法 可以自定义函数 shell是系统命令的集合 shell脚 ...
- shell脚本中的各种表达式介绍和使用
#前言:在shell脚本中,有各种的表达式,包括有条件测试表达式,文件表达式,字符串表达式,整数表达式,接下来我们来了解一下他们的使用方法 1.条件测试表达式 #首先来看一下条件测试语法 #条件测试语 ...
- 详解Linux交互式shell脚本中创建对话框实例教程_linux服务器
本教程我们通过实现来讲讲Linux交互式shell脚本中创建各种各样对话框,对话框在Linux中可以友好的提示操作者,感兴趣的朋友可以参考学习一下. 当你在终端环境下安装新的软件时,你可以经常看到信息 ...
- shell脚本中的反引号使用 `
反引号是~的英文切换 在shell脚本中,反引号允许将shell命令的输出赋值给变量. test=`date` 这样shell会执行反引号中的命令.并将执行的结果赋值给变量tests.
随机推荐
- CodeForces691C 【模拟】
这一题的模拟只要注意前后导零就好了... 感受就是... 如果是比赛中模拟题打好..要盯着注意点,测试不同的情况下的注意点..起码要针对性测试10分钟.. 还是蛮简单的,但是自己打烦了,应该,队友代码 ...
- CodeForces 653A【水】
sort一发,去重 #include<cstdio> #include<iostream> #include<queue> #include<string.h ...
- VR头盔产品镜片评测
2015-07-21 16:59 原创 Randy Orton http://www.leiphone.com/news/201507/7j46BjWsSitKML13.html 虚拟现实设备自从去年 ...
- cogs 1176. [郑州101中学] 月考
1176. [郑州101中学] 月考 ★ 输入文件:mtest.in 输出文件:mtest.out 简单对比时间限制:1 s 内存限制:128 MB [题目描述] 在上次的月考中Bug ...
- Mol Cell Proteomics. |廖文丽| 阿尔兹海默症临床前期的脑脊液中突触蛋白的变化先于神经变性标志物
大家好,本周分享的是发表在Molecular & Cellular Proteomics. 上的一篇关于阿尔兹海默病临床前期生物标志物鉴定的文章,题目是Changes in synaptic ...
- APP为什么会被打回来??
APP的设置界面, 按钮使用了类似iPhone的操作方式以及icon的圆角设计 -> 重新设计 APP的年龄设置太低 -> 改年龄 APP里有实物奖励 -> 免责声明, ...
- html table导出到Excel中,不走后台,js完成
静态表格table <table class="table tableStyles" id="tables"> <caption>不正经 ...
- get 和 post 请求的区别(转)
转自 http://www.cnblogs.com/hyddd/archive/2009/03/31/1426026.html http://www.nowamagic.net/librarys/ve ...
- log4j.xml中Filter的用法
前言 log4j中常用的Filter分为四种:DenyAllFilter.LevelMatchFilter.LevelRangeFilter.StringMatchFilter. 当appender匹 ...
- 基于php的AWS存储服务
近几天用到了aws的s3存储服务,公司内部的完全兼容aws并对其进行了封装,之前也用过,现在把经验总结一下. 既然要用,首先需要安装sdk,下边提供了几种安装方法 方法一:使用composer安装 1 ...