ksh0165 / ReactStudy

업무에 필요한 내용 기록
http://github.com/ksh0165/works.git
0 stars 0 forks source link

shell create table for mysql #344

Open ksh0165 opened 8 months ago

ksh0165 commented 8 months ago

!/bin/bash

id=root pwd=비밀번호 curMonth=datadate +"%Y%m" lastMonth=datadate -d "1 month ago" +"%Y%m"

sed -i 's/\'${lastMonth}'\\/\'${curMonth}'\\/g' createTable.sql

sed -i 's/'${lastMonth}'/'${curMonth}'/g' createTable.sql echo "s/`"${lastMonth}"`/`"${curMonth}"`/g" " createTable.sql"

findWordCount=sed -n '/\'${curMonth}'`/p' createTable.sql | wc -l` echo ${findWordCount}

if [ ${findWordCount} -ne 0 ] ; then mysql -u${id} -p''${pwd}'' gangnam < ./createTable.sql if [ $? -eq 0 ] ; then echo "Success Job" else echo "Fail Job" fi else echo "Not Find lastMonth for replace in createTable.sql("${curMonth}",plz check lastMonth in file content !!!" fi

exit 0