2016-09-19 41 views
0

我怎麼能連接到我的分貝,並在bash執行查詢插入值

這是我到目前爲止的代碼:

echo "estacion: "$st; 
fcha=$year2"-"$month"-"$day; 
echo "fecha: "$fcha; 

echo $archivoF " ==> " $rutabase"datos/obs/"$st"/"$year2"/"$archivoF; 
if [ ! -d $rutabase"datos/obs/"$st"/"$year2 ]; then 
    mkdir -p $rutabase"datos/obs/"$st"/"$year2; 
fi 
mv $archivoF $rutabase"datos/obs/"$st"/"$year2 
IFS='.' read -ra tipoO <<< "$archivoF" 
tipoOb=`echo "."${tipoO[1]}"."${tipoO[2]}` 
query="insert into FILES (name,type,date,station) VALUES($archivoF,$tipoOb,$fcha,$st)" 

echo $archivoG " ==> "$rutabase"rinex/nav/"$st"/"$year2"/"$archivoG; 
if [ ! -d $rutabase"datos/nav/"$st"/"$year2 ]; then 
mkdir -p $rutabase"datos/nav/"$st"/"$year2; 
fi 
mv $archivoG $rutabase"datos/nav/"$st"/"$year2 
IFS='.' read -ra tipoN <<< "$archivoG" 
tipoNa=`echo "."${tipoN[1]}` 
query="insert into FILES (name,type,date_f,station) VALUES($archivoG,$tipoOb,$fcha,$st)" 

任何建議

+0

'mysql -e「查詢字符串」' – Barmar

+0

請確保您引用字符串的值。 – Barmar

+0

爲什麼在作業中使用'echo'?只是'tipoOb =。$ {tipoO [1]}' – Barmar

回答

0

要執行從腳本查詢,使用mysql命令和-e選項。

query="insert into FILES (name,type,date,station) VALUES('$archivoF','$tipoOb','$fcha','$st')" 
mysql -h dbhost -u dbuser -ppassword dbname -e "$query" 

請確保您在查詢中的字符串值周圍加上引號。