Reputation: 145
How can i connect to my db and execute the query in bash
this is my code so far:
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)"
any suggestions
Upvotes: 0
Views: 3926
Reputation: 780688
To execute a query from a script, use the mysql
command with the -e
option.
query="insert into FILES (name,type,date,station) VALUES('$archivoF','$tipoOb','$fcha','$st')"
mysql -h dbhost -u dbuser -ppassword dbname -e "$query"
Make sure you put quotes around the values that are strings in the query.
Upvotes: 2