shell書き込みデータベースクエリーツール
1594 ワード
#!/bin/sh
echo "********************************************************"
echo " 1. Describe all table construct."
echo " 2. Show a Table's content by you input table name."
echo " 3. Show a Case's info by you input case id."
echo "*********************************************************"
echo "please select a number (1 ~ 3):"
read answer
if [ $answer -eq 1 ];
then
tables=`mysql -u root -e "use i_test;show tables;"`
for list in $tables
do
if [ $list == 'Tables_in_i_test' ];
then
echo "Table in i_test:" >> a.txt
else
echo >>a.txt
echo TABLE "["$list"]" DESCRIBE:>>a.txt
mysql -u root -t -e"desc i_test.$list" |tee -a a.txt
fi
done
elif [ $answer -eq 2 ];
then
echo "please input a table name:"
read tbname
mysql -u root -t -e"select * from i_test.$tbname"|tee -a select.txt
elif [ $answer -eq 3 ];
then
echo "please input a case_id:"
read case_id
tables=`mysql -u root -e "use i_test;show tables;"`
for table in $tables
do
if [ $table != 'Tables_in_i_test' ]
then
have=`mysql -u root -e"desc i_test.$table case_id"`
have="$have"
if [ "$have" != "" ];
then
echo $table >>cases_info.txt
mysql -u root -t -e "use i_test;select * from $table where case_id =$case_id"|tee -a cases_info.txt
fi
fi
done
fi
echo " The Shell is Complate !"