日期判斷行修改指令碼

pathfinder_cui發表於2015-09-15
#!/bin/sh
#
#the cobar create table on a file of schema.xml
excd=$(date +%Y%m%d)
endd=$(date +%Y%m%d -d +6day)   #當前日期向後推6天的日期
for i in $(seq 6) ; do
 if  [ $excd -le $endd ] && [ $(date -d $excd +%w) -ne 0 ] &&  [ $(date -d $excd +%w) -ne 6 ] ;then   #[$(date -d $excd +%w) -ne 0]判斷日期是星期幾,0是星期日、6是星期6
        sed -i "s@\(TQ.*ticktable_[0-9]\+\)@\1,k_minute1_$excd,ticktable_$excd@g" /tmp/schema.xml    #如果sed命令引數中有變數記得要用單引號,
#        echo "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA         is finish"
      fi
    excd=$(date +%Y%m%d -d +${i}day)
    continue
done



#!/bin/sh
#
excd=$(date +%Y%m%d)
#endd=$(date +%Y%m%d -d +6day)
for i in $(seq 0 6); do
  tdd=$(date +%Y%m%d -d +${i}day)
  if [ $(date -d +${i}day +%w) -ne 0 ] && [ $(date -d +${i}day +%w) -ne 6 ] ;then
    /mysql/bin/mysql --socket=/mysql/tmps/mysql.sock33017 shhq -e "create table k_minute1_${tdd} like k_minute1_20150910;"
    /mysql/bin/mysql --socket=/mysql/tmps/mysql.sock33017 shhq -e "create table ticktable_${tdd} like ticktable_20150910;"
    /mysql/bin/mysql --socket=/mysql/tmps/mysql.sock33018 shhq -e "create table k_minute1_${tdd} like k_minute1_20150910;"
    /mysql/bin/mysql --socket=/mysql/tmps/mysql.sock33018 shhq -e "create table ticktable_${tdd} like ticktable_20150910;"
  else
    continue
  fi
done

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29620572/viewspace-1799913/,如需轉載,請註明出處,否則將追究法律責任。

相關文章