I need a bash script that can retrieve MySQL data from a remote data base. Actually I have that done, but what I need it to do now is loop through the records somehow and pass a variable to another bash file.
Here’s my MySQL call:
mysql -X -u $MyUSER -p$MyPASS -h$MyHOST -D$MyDB -e'SELECT `theme_name`, `guid` FROM `themes` WHERE `theme_purchased`="1" AND `theme_compiled`='0';' > themes.xml
download_themes.sh
It exports the data into an xml file called theme.xml right now, I was just trying to figure out some way to loop through the data. I am trying to avoid PHP and perl and just trying to use bash. Thanks in advance.
something like:
in short: the
mysqlcommand outputs record separated by ‘\n’ and fields separated by ‘\t’ when the output is a pipe. thereadcommand reads a line, splits in fields, and puts each on a variable.if your data has spaces in the fields, you get some problems with the default
readsplitting. there are some ways around it; but if you’re only reading two fields and one of them shouldn’t have any spaces (like theguid), then you can put the ‘dangerous’ field at the end, andreadwill put everything ‘extra’ in the last variable.like this: