Shell指令碼中時間處理

2022-03-28 01:23:05 字數 2588 閱讀 6852

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 "$"`

x=`expr \$ - \$`

if [ $x -lt 1800 ]; then

#初始變數

checkorahost=172.16.219.101

filedir="/home/oracle/channelmonitoring"

sqldir="$/sql/trade_zf.sql"

datadir="$/data/trade_zf.txt"

dateflag="/home/oracle/channelmonitoring/date/trade_zf"

cat /dev/null >  $

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/[email protected]:1521/orclset feedback off;

set head off;

set pagesize 0;

set linesize 433;

set termout off;

define fi1= '$'

prompt *** spooling to &fi1

spool &fi1

@$;spool off;

exit;

eofsed  -i  's/[ \t]*\$//g'  $

curl -i -xpost '' --data-binary @$

date2=`date +"%s" -d "$"`

date3=1800

nextdate=`expr \$date2 + \$date3`

echo $nextdate

nextdate=`date -d @$ "+%y-%m-%d %h:%m:%s"`

cat /dev/null > $

echo \$  >> $

else

echo "已經執行過了,請過30分鐘之後在執行。"

ficat /dev/null > 目標檔案                           ###echo "" > 目標檔案有空行

漢字以及雙引號需要使用轉義字元\字元

『$』 需要加單引號

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 指令碼 shell script 是一種為 shell 編寫的指令碼程式。業界所說的 shell 通常都是指 shell 指令碼,但讀者朋友要知道,shell 和 shell script 是兩個不同的概念。由於習慣的原因,簡潔起見,本文出現的 shell程式設計 都是指 shell 指...

shell指令碼中 2 1

在指令碼開發中經常能看到 2 1 比如 2 root cd x php index.php task testone dev null 2 1對於 1 更準確的說應該是檔案描述符 1,而1標識標準輸出,stdout。對於2 表示標準錯誤,stderr。2 1 的意思就是將標準錯誤重定向到標準輸出。這...

shell指令碼中 set ex

剛剛學會了乙個很實用的shell命令set ex,在這裡分享一下。set e 先說說set e,這個引數的含義是,當命令發生錯誤的時候,停止指令碼的執行。通常來說,我們會習慣於使用 來實現這樣的功能,比如 echo 1 rm non existent file echo 2但是,寫成一行呢,可讀性有...