新公司写的第一个脚本

分为两个脚本

    1.从oracle数据库中获取信息

    2.进行查找指定内容

    3.计划任务


查询数据的脚本

#!/bin/bash

export ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1

export NLS_LANG="SIMPLIFIED CHINESE_CHINA.ZHS16GBK"

/u01/app/oracle/product/10.2.0/db_1/bin/sqlplus -s hs_user/handsome@oracle1 << EOF

set lines 350

set pagesize 1000

select a.init_date,a.curr_time,a.fund_account,a.client_name,b.bank_name,c.branch_name,d.mobile_tel,e.bkaccount_regflag from hs_fund.fundaccountjour a,hs_fund.bankarg b,hs_user.allbranch c,hs_user.clientinfo d,hs_fund.bankexchaccount e where a.fund_account=d.client_id and a.fund_account=e.fund_account and a.bank_no=b.bank_no and a.branch_no=c.branch_no and a.bank_no=e.bank_no and a.business_flag='1072' order by a.curr_time desc;

exit;

EOF

----------------------------------------------------------------------------------

#!/bin/bash

cd /home/oracle

curr_file=`/bin/date +"%k%M%S"`    获取当前时间,因为数据库中的时间显示格式为 101235 表示 10点12分35秒

old_file_time=`date -d -1hour "+%k%M%S"`    获取上一个小时的时间

/bin/bash test.sh >> $curr_file

for i in `grep '20' $curr_file | /bin/awk -F' ' '{print $2}'`

do

        if [ $i -lt $curr_file -a $i -gt $old_file_time ];then

                /bin/grep $i $curr_file >> /home/oracle/$curr_file.txt

        fi

done


如果在for循环里进行判断则会报错,不知道为什么原因,所以就这么写了

if ! /bin/cat /home/oracle/$curr_file.txt &> /dev/null;then

        exit 102

fi


iconv -f GBK -t utf-8 /home/oracle/$curr_file.txt -o /home/oracle/news.$curr_file.txt

/bin/cat /home/oracle/news.$curr_file.txt | /bin/awk -F' ' '{print $2,$3,$4,$5,$6,$7,$8,$9}' > /home/oracle/news.$curr_file.txt

应该是中文的关系无法使用 -e,如果使用了则文件中没有数据

sed -i 's/male/男/g' news.$curr_file.txt

sed -i 's/fem/女/g' news.$curr_file.txt

sed -i 's/wei/未签约/g' news.$curr_file.txt

sed -i 's/yi/签约/g' news.$curr_file.txt

发送邮件

/usr/local/bin/sendEmail -f [email protected] -t [email protected] -cc [email protected],[email protected] -s mail.xxx.com -u "今日开户客户" -o message-file=/home/oracle/news.$curr_file.txt -xu nagios@@

txsec.com -xp tianxiang -m "`cat /home/oracle/news.$curr_file.txt`"

你可能感兴趣的:(shell)