2016-09-19 61 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" 

请确保您在查询中的字符串值周围加上引号。