您的位置:首页 > 运维架构 > Shell

工作学习日志(shell -file)

2016-11-18 00:00 295 查看
摘要: 用shell读取文件,循环显示每一行内容

大家应该能看懂下面,附上文件内容:

[new]

20161109111001_*****.sql

[old-game-2016.10.29]
20161109111001_*****.sql

#类型: 内部函数
function __updateSqlBlock() {
local config_name=$1
local db_url=$2
local db_username=$3
local db_password=$4

file='./config/update_sql_info.conf'
read_tag=0
while read line
do
row=`echo $line | grep '\[' | sed 's/\[//g' | sed 's/\]//g'`
if [ "$row" == 'new' ];then
read_tag=1
fi

is_old=`echo $row | grep 'old' `
if [ "$is_old" != "" ];then
read_tag=0
fi

if [ "$read_tag" -eq "1" ];then
if [ "$row" != 'new' ] && [ "$line" != "" ] ;then
echo "mysql -h$db_url -u$db_username -p$db_password $config_name < /var/www/$config_name/sql/migrations/$line"
fi
fi
done < $file
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  shell sql server auto