【1.8】shell读入参,shell用户交互式输入
作者:互联网
代码:
#!/bin/bash set -e if [ $# -ne 3 ] then echo "[error] please input three digits, usage: create_database.sh <segno> <start> <end>" exit 1 fi seg=$1; start=$2; end=$3 printf "将在国内库中加区[%s%04d-%s%04d], 是否继续? [y/n]:" $seg $start $seg $end read countinue if [ "x$countinue" != "xy" ] then exit 0 fi mysqldump -urwuser -pQBhhvX2Fi2QnEurA -h10.154.28.249 --set-gtid-purged=OFF --default-character-set=utf8 --add-drop-table=false --no-data g ame_70_0001 >init.sql version=`mysql -urwuser -pQBhhvX2Fi2QnEurA -h10.154.28.249 -D game_70_0001 -Bse "select version from db_version"` logic_version=`mysql -urwuser -pQBhhvX2Fi2QnEurA -h10.154.28.249 -D game_70_0001 -Bse "select config_value from global_config where config _key='LOGIC_VERSION'"` for (( i=$start;i<=$end;i++ )) do ch=$(printf "%04d" $i) db1="game_${seg}_" sql1="create database $db1$ch;" db="$db1$ch" echo $sql1 mysql --default-character-set=utf8 -uroot -p123456 -e "$sql1" echo "init table" mysql --default-character-set=utf8 -uroot -p123456 -D$db < init.sql sql2="use $db1$ch;insert into db_version values(1,'$version');insert into global_config(config_key,config_value) values('LOGIC_VERSION','$l ogic_version')" echo $sql2 mysql -uroot -p123456 -e "$sql2" done echo `date` "done--------------"
标签:h10.154,set,version,--,1.8,seg,start,shell,读入 来源: https://www.cnblogs.com/gered/p/15915175.html