bash常用記錄

# getIp.sh
#!/bin/bash
CUR_DIR=$(cd "$(dirname "${BASH_SOURCE-$0}")";pwd)
exec 1>>$CUR_DIR"/log/getIp.sh.log"
exec 2>>$CUR_DIR"/log/getIp.sh.log.wf"
 . ~/.bashrc
filename=$1
datafile=$CUR_DIR/var/${filename}
echo $datafile
datecsv=`date +'%Y%m%d'`
current=`date "+%Y-%m-%d %H:%M:%S"`
timeStamp=`date -d "$current" +%s`
#將current轉換爲時間戳,精確到毫秒
currentTimeStamp=$((timeStamp*1000+`date "+%N"`/1000000))
csvfile=$CUR_DIR/"host-"${datecsv}".csv"
# 集羣所有IP列表
gp_sql="select distinct(hostname) from gp_segment_configuration"
# 集羣master節點IP
# gp_sql="select distinct(hostname) from gp_segment_configuration where content=-1 and role='p'"
# 集羣standby節點IP
# gp_sql="select distinct(hostname) from gp_segment_configuration where content=-1 and role='m'"
echo $gp_sql
gp_info=`echo -e ${gp_sql} |gp -t -A`
echo $gp_info
for var in $gp_info
do
   echo $var
   ip=`host -i $var |awk '{print $4}'`
   echo $ip
   `echo -e "${ip}" >> $csvfile`
done
# open_incr.sh
#!/bin/bash
. ~/.bashrc
start_date=`date -d "1 days ago" +%Y%m%d`
if [ $# -gt 0  ]
then
    start_date=$1
fi
#end_date=`date -d "${start_date} 1 days " "+%Y-%m-%d"`
schema="open"
tablename="t_pay"
tablename_incr="t_pay_incr"
data_path=" /home/work/hdfs_gpdata/alldata/${schema}/${tablename_incr}"
if [  ! -d $data_path   ]; then
    mkdir ${data_path}
fi
echo ${start_date}
DATAX_HOME="/home/work/datax"
HOMEPATH=$(cd `dirname $0`; pwd)
jobdir="/home/work/datax/job"
template="/home/work/datax/job/example.t_pay_incr"
dayfile="${jobdir}/${schema}_${tablename_incr}"
sed "s/START_DATE/${start_date}/g" ${template} > ${dayfile}
cd "${DATAX_HOME}/bin"
echo $dayfile
./start_datax.sh ${dayfile}  > ${HOMEPATH}/${tablename}_incr.log 2>&1 &
# core_incr.sh
#!/bin/bash
. ~/.bashrc
start_date=`date -d "1 days ago" +%Y-%m-%d`
if [ $# -gt 0  ]
then
    start_date=$1
fi
end_date=`date -d "${start_date} 1 days " "+%Y-%m-%d"`
schema="core"
tbname="t_trans"
tbname_incr="t_trans_incr"
data_path="/home/work/hdfs_gpdata/alldata/paycoredb/${schema}_${tbname_incr}"
if [  ! -d $data_path   ]; then
    mkdir ${data_path}
fi
echo ${start_date} ${end_date}
HOMEPATH=$(cd `dirname $0`; pwd)

example="/home/work/daiyuanpei/tasks/core_json_example"
tempdir="/home/work/paycoredb/datax/tempdir"
basepath=$(cd `dirname $0`; pwd)
cd $basepath
ARR=(1 2 3 4 5 6 7 8)
for ID in ${ARR[*]}
do
    jsonfile="${tempdir}/${schema}_${tbname_incr}_$ID"
    sed "s/<HOSTID>/${ID}/g;s/<TBNAME>/${tbname}/g;s/<TBNAME_INCR>/${tbname_incr}/g;s/<SCHEMA>/${schema}/g;s/START_DATE/${start_date}/g;s/END_DATE/${end_date}/g" ${example} > ${jsonfile}
done
echo "${jsonfile} done"
ARR=(1 2 3 4 5 6 7 8)
for ID in ${ARR[*]}
do
    ~/datax/bin/start_datax.sh /home/work/paycoredb/datax/tempdir/${schema}_${tbname_incr}_$ID >> /home/work/paycoredb/datax/core_incr.out &
    echo "~/datax/consolelog/${schema}_${tbname_incr}_$ID.log"
done

 

發佈了24 篇原創文章 · 獲贊 8 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章