Hi there, i've written a script to extract a portion of a MySQL database table and convert it to CSV and then to import it back as CSV to MySQL. Initially it worked without the while loop but after adding the while loop statement, i am getting the following error:
./export-csv-coordinates.sh: line 49: warning: here-document at line 18 delimited by end-of-file (wanted `EOFMYSQL')
./export-csv-coordinates.sh: line 50: syntax error: unexpected end of file
Here's my script:
#!/bin/bash
while :
do
clear
echo "Server Name - $(hostname)"
echo "-------------------------------------"
echo " MAIN MENU "
echo "-------------------------------------"
echo "1. Export coordinates as csv file"
echo "2. Import csv file to update database"
echo "3. Exit"
read -p "Enter your choice [ 1 - 3 ]" choice
case $choice in
1)
echo "Exporting coordinates as CSV...please wait!"
sleep 5
mysql -uroot -proot iaf<<EOFMYSQL
SELECT * INTO OUTFILE '/var/lib/mysql/nodecoordinates.csv' FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' FROM sngnms_node_map_coordinate;
EOFMYSQL
echo "CSV created in /var/lib/mysql"
read -p "Press [ENTER] key to continue..."
readEnterKey;;
2)
file="/var/lib/mysql/nodecoordinates.csv"
for f in $file
do
[ -f $f ] && echo "$f file found" || echo "*** Error -$f file not found!"
done
echo ""
echo "Importing CSV file to update database...please wait!"
sleep 5
mysql -uroot -proot iaf<<EOFMYSQL
LOAD DATA INFILE '/var/lib/mysql/nodecoordinates.csv' INTO TABLE sngnms_node_map_coordinate FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n';
EOFMYSQL
/etc/init.d/mysql restart
sleep 5
echo "CSV file updated to current database"
read -p "Press [ENTER] key to continue..."
readEnterKey;;
3)
echo "Bye!"
exit 0;;
*)
echo "Error: Invalid option..."
read -p "Press [ENTER] key to continue..."
readEnterKey;;
esac
done
Could someone help in pointing what's wrong with my script. I am just beginning to learn scripting.
Thanks!