shell打印每年的每月1号,格式YYYYMMDD

2017-07-04

我需要用shell脚本下载一些oracle记录,希望指定日期参数,例如a.sh  20170101 20170201

1、创建日期列表aa.py

#!/usr/bin/python
for Y in range(2013,2018):
for i in range(1,13):
print  "%d%02d01" %(Y,i)

执行aa.py > 2013.txt

2、year.sh

#!/bin/sh
N=$(sed -n '$=' 2013.txt)
for ((x=1;x<${N};x++));
do
((y=x+1));
m=$(sed -n "${x}p" 2013.txt);
n=$(sed -n "${y}p" 2013.txt);
./get_RECORDER_from_cid_2xls.sh 90000001 $m $n > /dev/null
done

3、./get_RECORDER_from_cid_2xls.sh

#!/bin/sh

cid=$1;
start_date=$2
end_date=$3

file=crm_contact_recorder_${cid}_${start_date}_${end_date}.xls

if [ -z $1 ]||[ -z $2 ]||[ -z $3 ];then
echo "Usage: $0 company_id 20140701 20140715"
exit 0;
fi

sqlplus -s 'crm/test123456<< EOF
set linesize 200
set term off verify off feedback off pagesize 999
set markup html on entmap ON spool on preformat off
alter session set nls_date_format='YYYY-MM-DD HH24:MI:SS';
spool $file
select a.crm_COMPANY_ID ID,b.name,''''||b.CREATE_TIME TIME1,b.OWNER,''''||a.CREATE_TIME TIME2,a.NOTE from CRM_CONTACT_RECORDER a,CRM
_COMPANY b where a.crm_company_id=b.ID and a.company_id='${cid}' and b.create_time between TO_DATE('${start_date} 00:00:00', 'YYYYMM
DD HH24:MI:SS') and TO_DATE('${end_date} 00:00:00', 'YYYYMMDD HH24:MI:SS') order by a.CRM_COMPANY_ID,a.create_time;
spool off
quit;
EOF

sed -i '/select/d' $file
sed -i '/spool/d' $file
zip -r ${file}.zip $file
ls -l ${file}.zip

4、执行year.sh即可按月生成很多记录包了。

分类:数据库 | 标签: |

相关日志

评论被关闭!