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
!/bin/bash
id=root pwd=비밀번호 curMonth=data
date +"%Y%m"
lastMonth=datadate -d "1 month ago" +"%Y%m"
sed -i 's/\
'${lastMonth}'\\
/\'${curMonth}'\\
/g' createTable.sqlsed -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